Jump to content

User:Chris Chittleborough/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Chris Chittleborough (talk | contribs) at 08:30, 23 October 2006 (fmt). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
  //Interiot's javascript edit counter
  if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) {
    document.write(
	'<script type="text/javascript" src="'+
	'http://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js'+
	'&action=raw&ctype=text/javascript&dontcountme=s"></script>');
  }

  // Rewrite "ISBN xxx" links. See also [[User:Lunchboxhero/monobook.js]].
  function Rewrite_ISBNs() {
    for (var i = 0; i < document.links.length; i++) {       
      if( document.links[i].href.match(
	/^http:\/\/en\.wikipedia\.org\/w\/index\.php\?title=Special:Booksources&isbn=(.*)/) )
      {
        document.links[i].href='/wiki/User:Chris_Chittleborough/Sandbox#'+RegExp.$1';
      }
    }
  }
  addOnloadHook(Rewrite_ISBNs);

  if (document.url.substring(0, 61) == "http://en.wikipedia.org/wiki/User:Chris_Chittleborough/Sandbox") {
    if (document.url.substring(62,0).match( /^#([0-9-]+X?$)/ ) {
      var isbn = RegExp.$1;
	alert('#D# Munging [[User:Chris_Chittleborough/Sandbox]] for ISBN "'+isbn+'" ...')
      var div = document.getElementById('bodyContent');
      var re = /«»/;
      var alist = document.getElementById('bodyContent').getElementsByTagName('a');
      for (var i = 0; i < alist.length; ++ i) {
	var url = alist[i].href;
	if ( url.match(re) ) {
	  alist[i].href = url.replace(re, isbn);
        }
      }
    }else{alert('#D# No ISBN to mung [[User:Chris_Chittleborough/Sandbox]] for!');}
  }