Revolution X

Coding Community => Coding Snippets => Topic started by: Agent Moose on August 28, 2009, 09:40:38 pm



Title: User Widget
Post by: Agent Moose on August 28, 2009, 09:40:38 pm
Footers:
Code:
<script type="text/javascript">
var yes = "Welcome {user}.";
var no = "Please <a href='" + smf_scripturl + "?action=login'>Login</a> or <a href='" + smf_scripturl + "?action=join'>Register</a>";

var name = document.getElementsByTagName("span");
//Created by Agent Moose (revolutionx.smfforfree3.com)
for(v=0;v<name.length;v++){
if(name[v].innerHTML.match(/Hello <b>(.*)<\/b>/i)){
var username = RegExp.$1;
if(yes.match(/{user}/i)) yes = yes.replace(/{user}/i,username);
};};
var O_o = document.getElementsByTagName("td");
for(o_O=0;o_O<O_o.length;o_O++){
if(O_o[o_O].className == "catbg" && O_o[o_O].height == "32" && username){
O_o[o_O].innerHTML = "<span style='float: right;'>" + yes + "</span>" + O_o[o_O].innerHTML;
}else if(O_o[o_O].className == "catbg" && O_o[o_O].height == "32" && !username){
O_o[o_O].innerHTML = "<span style='float: right;'>" + no + "</span>" + O_o[o_O].innerHTML;
};};
</script>

Original Request: http://revolutionx.smfforfree3.com/index.php/topic,1010.0.html

This code will add either "Welcome {user}" or "Please Login or Register" to the top where it shows your board name. If you have a banner for your forum, this code will not look very well on your forum.

Edit as you wish :)  If you put {user} in the var yes = ""; part, it will show the users' username :)

Enjoy :)


Title: Re: User Widget
Post by: Andrew on August 28, 2009, 10:40:51 pm
Lmao what's with all the 'O_o' s in there? Makes the code look kinda.. silly :D

Gonna go add this one now! Great code Agent!!  O0


Title: Re: User Widget
Post by: Exilis on August 29, 2009, 09:03:33 am
Ah yes I love the variable names.


Title: Re: User Widget
Post by: KrylonKrystals on August 29, 2009, 09:47:41 am
Thanks again moose! :)


Title: Re: User Widget
Post by: Nick on August 29, 2009, 11:56:36 am
Awesome code :)


Title: Re: User Widget
Post by: Agent Moose on August 29, 2009, 06:33:10 pm
Glad all of yall like :)


Title: Re: User Widget
Post by: KrylonKrystals on August 30, 2009, 09:14:59 pm
Hey moose I've got a question.. Is it possible to make the code wrapped in <span class= "smalltext"> html? Also, is there a way maybe I can possible move the thing out of catbg? I see you have it in the code, I tried didn't succeed well in doing that maybe you can take a look at my forum for a better spot?

http://gamerscoreachievements.smfforfree3.com (not advertising)

- Thanks again
KrylonKrystals