Jump to content

User:Quiddity/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Quiddity (talk | contribs) at 01:30, 28 March 2008 (isbn to end). 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.
//Highlight admin names
importScript('User:Ais523 non-admin/adminrights.js');


// [[User:Dschwen/highlightredirects.js]] - please include this line 
document.write('<script type="text/javascript" src="' 
+ 'http://en.wikipedia.org/w/index.php?title=User:Dschwen/highlightredirects.js' 
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');


importScript('User:Magnus Manske/fixdisambig.js');


//See [[Wikipedia:WikiProject User scripts/Scripts/Show last diff]]
// Originally based on http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510  
// addLastDiff
function addLastDiff()
{addPortletLink('p-cactions', 'http://en.wikipedia.org/w/index.php?title=' + wgPageName + "&diff=cur&oldid=prev", 'last', 'ca-last', 'Show most recent diff');}
addOnloadHook(addLastDiff);


//Twinkle bits
importScript('User:AzaToth/morebits.js');
importScript('User:AzaToth/twinklefluff.js');
importScript('User:AzaToth/twinklewarn.js');
TwinkleConfig = {
        userTalkPageMode                :       'tab',
        openTalkPage                    :       [ 'agf', 'norm', 'vand' ],
        showSharedIPNotice              :       false,
        summaryAd                       :       "",
        deletionSummaryAd               :       " using [[WP:TWINKLE|TW]]",
        protectionSummaryAd             :       " using [[WP:TWINKLE|TW]]",
};


//This script (taken from [[User:ais523/highlightmyname2.js]]) highlights all instances of the
//logged-in user's username on pages by giving them a bright background. It only checks
//bodyContent, not titles or sidebars, and doesn't change edit windows or Special:Preferences.
function highlightmyname(n,p) //node, parent node
{while(n!=null)
  {if(n.nodeType==3) //text node
    {if(n.data.toLowerCase().indexOf(wgUserName.toLowerCase())!=-1)
       {var ix=n.data.toLowerCase().indexOf(wgUserName.toLowerCase());
        var t1=ix?document.createTextNode(n.data.substr(0,ix)):null;
        var t2=document.createTextNode(n.data.substr(ix,wgUserName.length));
        var t3=ix+wgUserName.length==n.data.length?null:
          document.createTextNode(n.data.substr(ix+wgUserName.length));
        var s1=document.createElement("SPAN");
        s1.style.backgroundColor="#82D9AD";
        s1.appendChild(t2);
        var s2=document.createElement("SPAN");
        if(t1!=null) s2.appendChild(t1);
        s2.appendChild(s1);
        if(t3!=null) s2.appendChild(t3);
        p.replaceChild(s2,n);
        if(t3!=null) highlightmyname(t3,s2); //find remaining occurences in the new nodes
        n=s2.nextSibling;}
      else
        n=n.nextSibling;}
    else
    {if(n.firstChild!=null) highlightmyname(n.firstChild,n);
      n=n.nextSibling;}}}
addOnloadHook(function() {
  if(location.href.indexOf("?quiddity")==-1&&location.href.indexOf("&quiddity")==-1&&
     location.href.indexOf("?action=edit")==-1&&location.href.indexOf("?action=submit")==-1&&
     location.href.indexOf("&action=edit")==-1&&location.href.indexOf("&action=submit")==-1&&
     location.href.indexOf("&action=raw")==-1&&wgPageName!="Special:Preferences")
    highlightmyname(document.getElementById('bodyContent').firstChild,
                    document.getElementById('bodyContent'));
});

//This code will change ISBN links to point to the url of your choice,
//instead of Special:Booksources. 
//
//How to use it:
//
//First, you must copy this code to your user javascript page. This is 
//at User:<your username>/monobook.js . My username is Lunchboxhero so
//my javascript page is User:Lunchboxhero/monobook.js . You must be logged
//in to edit your javascript page.
//
//Once you have copied the code and saved the page, you need to refresh your
//browser's cache. For Mozilla/Safari/Konqueror: hold down Shift while clicking 
//Reload (or press Ctrl-Shift-R), IE: press Ctrl-F5, Opera: press F5.
//
//The code should now work, as long as you are logged in.
//
//You can change the destination URL.  Go to [[Wikipedia:Book sources]] and copy 
//the URL of the site you want to use (right-click the link, then click "Copy Link 
//Location", "Copy Target", or similar).  Put the new URL between the quotes next 
//to magicURL, in place of the URL now there.
//
//The current magicURL includes Wikipedia's Amazon Referral reference. That means if you click on 
//the ISBN link, go to Amazon and end up buying the book, Wikipedia will earn some small amount
//of money from that sale.  If you don't want to support Wikipedia in this way, but do want ISBNs
//to link to Amazon, replace the current magicURL with "http://www.amazon.com/exec/obidos/ASIN/MAGICNUMBER"
//
//Good luck, and if you have any questions, leave a comment on the discussion
//page of User:Lunchboxhero/monobook.js . Thanks to Superm401 and drrngravy for their
//improvements.
//
//(Every line that starts with "//" is a comment and can be discarded.)
 
function externISBN() {
 
  var magicURL = "http://www.amazon.com/exec/obidos/ASIN/MAGICNUMBER/wikipedia08-20";
 
  var magicRegex = /MAGICNUMBER/ig;
  if(wgPageName != "Special:BookSources" && !(wgTitle == "Book sources" && wgCanonicalNamespace == "Project")){
    for (var i = 0; i < document.links.length; i++) {       
      if( document.links[i].href.match(/Special:Booksources\/(.*)/) ) {
        document.links[i].href=magicURL.replace(magicRegex, RegExp.$1);
      }
    }
  }
 
}
 
addOnloadHook(externISBN);