Source for "MySpace Birthdays on Homepage"

By Jordon Kalilich
Has 28 other scripts.


Add Syntax Highlighting (this will take a few seconds, probably freezing your browser while it works)

// MySpace Birthdays on Homepage, a Greasemonkey user script
// Version 2.03 - June 18, 2008
// Copyright 2007, 2008 Jordon Kalilich (http://www.theworldofstuff.com/)
// This program is free software: you may redistribute and/or modify
// it under the terms of the GNU GPL version 3 or any later version.
// http://www.gnu.org/copyleft/gpl.html
//
// ==UserScript==
// @name          MySpace Birthdays on Homepage
// @namespace     http://www.theworldofstuff.com/greasemonkey/
// @description   Lists your friends' upcoming birthdays on your homepage.
// @include       http://home.myspace.com/*?*fuseaction=user&*
// @include       http://home.myspace.com/*?*fuseaction=user
// @include       http://home.myspace.com/*?*fuseaction=user#*
// ==/UserScript==

////////////////////////////////////////////////////////////////////
///                    THE OPTIONS HAVE MOVED                    ///
///                                                              ///
/// You can set them by going to:                                ///
///    Tools -> Greasemonkey -> User Script Commands...          ///  
/// Or by right-clicking the Greasemonkey icon and going to:     ///
///    User Script Commands...                                   ///
///                                                              ///
/// Don't edit below this line unless you know what you're doing ///
////////////////////////////////////////////////////////////////////    

updateNotifier();

// determine whether we're on the old or new homepage:
var onNewHomePage = true;
if (document.getElementById('home_profileInfo')) { // if on the old homepage
   onNewHomePage = false;
}

var maxBirthdays = GM_getValue('maxBirthdays', 5);
var placement = GM_getValue('placement', 2);
var scrollList = GM_getValue('scrollList', true);
var showIfNone = GM_getValue('showIfNone', true);

// create options
GM_registerMenuCommand("Birthdays: Set Maximum...", setMaxBirthdays);
GM_registerMenuCommand("Birthdays: Set Placement...", setPlacement);
if (showIfNone == true) {
   GM_registerMenuCommand("Birthdays: Don't Show If None", function(){ GM_setValue('showIfNone', false); window.location.reload(); });
}
else {
   GM_registerMenuCommand("Birthdays: Show If None", function(){ GM_setValue('showIfNone', true); window.location.reload(); });
}
if (onNewHomePage == true) {
   if (scrollList == true) {
      GM_registerMenuCommand("Birthdays: Don't Scroll If Many", function(){ GM_setValue('scrollList', false); window.location.reload(); });
   }
   else {
      GM_registerMenuCommand("Birthdays: Scroll If Many", function(){ GM_setValue('scrollList', true); window.location.reload(); });
   }
}

function setMaxBirthdays() {
   do {
      var lala = prompt("Set the maximum number of birthdays to be shown.\nTo show all birthdays, enter 0.", GM_getValue('maxBirthdays', 5));
      // DON'T get variable maxBirthdays here. it could and probably will change below!
   }
   while ( (lala != null) && (/^\d+$/.test(lala) == false) );

   if (lala != null) { // null is if they hit cancel, so we don't want to add that. if they just hit backspace, it's an empty string, which will cause the loop above.
      GM_setValue('maxBirthdays', parseInt(lala));
      window.location.reload();
   }
}
function setPlacement() {
   do {
      var lala = prompt("Set the placement of the \"Upcoming Birthdays\" list:\n\n0: Before everything\n1: After Friend Status\n2: After Friend Subscriptions\n3: After Bulletin Space\n4: After Friend Space", placement);
   }
   while ( (lala != null) && (/^\d+$/.test(lala) == false) );

   if (lala != null) {
      GM_setValue('placement', parseInt(lala));
      window.location.reload();
   }
}

var friendIDs = new Array();
var names = new Array();
var images = new Array();
var birthdays = new Array();
var friends = new Array();
// var ages = new Array(); // from a previous version
var separator = '|BREAKHERE|';
var actualFriendCount = 0;

GM_xmlhttpRequest({
   method: 'GET',
   url: 'http://friends.myspace.com/index.cfm?fuseaction=user.birthdays', // we could use home.myspace.com so it's not cross-site, but friends seems much faster
   headers: {
      'User-agent': navigator.userAgent,
   },
   onload: function(responseDetails) {
      foo = responseDetails.responseText.match(/http:\/\/profile\.myspace\.com\/index\.cfm\?fuseaction=user\.viewprofile&friendID=\d+/ig);
      if ( (foo) && (foo.length > 1) ) { // the first hit is yours, and each of your friends has two links
         // get friend IDs
         for (i = foo.length - 1; i >= 1; i -= 2) {
            friendIDs.push(foo[i].match(/\d+/));
         }
         // get names. if a friend has quotes in their name, they won't have a proper alt tag, but the name is there. for friend " MeAn JeAn" (w/quotes):
         // alt="" MeAn JeAn"" title="...
         var foo = responseDetails.responseText.match(/<img[^>]*\s+alt="[^>]*"\s+title=[^>]*>/ig);
         for (i = foo.length - 1; i >= 0; i--) {
            foo[i] = foo[i].replace(/<img[^>]*\s+alt="([^>]*)"\s+title=[^>]*>/i,'$1');
            var namePos = 10;
            while (namePos < foo[i].length) { // inserts a <wbr> after 10 characters and every 8 thereafter
               // last character of string.substring(start, end) is the one at end - 1.
               // don't split up alt codes and stuff
               while ( (/&[^;]*$/.test(foo[i].substring(0, namePos))) && (/^[^&]*;/.test(foo[i].substring(namePos, foo[i].length))) ) {
                  namePos++;
               }
               foo[i] = foo[i].substring(0, namePos) + '<wbr>' + foo[i].substring(namePos, foo[i].length);
               namePos += 13; // 5 characters added by <wbr>, so this actually advances by 8 characters.
            }
            names.push(foo[i]);
         }
         // names now contains the people's names, in the same order as before
         var foo = responseDetails.responseText.match(/http:\/\/(\w+\.ac-images\.myspacecdn\.com[\/a-z0-9_\.]+|x\.myspace\.com\/images\/no_pic\.gif)/ig);
         for (i = foo.length - 1; i >= 0; i--) {
            images.push(foo[i]);
         }
         // and now we have the images.
         var foo = responseDetails.responseText.match(/\s{2,}[a-z]{3}\s+\d{2}\s{2,}/ig);
         for (i = foo.length - 1; i >= 0; i--) {
            foo[i] = foo[i].replace(/\s{2,}/g,''); // delete the horrible tabs that surround everything
            foo[i] = foo[i].replace(/\s+0/,' '); // delete leading zeroes from dates (to match homepage date style)
            foo[i] = foo[i].replace(/\s/,'&nbsp;'); // just because it looks annoying broken up in the final table
            birthdays.push(foo[i]);
         }
         // now we have the birthdays. good.

         GetDate();
      }
      else { // if no birthdays listed
         if (showIfNone == true) {
            BuildContainer();
         }
      }
   }
});

function AddStyles() {
   GM_addStyle('#gm_BirthdayContainer td.notFirst {background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAAAXNSR0IArs4c6QAAABFJREFUCNdj8Pb2Xs3AwMAAAAmHAY1v+Na7AAAAAElFTkSuQmCC) 0 0 repeat-x;}');
   GM_addStyle('#gm_BirthdayContainer a.links {font-size: 10px;font-weight:normal}');
   GM_addStyle('#gm_BirthdayContainer table {width: 99%}'); // if the box is in the wide column, it should have this (it's not 100% because the table would get pushed too far to the right)
   GM_addStyle('#gm_BirthdayContainer table td { padding: 4px }');
   if (scrollList == true) {
      GM_addStyle('#gm_BirthdayContainer #gm_BirthdayDivScroll {max-height: 325px; overflow-x: hidden; overflow-y: auto;}');
   }
}

function GetDate() {
   actualFriendCount = birthdays.length; // this will stick if dateContainer isn't found
   var dateContainer;
   var date;
   if (document.getElementById('lyrTime2')) { // new homepage
      dateContainer = document.getElementById('lyrTime2');
      date = dateContainer.innerHTML; //.match(/[a-z]{3,}\s+\d{1,2}/i) + ''; // ex. "Dec 6" (birthday listing would say "Dec 06")
   }
   else if (document.getElementById('home_infoBar')) { // old homepage
      dateContainer = document.getElementById('home_infoBar');
      date = dateContainer.innerHTML.match(/[a-z]{3}\s+\d{1,2}/i) + ''; // same format as new homepage?
   }
   if (date) {
      var day = date.match(/\d{1,2}/) + '';
      if (day.length == 1) day = '0' + day; // to make it sortable
      var year = dateContainer.innerHTML.match(/\d{4}/);
      var month;
      if (/Jan/i.test(date) == true) month = '01';
      else if (/Feb/i.test(date) == true) month = '02';
      else if (/Mar/i.test(date) == true) month = '03';
      else if (/Apr/i.test(date) == true) month = '04';
      else if (/May/i.test(date) == true) month = '05';
      else if (/Jun/i.test(date) == true) month = '06';
      else if (/Jul/i.test(date) == true) month = '07';
      else if (/Aug/i.test(date) == true) month = '08';
      else if (/Sep/i.test(date) == true) month = '09';
      else if (/Oct/i.test(date) == true) month = '10';
      else if (/Nov/i.test(date) == true) month = '11';
      else if (/Dec/i.test(date) == true) month = '12';
      // now we have to sort them... sigh
      // this array needs to go from 0 to 1 less than NAMES.LENGTH. your personal attributes may be captured as the last match in friendIDs, etc., but not names.
      // if you use friendIDs.length, it will complain that there is no corresponding birthdays for the last friendID (yours). you shouldn't belong there anyway.
      for (i = 0; i < names.length; i++) {
         var bMonth;
         if (/Jan/i.test(birthdays[i]) == true) bMonth = '01';
         else if (/Feb/i.test(birthdays[i]) == true) bMonth = '02';
         else if (/Mar/i.test(birthdays[i]) == true) bMonth = '03';
         else if (/Apr/i.test(birthdays[i]) == true) bMonth = '04';
         else if (/May/i.test(birthdays[i]) == true) bMonth = '05';
         else if (/Jun/i.test(birthdays[i]) == true) bMonth = '06';
         else if (/Jul/i.test(birthdays[i]) == true) bMonth = '07';
         else if (/Aug/i.test(birthdays[i]) == true) bMonth = '08';
         else if (/Sep/i.test(birthdays[i]) == true) bMonth = '09';
         else if (/Oct/i.test(birthdays[i]) == true) bMonth = '10';
         else if (/Nov/i.test(birthdays[i]) == true) bMonth = '11';
         else if (/Dec/i.test(birthdays[i]) == true) bMonth = '12';
         var bDay = birthdays[i].match(/\d{1,2}/) + ''; // makes it a string, otherwise the length property is screwy
         if (bDay.length == 1) bDay = '0' + bDay; // to make it sortable
         var bYear;
         if ((month == '12') && (bMonth == '01')) {
            bYear = year + 1;
         }
         else {
            bYear = year;
         }
         if (bYear + bMonth + bDay >= year + month + day) { // don't include birthdays that have passed!
            if ((bYear + bMonth + bDay) == (year + month + day)) {
               birthdays[i] = "Today";
            }
            friends.push(bYear + bMonth + bDay + separator + friendIDs[i] + separator + names[i] + separator + images[i] + separator + birthdays[i]);
         }
      }
      actualFriendCount = friends.length;
      if (friends.length) friends.sort();
      for (i = 0; i < friends.length; i++) {
         foo = friends[i].split(separator);
         friendIDs[i] = foo[1];
         names[i] = foo[2];
         images[i] = foo[3];
         birthdays[i] = foo[4];
      }
      actualFriendCount = friends.length; //still
   }
   if ( (showIfNone == true) || (actualFriendCount > 0) ) { // I did the truth table for this. it makes sense.
      BuildContainer();
   }
}

function BuildContainer() {

   var addViewAllLink = false;
   if (actualFriendCount > 0) {
      // this uses actualFriendCount cause it excludes friends whose birthdays have passed. when birthdays is reused, there may be fewer than to completely overwrite the array.
      if ( ( (maxBirthdays != 0) && (actualFriendCount > maxBirthdays) ) || (actualFriendCount >= 40) ) { // I think 40 is the most you'll see on one page. Can anyone verify?
         addViewAllLink = true;
      }
      if ( (maxBirthdays == 0) || (actualFriendCount < maxBirthdays) ) {
         maxBirthdays = actualFriendCount;
      }
   }

   if (onNewHomePage == true) { // if on new homepage (duh)

   AddStyles();
   var birthdayContainer = document.createElement('div');
   birthdayContainer.className = 'module';
   birthdayContainer.id = 'gm_BirthdayContainer';
   birthdayContainer.innerHTML = '<h4 class="top"><div><div><span class="title"><span id="moodicon" style="background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAASCAYAAAC5DOVpAAAAAXNSR0IArs4c6QAAA0dJREFUOMuVlF1M21UYxn/n33YttJRB1Q3EUGBipw5Q9oEI4rKELJrtYgnGRG90S0ThZujMnDfzwsQYEz+iN35gdB8xGuMutmgWnehEFGGb2Vg7QyIwHEhhnW2htMD/8cJiELcle5L34s057y/nyXPywjUkyUi6Q9JJSX9KOiXpMUlVknySzPIZi+vLAJ64w6XhYQrHxtgN7AU2AXn/A0pyScqXVLisApLqJJ1pNZsTIOXlaeD8eZ2T9ImkZkkrlwKNpCpgI+C/yqtuBh61LAK5zqTvvqJvqSieOvPG4SrbU3bvBeAj4CcgboyRkdQZT8dr932zbxxg3TA8MPAPrbSjoyS3vDzodmbstupXfc+tfx0A23dTf+DpA+Ss2fgb0AlcAOaMpL8aDjac7jbdTQC3h+GFQ/DgEMRDoR9DXV2V+7e96Xl2w3s+n2cFAOn5BRLO/P5A22E7p7w2DEQB2wL83aPdTQThnjLD3s1OavY4Ka22mItE6jPj4/En73ybRRCA2+nASk7WpodOzwMPNTRQAzzuXLxQaQzv5xdSc/dtsAHssj/Q7slrxnww0so7jzwcSFmMRKM0LH6NS0d2HDnlPwvrXC4svx/L74fKFYQ6XzrpDYV8JS8eH5mIz/wLSs5m2LJ1oeuL40Uzx44x09vLz8DvRlK7LfuJxNSX5F7etdZVUZEDMD80NGtWvtXnCOwYkewts4O9sdGXm0sAvNVb+4raD9xlXO6jwFdADJCRtBpoBtoWpj5TItxaLhnLX/lKxLFqlw/okb2wPT0anl1q01VQ5HLkBb7OpjkApJzARJZuOQItO3+4kvNLKpUyLY0tq4FfgcZEz6cXYx8+s+k/sDV1393yVOd6Z0HRFDAJDFrGGDvbnAA+TyaTl6anp6NAH1Bx5cQHscTH7dWr8nNZWu7R/qbouzsvz8fG7geCgMsCyAITwFgwGBzPZDJ2OBxOAL6JQ88XF3jdnuVpet0u5gd7mtIXz2UAN2CcS87TwEhdXV2hbdtzDofDA9jcgJbCZoEIkKmvr/cAtwJNQP4Nw7JWY0B/dpuUAkNlr50tHu4ITQPe5cMF2/Z8n7O20QPMXNeFpFxJ2yVFJNm6uiYk7ZdUKsnxN4CmnexbHpNSAAAAAElFTkSuQmCC) no-repeat scroll 0% ! important"></span>Upcoming Birthdays</span><div style="padding: 0pt; clear: both;"></div></div></div></h4>';
   var divMiddle = document.createElement('div');
   divMiddle.className = 'middle';
   birthdayContainer.appendChild(divMiddle);

   var divScroll = document.createElement('div');
   divScroll.id = 'gm_BirthdayDivScroll';
   divMiddle.appendChild(divScroll);

   var birthdayTable = document.createElement('table');
   birthdayTable.id = 'gm_birthdays';
   birthdayTable.style.margin = '2px ! important';
   divScroll.appendChild(birthdayTable);

   if (actualFriendCount > 0) {
      var trBirthdayString = ''; // this will be used so we don't have to get the style for the birthday rows every time
      for (i = 0; i < maxBirthdays; i++) {
         var trStyleString = '';
         if (birthdays[i] == 'Today') {
            if (trBirthdayString == '') {
               var birthdayTodayBackground = '#fff9d2';
               var backgroundExample = document.getElementById('divStatusMood');
               if (backgroundExample) {
                  // we have to get all the background properties separately
                  birthdayTodayBackground = document.defaultView.getComputedStyle(backgroundExample,null).getPropertyValue('background-color');
               }
               trStyleString = ' style="background: ' + birthdayTodayBackground + '"';
               trBirthdayString = trStyleString;
            }
            else {
               trStyleString = trBirthdayString;
            }
         }
         var tdClassString = ' class="notFirst"';
         if (i == 0) {
            tdClassString = '';
         }
         birthdayTable.innerHTML += '<tr' + trStyleString + '><td' + tdClassString + '><a href="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=' + friendIDs[i] + '"><img src="' + images[i] + '" width="45" style="border: 0px"></a></td><td style="width: 100%"' + tdClassString + '><a href="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=' + friendIDs[i] + '">' + names[i] + '</a><br /><a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID=' + friendIDs[i] + '" class="links">Send Message</a> - <a href="http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm&friendID=' + friendIDs[i] + '" class="links">Add Comment</a></td><td' + tdClassString + '>' + birthdays[i] + '</td></tr>';
      }
   }
   else {
      birthdayTable.innerHTML = '<tr><td>None of your friends have upcoming birthdays this week!</td></tr>';
   }

   if (addViewAllLink == true) {
      var rightTextTransform = 'none';
      var rightExample = document.evaluate("//div[@class='right']",document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);
      if (rightExample) {
         rightTextTransform = document.defaultView.getComputedStyle(rightExample,null).getPropertyValue('text-transform'); // could be 'capitalize'
      }
      var divRight = document.createElement('div');
      divRight.className = 'right';
      divRight.innerHTML = '<span class="viewall" style="text-transform: ' + rightTextTransform + '"><a href="http://friends.myspace.com/index.cfm?fuseaction=user.birthdays" class="white">view all</a></span><div style="clear:both;padding:0;"></div>';
      divMiddle.appendChild(divRight);
   }

   var divBottom = document.createElement('div');
   divBottom.className = 'bottom';
   divBottom.innerHTML = '<div><div>&nbsp;</div></div>';
   birthdayContainer.appendChild(divBottom);

   switch (placement) {
      case 0: // "before everything"
         var col2 = document.getElementById('col2');
         col2.insertBefore(birthdayContainer, col2.firstChild);
         break;
      case 1: // after friend status
         var userstatus = document.getElementById('userstatus');
         userstatus.parentNode.insertBefore(birthdayContainer, userstatus.nextSibling);
         break;
      case 3: // after bulletin space
         var bulletins = document.getElementById('bulletins');
         bulletins.parentNode.insertBefore(birthdayContainer, bulletins.nextSibling);
         break;
      case 4: // after friend space
         var friendspace = document.getElementById('friendspace');
         friendspace.parentNode.insertBefore(birthdayContainer, friendspace.nextSibling);
         break;
      default: // after friend subscriptions
         var friendupdate = document.getElementById('friendUpdate');
         friendupdate.parentNode.insertBefore(birthdayContainer, friendupdate.nextSibling);
   }

   } else { // if on old homepage

   var birthdayTableContainer = document.createElement('div');
   birthdayTableContainer.id = 'gm_birthdayContainer';
   birthdayTableContainer.className = 'section';
   birthdayTableContainer.innerHTML = '<h5 class="heading">Upcoming Birthdays</h5>';

   // this div has a padding that keeps the table from busting out
   var containerDiv = document.createElement('div');
   containerDiv.style.padding = '2px 2px 0px 2px';
   containerDiv.style.overflow = 'hidden';
   birthdayTableContainer.appendChild(containerDiv);

   var birthdayTable = document.createElement('table');
   birthdayTable.id = 'gm_birthdays';
   birthdayTable.className = 'cols';
   birthdayTable.width = '99%';
   birthdayTable.style.border = '7px solid #fff';

   if (actualFriendCount > 0) {
      var unbrokenName;
      for (i = 0; i < maxBirthdays; i++) {
         unbrokenName = names[i].replace(/<wbr>/ig,'');
         if (birthdays[i] == 'Today') {
            birthdays[i] = '<b>' + birthdays[i] + '</b>';
         }
         birthdayTable.innerHTML += '<tr><td><a href="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=' + friendIDs[i] + '">' + names[i] + '</a></td><td><a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID=' + friendIDs[i] + '" title="Send a message to ' + unbrokenName + '">M</a></td><td><a href="http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm&friendID=' + friendIDs[i] + '" title="Post a comment about ' + unbrokenName + '">C</a></td><td>' + birthdays[i] + '</td></tr>';
      }
   }
   else {
      birthdayTable.innerHTML = '<tr><td>None of your friends have upcoming birthdays this week!</td></tr>';
   }

   containerDiv.appendChild(birthdayTable);

   if (addViewAllLink == true) {
      birthdayTableContainer.style.paddingBottom = '5px';
      newBirthdayLink = document.createElement('a');
      newBirthdayLink.href = 'http://friends.myspace.com/index.cfm?fuseaction=user.birthdays';
      newBirthdayLink.innerHTML = 'View All Upcoming Birthdays';
      newBirthdayLink.style.margin = '7px';
      containerDiv.appendChild(newBirthdayLink);
   }

   switch (placement) {
      case 0: // "before everything" (before friend subscriptions)
         var subscriptions = document.getElementById('home_activities');
         subscriptions.parentNode.insertBefore(birthdayTableContainer, subscriptions);
         break;
      case 1: // after friend status
         var statusBox = document.getElementById('StatusBox');
         statusBox.parentNode.insertBefore(birthdayTableContainer, statusBox.nextSibling);
         break;
      case 3: // after bulletin space
         var bulletinTable = document.getElementById('home_bulletins');
         bulletinTable.parentNode.insertBefore(birthdayTableContainer, bulletinTable.nextSibling);
         break;
      case 4: // after friend space
         var friendTable = document.getElementById('home_friends');
         friendTable.parentNode.insertBefore(birthdayTableContainer, friendTable.nextSibling);
         break;
      default: // after friend subscriptions
         var subscriptions = document.getElementById('home_activities');
         subscriptions.parentNode.insertBefore(birthdayTableContainer, subscriptions.nextSibling);
   }

   } // end of if statement
}

// this isn't in a function. just do it, ok? (get rid of birthday link in top 8 section)
if (onNewHomePage == true) {
   var origBirthdayLink = document.getElementById('viewFriendBirthdays');
   if (origBirthdayLink) {
      var origBirthdayLinkContainer = origBirthdayLink.parentNode;
      origBirthdayLinkContainer.removeChild(origBirthdayLink);
      origBirthdayLinkContainer.innerHTML = origBirthdayLinkContainer.innerHTML.replace(/\|\s*$/,'');
   }
}
else {
   var origBirthdayLinkContainer = document.getElementById('home_friendsTop8');
   var origBirthdayLink = origBirthdayLinkContainer.getElementsByTagName('a')[1];
   origBirthdayLink.parentNode.removeChild(origBirthdayLink);
}

// UPDATE NOTIFIER (Version 11: May 30, 2008)
// Usage Information: http://www.theworldofstuff.com/greasemonkey/updatenotifier.html
function updateNotifier() {
//      PARAMETERS       //
var scriptName = "MySpace Birthdays on Homepage";
var scriptURL = "http://userscripts.org/scripts/show/10174";
var scriptVersion = 2.03;
var updateURL = "http://www.theworldofstuff.com/greasemonkey/myspacebirthdays.txt";
var updateInterval = 3600;
//   END OF PARAMETERS   //
var checkForUpdates = GM_getValue('checkForUpdates', true);
if (checkForUpdates == true) {
var lastCheck = GM_getValue('lastCheck', 0);
var d = new Date();
var currentTime = Math.round(d.getTime() / 1000); // Unix time in seconds
if (currentTime >= lastCheck + updateInterval) {
   GM_xmlhttpRequest({
    method: 'GET',
    url: updateURL,
    headers: {'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey','Accept': 'text/plain',},
    onload: function(responseDetails) {
      if (responseDetails.status == 200) {
        var info = responseDetails.responseText;
        function createNotice(noticeText) {
           var notice = document.createElement('div');
           with (notice.style) { id = 'GMscriptnotice'; position = 'fixed'; top = '0px'; left = '0px'; width = '100%'; background = '#ffeb7c'; zIndex = '1000'; textAlign = 'center'; font = '12px sans-serif'; fontWeight = 'normal'; color = '#000'; padding = '5px 3px 5px 3px'; margin = '0px'; borderTop = '0px'; borderRight = '0px'; borderBottom = '1px solid #beaf5d'; borderLeft = '0px'; }
           notice.innerHTML = noticeText;
           document.getElementsByTagName('body')[0].appendChild(notice);
           if (document.getElementById('offLink')) {
              document.getElementById('offLink').addEventListener('click', function(event) {
                 event.stopPropagation();
                 event.preventDefault();
                 var confirmTurnOff = confirm('Are you sure you no longer want to be notified of updates to this script?');
                 if (confirmTurnOff) {
                    alert('You will no longer be notified of updates to ' + scriptName + '. You can change this preference in about:config.');
                    GM_setValue('checkForUpdates', false);
                    notice.parentNode.removeChild(notice);
                 }
              }, true);
           }
           if (document.getElementById('ignoreLink')) {
              document.getElementById('ignoreLink').addEventListener('click', function(event) {
                 event.stopPropagation();
                 event.preventDefault();
                 alert('You will not be notified until the script is updated again.');
                 GM_setValue('ignoreVersionNumber', versionOnSite.toString());
                 notice.parentNode.removeChild(notice);
              }, true);
           }
           document.getElementById('closeLink').addEventListener('click', function(event) {
              event.stopPropagation();
              event.preventDefault();
              notice.parentNode.removeChild(notice);
           }, true);
        }
        var linkStyle = 'color: #00f; text-decoration: underline; font: 12px sans-serif';
        if (info.match(/^[\d\.]+/)) {
           var ignoreVersionNumber = parseFloat(GM_getValue('ignoreVersionNumber', '0'), 10);
           var versionOnSite = info.match(/[\d\.]+/);
           if (info.indexOf(';') > 0) {
              scriptURL = info.split(";")[1];
           } 
           if ((versionOnSite > scriptVersion) && (versionOnSite > ignoreVersionNumber)) {
              createNotice('An update to the Greasemonkey user script "' + scriptName + '" is available. You are using version ' + scriptVersion + '.<br /><a href="' + scriptURL + '" style="' + linkStyle + '; font-weight: bold" id="upgradeLink">Review changes and upgrade to version ' + versionOnSite + '</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" style="' + linkStyle + '; font-weight: normal" id="ignoreLink">Wait until next version</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" style="' + linkStyle + '; font-weight: normal" id="offLink">Turn off these notifications</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" style="' + linkStyle + '; font-weight: normal" id="closeLink">Close</a>');
           }
        }
        else if (info.indexOf('-') == 0) { // if the script will no longer be maintained
           GM_setValue('checkForUpdates', false);
           if (info.indexOf(';') == 1) {
              scriptURL = info.split(";")[1];
              createNotice('The Greasemonkey user script "' + scriptName + '" will no longer be updated.<br /><a href="' + scriptURL + '" style="' + linkStyle + '; font-weight: bold" id="upgradeLink">More information</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" style="' + linkStyle + '; font-weight: normal" id="closeLink">Close</a>');
           }
        }
      }
    }
   });
   GM_setValue('lastCheck', currentTime);
}
}
} // END OF UPDATE NOTIFIER