Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Justin

Justin Avatar
:)

****
Senior Member

256


July 2009
Well, im still trying to become a coder, so i want to make my first PB code, i know Wrighty just made me one, but i would like to know how to make one for future purposes :P

But i dotn know the basics, ive looked at a few and still dotn understand it, i dont know how to make it say "Hey X you have X Message" or if it says "Hey Justin =), you Have 6 Messages 0 are new" i dont know how to make it so when you click the 0 or 6 it takes you to your inbox.

so can someone tell me the basics on making a pm bar?
My signature
[/left][/i][/size]

JD

JD Avatar



1,032


June 2008
<script type="text/javascript"></script> as you know starts and ends the script.

First we define a variable to represent table cells. We need to do this to find the PM information from the welcome table. I'll call it 't'.

var t = document.getElementsByTagName("td");

Now that we have that, we can use an if statement to find the cell with the pm information.

if(t[2].innerHTML.match(/you have <.+?>(.+?) (message|messages)<.+?>, (\d+) (are|is) new./i)){

Basically says 'if the cell contains the pm information...'

This defines four different regular expressions.
RegExp.$1 is the total pms
RegExp.$2 is message/messages
RegExp.$3 is the number of new pms
and RegExp.$4 is the are/is.

You can use something as simple as a document.write to then create the table. You'll need a grasp of html to shape it to your needs.

There we are :D

Justin

Justin Avatar
:)

****
Senior Member

256


July 2009
seems easy enough, i just have one more question, what if i wanted it to just have Text no table, and have it placed on my menuBG?
My signature
[/left][/i][/size]

JD

JD Avatar



1,032


June 2008
That's fine with no table, just include the text in the document.write.

When you say 'on' your menu, what do you mean? Having the menu on the left and PM info on the right?

Justin

Justin Avatar
:)

****
Senior Member

256


July 2009
PM info on the left while the Menu buttons are on the right.
My signature
[/left][/i][/size]

JD

JD Avatar



1,032


June 2008
In a nutshell, it's completely possible, and within a decent grasp of javascript.

var m = document.getElementsByTagName("td")[5];

gets the table cell that contains the menu.

var M = m.innerHTML;

is the menu itself.

Then you can use m.innerHTML = 'content here'; to design your layout.

Justin

Justin Avatar
:)

****
Senior Member

256


July 2009
Thank you :)
My signature
[/left][/i][/size]

JD

JD Avatar



1,032


June 2008
Let me know how it goes!

Justin

Justin Avatar
:)

****
Senior Member

256


July 2009
im still not understanding it =/, i thought i had it down and it looked really easy, boy was i wrong.

its mostly how to make a table using Document.write, i jdont understand that, and i dont know how to make it say "Hey X you have X messages X are new" and how to make it so when you click the X`s (or in this case the number) itll take you to your inbox

what wedge said was helpful, im just hard to teach :-X, i see many people using "If PB username =" that, can i be taught how to do that, as that seems more simple.
My signature
[/left][/i][/size]

Alex

Alex Avatar

**
Official Member

33


April 2009
This may be of some help. It will grab the private message info you are after.




<script type="text/javascript">
<!--

if(pb_username=="Guest"){ //This checks whether the person is a guest

        document.write('Hi Guest'); //Everything here will only happen for guests

} //End guest check

else if(pb_username!="Guest"){ //This makes sure the person is not a guest

        var Message_Font=document.getElementsByTagName('font').item(2).innerHTML;
        var New_Messages=(Message_Font.match(/<\/a>, (.+?) (is|are) new./i))? RegExp.$1 : '';
        var Total_Messages=(Message_Font.match(/>(.+?) message(s)?<\/a>/i))? RegExp.$1 : '';

} //End member check

//-->
</script>





pb_username: This is a variable that Proboards automatically puts on all of their boards. It's pretty much there to make it easier for coders. It holds the actual user name of the person who is logged in. So, for you it would be 'jsher2', for me it would be 'asdf' and for Wedge it would be 'jambuster'. If a person is not logged in then their username will be 'Guest'. This is useful for private message scripts because you will want to create a different message if a person is a guest. You do not want to be trying to grab someone's private messaging info if they are not logged in, as it is not there.

pb_displayname: This isn't in the script that I posted above, but it is useful for you to know about. It is similar to the pb_username variable, except that it holds the actual display name of the person logged in. So for you it would be 'Justin =)', for me it would be 'Alex' and for Wedge it would be 'Wedge'. This would be useful for your private message greeting. For example:
document.write('How are you today '+pb_displayname+'?');
Will create a greeting, which will have every individuals own display name.

Message_Font: This is a variable I created, which will grab whatever is in the third font tag on the page (since javascript starts counting at 0). The third font tag on every Proboard is this message:
Hey, Justing =), you have 8 messages, 0 are new.
16 Aug, 2009, 9:13pm

New_Messages: This is a variable that I created, that will grab the amount of new private messages a person has. Using regular expressions it grabs this information from the Message_Font variable.

Total_Messages: This uses regular expressions to grab the amount of total messages a person has from the Message_Font variable.

Using these variables you would then be able to make your own customized greeting.
document.write('Hey there '+pb_displayname+', you have <a href="/index.cgi?action=pm">'+New_Messages+'</a> new messages and a total of '+Total_Messages+'.');

This is just an extremely quick run down and I'm not sure how much you already know about. If you want more info on regular expression then check here.
Feel free to ask any questions about what I just wrote or if you have any more about finishing off your private message code.

Justin

Justin Avatar
:)

****
Senior Member

256


July 2009
Thanks Alex :)

i just have one more question, if i wanted to put the PM bar in a table using document.write('Table here') (i believe thats how you make it) would i place the code Above the PM code or below?
My signature
[/left][/i][/size]

Michael

Michael Avatar
*Has a custom title*



1,462


October 2007
You'd have to place the code that alex posted above the table code. Otherwise it won't know the variables! :)

Justin

Justin Avatar
:)

****
Senior Member

256


July 2009
makes sense thanks Wrighty.

Now ANOTHER question xD, i dont know what to add at the beginning of the code, i tried "
var t = document.getElementsByTagName("td");" but it didnt seem to work =/
My signature
[/left][/i][/size]

Michael

Michael Avatar
*Has a custom title*



1,462


October 2007
Hows about you paste your code so far and one of us can go through it and comment on each line that's in the wrong place or got an error? :)

Justin

Justin Avatar
:)

****
Senior Member

256


July 2009
of course i used the way Alex taught me, still trying to figure out how to make it say "Welcome "PB Username" you have 0 new messages" if Alex has a problem i can find a different way, though im giving him credit :P, and im still working on the table :)


<script type="text/javascript">
<!--
//Created by Justin
//Special thanks to Alex and Wrighty of SZ


if(pb_username=="Guest"){

       document.write('Hello Guest, Please login or Register');

}

else if(pb_username!="Guest"){

       var Message_Font=document.getElementsByTagName('font').item(2).innerHTML;
       var New_Messages=(Message_Font.match(/<\/a>, (.+?) (is|are) new./i))? RegExp.$1 : '';
       var Total_Messages=(Message_Font.match(/>(.+?) message(s)?<\/a>/i))? RegExp.$1 : '';

}

//-->
</script>

My signature
[/left][/i][/size]

newBookmarkLockedFalling