Source for "Facebook Highlight Birthdays"

By Jordon Kalilich
Has 30 other scripts.


// Facebook Highlight Birthdays, a Greasemonkey user script
// Version 0.8 - July 25, 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          Facebook Highlight Birthdays
// @namespace     http://www.theworldofstuff.com/greasemonkey/
// @description   Highlights today's birthdays on your home page.
// @include       http://*.facebook.com/home.php*
// ==/UserScript==

window.gm_HighlightBirthdays = function() {
   // languages: English, Catalan, German, Spanish, French, Korean, Italian, Dutch, Japanese, Norwegian, Polish
   var birthdays = /Birthdays|Aniversaris|Geburtstage|Cumpleaños|Anniversaires|생일|Compleanni|Verjaardagen|誕生日|Fødselsdager|Urodziny/;
   var today = /(Today|Avui|Heute|Hoy|Aujourd'hui|오늘|Oggi|Vandaag|今日|I dag|Dzisiaj)\s*$/;
   // the following gets events and birthdays. either or both may be there (or neither), but birthdays is always last.
   // FOR THE OLD FACEBOOK:
   var foo = document.evaluate("//div[@class='sidebar_item birthdays']",document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
   if (foo.snapshotLength > 0) { // apparently every xpath always exists, so you actually have to look at its snapshotlength. learn something new every day!
      for (k = 0; k < foo.snapshotLength; k++) {
         birthdayBox = foo.snapshotItem(k);
         if (birthdays.test(birthdayBox.getElementsByTagName('h2')[0].innerHTML)) {
            var divs = birthdayBox.getElementsByTagName('div');
            for (i = 0; i < divs.length; i++) {
               if (divs[i].className.indexOf('sidebar_item_body') > -1) {
                  var h4s = divs[i].getElementsByTagName('h4');
                  for (j = 0; j < h4s.length; j++) {
                     if (today.test(h4s[j].innerHTML)) {
                        h4s[j].setAttribute('style','background: #fffe88 !important; font-weight: bold !important; padding: 5px 5px 0px 5px !important');
                        h4s[j].nextSibling.setAttribute('style','background: #fffe88 !important; font-weight: bold !important; padding: 0px 5px 5px 5px !important');
                     }
                  }
                  break;
               }
            }
            break;
         }
      }
   }
   else { // FOR THE NEW FACEBOOK:
      birthdayList = document.evaluate("//ul[@class='birthday_list']",document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);
      if (birthdayList) {
         var listItems = birthdayList.getElementsByTagName('li');
         for (i = 0; i < listItems.length; i++) {
            if (today.test(listItems[i].innerHTML)) {
               listItems[i].setAttribute('style','background: #fffe88 !important; font-weight: bold !important; padding: 5px !important; margin-bottom: 3px !important');
            }
         }
      }
   }
}
gm_HighlightBirthdays();

updateNotifier();

// UPDATE NOTIFIER (Version 12: June 19, 2008)
// Usage Information: http://www.theworldofstuff.com/greasemonkey/updatenotifier.html
function updateNotifier() {
//      PARAMETERS       //
var scriptName = "Facebook Highlight Birthdays";
var scriptURL = "http://userscripts.org/scripts/show/12813";
var scriptVersion = 0.8;
var updateURL = "http://www.theworldofstuff.com/greasemonkey/facebookbirthdays.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 = '50000'; 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