User:Poke/tools.js

From Guild Wars Wiki
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
 /*<nowiki>*/
/**** function clearRecentChanges.js
 * (c) 2009 by Patrick Westerhoff [poke]
 *
 * Customize rNames and rWords to filter out entries from Special:RecentChanges.
 */
function clearRecentChanges ()
{
  if ( wgPageName !== 'Special:RecentChanges' )
    return false;
  
  var rNames, rWords, xpath, snaps, snap;
  rNames = [ 'username' ];
  rWords = [ 'Word', 'word' ]; 
  
  xpath  = '//div[@id="bodyContent"]//li/.. | //div[@id="bodyContent"]//li[';
  xpath += rNames.length > 0 ? './a[contains(@class,"mw-userlink")][contains(@title,"' + rNames.join( '") or contains(@title,"' ) + '")] or ' : '';
  xpath += rWords.length > 0 ? 'contains(a[1]/@title,"' + rWords.join( '") or contains(a[1]/@title,"' ) + '") or ' : '';
  xpath += rWords.length > 0 ? 'contains(span[@class="comment"],"' + rWords.join( '") or contains(span[@class="comment"],"' ) + '") or ' : '';
  xpath += ' 0 ]';
  snaps  = document.evaluate( xpath, document, null, 6, null );
  parent = snaps.snapshotItem( 0 );
  
  for ( var i = 1; i < snaps.snapshotLength; i++ )
    parent.removeChild( snaps.snapshotItem( i ) );
}

/**** bookmarklet clearRecentChanges.js
 * (c) 2009 by Patrick Westerhoff [poke]
 *
 * Customize the username and copy the bookmarklet code into your browser's location bar, or save as a bookmark.
 */
javascript:var user = 'People of Antioch'; var snaps = document.evaluate( '//div[@id="bodyContent"]//li/.. | //div[@id="bodyContent"]//li[./a[contains(@class,"mw-userlink")][@title="User:' + user + '"]]', document, null, 6, null ); for ( var i = 1; i < snaps.snapshotLength; i++ ) { snaps.snapshotItem( 0 ).removeChild( snaps.snapshotItem( i ) ) }; void(0);

/**** function highlightRecentChanges.js
 * (c) 2009 by Patrick Westerhoff [poke]
 *
 * Highlighs the given users or titles that contain the given text with the specified background color
 */
function highlightRecentChanges ( users, pages )
{
  if ( wgPageName != 'Special:RecentChanges' )
    return;
  
  for ( var user in users )
  {
    var snaps = document.evaluate( '//div[@id="bodyContent"]//li[./a[contains(@class,"mw-userlink")][contains(@title,"' + user + '")]]', document, null, 6, null );
    for ( var i = 0; i < snaps.snapshotLength; i++ )
      snaps.snapshotItem( i ).style.background = users[user];
  }
  for ( var page in pages )
  {
    var snaps = document.evaluate( '//div[@id="bodyContent"]//li[contains(a[1]/@title,"' + page + '")]', document, null, 6, null );
    for ( var i = 0; i < snaps.snapshotLength; i++ )
      snaps.snapshotItem( i ).style.background = pages[page];
  }
}
// example call
highlightRecentChanges( { 'Poke' : '#CEEFFF' }, { '.js' : '#FDFFCE', '.css' : '#EAFFCE' });


/**** Different more or less useful tools
 * (c) 2007-2009 by Patrick Westerhoff [poke]
 * Feel free to use
 */

/** Gem Stalker **/
hookEvent( 'load', function()
{
  if ( wgPageName != 'Special:Recentchanges' )
    return;
  
  var links = document.getElementById( 'bodyContent' ).getElementsByTagName( 'a' );
  for ( var i = 0; i < links.length; i++ )
  {
    if ( links[i].title.indexOf( 'User:Gem' ) > -1 )
      links[i].style.background = '#FCC';
  }
} );

/** Favicon changer **/
function changeFavicon( url )
{
  var head  = document.getElementsByTagName( 'head' )[0];
  var link  = document.createElement( 'link' );
  link.rel  = 'shortcut icon';
  link.type = "image/x-icon";
  link.href = url;
  var links = head.getElementsByTagName( 'link' );
  
  for ( var i = 0; i < links.length; i++ )
  {
    if ( links[i].rel == 'shortcut icon' )
    {
       head.removeChild( links[i] );
       break;
    }
  }
  head.appendChild( link );
}
// to run, call changeFavicon onload; for example with gwwt
gwwtLoadAfter = function()
{
  changeFavicon( 'http://borntolaugh.de/files/GuildWarsWiki.ico' );
}

/** Custom timezone compatible javascript clock **/
function showTime ( displayObj, timezoneOffset )
{
  var aMonths = new Array( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );
  var aDays   = new Array( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' );
  var oDays   = { 1 : 'st', 2 : 'nd', 3 : 'rd', 21 : 'st', 22 : 'nd', 23 : 'rd', 31 : 'st' };
  var date, str;
  
  function actualize()
  {
    date = new Date();
    date.setMinutes( date.getMinutes() + date.getTimezoneOffset() + timezoneOffset * 60 );
    str  = aDays[ date.getDay() ] + ', ' + date.getDate() + '<sup>'
         + ( oDays[ date.getDate() ] == undefined ? 'th' : oDays[ date.getDate() ] )
    	 + '</sup> ' + aMonths[ date.getMonth() ] + ' ' + date.getFullYear()
         + ' ' + ( date.getHours() % 12 < 10 ? '0' : '' ) + date.getHours() % 12
    	 + ':' + ( date.getMinutes() < 10 ? '0' : '' ) + date.getMinutes()
    	 + ':' + ( date.getSeconds() < 10 ? '0' : '' ) + date.getSeconds()
    	 + ' ' + ( date.getHours() < 12 ? 'am' : 'pm' );
    displayObj.innerHTML = str;
  }
  setInterval( actualize, 1000 );
  actualize();
}
showTime( document.getElementById( 'timerPDT' ), -7 );

/*</nowiki>*/