October 21, 2018, 09:46:20 am
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to Revolution X, where Coding meets Graphics.
 
  Home Help Search Arcade Affiliates Staff List Calendar Members Login Register  

Common Coding Tasks (and how to accomplish them)

Pages: [1]   Go Down
  Print  
Author Topic: Common Coding Tasks (and how to accomplish them)  (Read 424 times)
Celebrus
Artificially Conscious
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 626



View Profile WWW
Badges: (View All)
« on: May 28, 2009, 12:43:30 am »

Note: This is by no means a thorough or exhaustive list. As of now it is incomplete. If you would like to see something added to this, please reply to this topic.


Checking whether the user is logged in
This function will return true or false depending on whether the user is logged in.

Code:
function loggedIn() {
  return $('td.titlebg2 span b').not($("td.titlebg2 span b:contains(News)")).html() ? true : false;
}

Example:
Code:
if( ! loggedIn() ) {
  alert("Hey there, guest");
}


Checking whether the user is an admin
This function will return true or false depending on whether the user is logged in.

Code:
function isAdmin() {
return ($("td.maintab_back:contains('Admin')").length == 1 || $("td.maintab_active_back:contains('Admin')").length == 1)
}

Example:
Code:
if( isAdmin() ) {
  alert("Hey there, admin");
}


Notice that fits in with the forum theme
This function will return a string containing HTML that is appropriate for displaying widgets.

Code:
function widget(m) {
return ('<div class="tborder"><div class="windowbg" style="padding:8px">' + m + '</div></div>');
}

Example:
Code:
document.write( widget( 'Hey there!' ) );
« Last Edit: May 28, 2009, 12:54:18 am by Celebrus » Report Spam   Logged

Social Buttons

Agent Moose
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 1,470



View Profile WWW
Badges: (View All)
« Reply #1 on: May 28, 2009, 06:46:38 am »

Well, never thought of using the last part Tongue

Pretty nice man.
Report Spam   Logged


Celebrus
Artificially Conscious
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 626



View Profile WWW
Badges: (View All)
« Reply #2 on: May 28, 2009, 07:12:40 am »

Thanks ^_^

The main inspiration behind this thread was when I had to search through my entire post history to get the loggedIn function. I thought this would make it easier.
Report Spam   Logged

Agent Moose
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 1,470



View Profile WWW
Badges: (View All)
« Reply #3 on: May 28, 2009, 07:46:48 am »

Heh, or you can use this:
Code:
<script type="text/javascript">
var name = document.getElementsByTagName("span");
for(v=0;v<name.length;v++){
if(name[v].innerHTML.match(/Hello <b>(.*)<\/b>/i)){
var username = RegExp.$1;
};};
if(username) alert("Your logged in.")
</script>
Report Spam   Logged


Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum | Buy traffic for your forum/website

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy