:User:Pixelface/monobook.js

// 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:/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 Wikimedia's Amazon Referral reference. That means if you click on

// the ISBN link, go to Amazon and end up buying the book, Wikimedia will earn some small amount

// of money from that sale. If you don't want to support Wikimedia in this way, but do want ISBNs

// to link to Amazon, replace the current magicURL with "http://www.amazon.com/gp/search?ie=UTF8&field-isbn=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.)

var magicURL = "http://www.amazon.com/gp/search?ie=UTF8&field-isbn=MAGICNUMBER";

importScript('User:Lunchboxhero/externISBN.js');

// Addtabs, added 2007-12-17

////////////////////////////////////////////////////////////////

// =-=-=- HELPER FUNCTIONS -=-=-=-

function addlilink(tabs, url, name, id, title, key){

var na = document.createElement('a');

na.href = url;

na.appendChild(document.createTextNode(name));

var li = document.createElement('li');

if(id) li.id = id;

li.appendChild(na);

tabs.appendChild(li);

if(id)

{

if(key && title)

{

ta[id] = [key, title];

}

else if(key)

{

ta[id] = [key, ''];

}

else if(title)

{

ta[id] = ['', title];

}

}

// re-render the title and accesskeys from existing code in wikibits.js

akeytt();

return li;

}

function addToolboxLink(url, name, id){

var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];

addlilink(tb, url, name, id);

}

function addTab(url, name, id, title, key) {

return mw.util.addPortletLink('p-cactions', url, name, id, title, key);

}

function addLink(where, url, name, id, title, key, after){

var na = document.createElement('a');

na.href = url;

na.appendChild(document.createTextNode(name));

var li = document.createElement('li');

if(id) li.id = id;

li.appendChild(na);

var tabs = document.getElementById(where).getElementsByTagName('ul')[0];

if(after) {

tabs.insertBefore(li,document.getElementById(after));

} else {

tabs.appendChild(li);

}

if(id) {

if(key && title) { ta[id] = [key, title]; }

else if(key) { ta[id] = [key, '']; }

else if(title) { ta[id] = ['', title];}

}

// re-render the title and accesskeys from existing code in wikibits.js

akeytt();

return li;

}

function addlimenu(tabs, name, id)

{

var na = document.createElement('a');

na.href = '#';

var mn = document.createElement('ul');

na.appendChild(document.createTextNode(name));

var li = document.createElement('li');

li.id = id;

li.className = 'tabmenu';

li.appendChild(na);

li.appendChild(mn);

tabs.appendChild(li);

return li;

}

function addnavbox_link(URL,Name,ID)

{

var portlet = document.getElementById('p-navigation');

var links = portlet.getElementsByTagName('ul')[0];

links.innerHTML += '

  • ' + Name + '
  • ';

    }

    /////////////////////////////////////////////

    // History, added 2007-12-17

    //{{PAGENAME}}

    //Helper tools

    //admin list

    document.write('');

    //bot list

    document.write('');

    document.write('');

    //

    //History stats tabs

    $(addhiststats)

    function addhiststats()

    {

    if (location.href.indexOf('&action=history') !=-1 && location.href.indexOf('&jsaction=validate') ==-1)

    {

    addTab("javascript:histstats()", "%", "ca-stats", "History statistics", "");

    if (wgNamespaceNumber==0)

    {addTab("http://vs.aka-online.de/cgi-bin/wppagehiststat.pl?lang=en&page=" + wgPageName, "tree", "ca-editors", "Editor statistics", "");}

    }

    else if (location.href.search(/Special:(Undelete\/|Undelete.*&target=)/) !=-1 && location.href.search(/×tamp=|&action=submit/) == -1)

    {

    addTab("javascript:histstats()", "%", "ca-stats", "Revision statistics", "");

    }

    else if (location.href.search(/=(Special:Log|Special%3ALog).*&user=[^&]+/) !=-1 && location.href.search(/=Special:Log\/|&type=\w/) ==-1)

    {

    addTab("javascript:logstats()", "%", "ca-stats", "User's log statistics", "");

    addTab("javascript:masterview(5000)", "5k", "ca-v5k", "view last 5000 actions", "");

    }

    else if (document.title.indexOf('User contributions') == 0)

    {

    addTab("javascript:sumperentcuse()", "%", "ca-sumuse", "User's edit statistics", "");

    addTab("javascript:masterview(5000)", "5k", "ca-v5k", "view last 5000 edits", "");

    if (location.href.search(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) ==-1)

    addTab("javascript:get_userlist_xml()", "$", "ca-rts", "Shows user groups", "");

    }

    else if (document.title.search(/User:|User talk:/) == 0 && document.title.indexOf('/') == -1 && location.href.search(/Special:/) ==-1)

    {addTab("javascript:get_userlist_xml()", "$", "ca-stats6", "Shows user groups", "");}

    }

    //END

    function logstats()

    {

    //monobook

    if (document.getElementById('bodyContent'))

    {

    var body = document.getElementById('bodyContent');

    }

    //cologneblue

    else if (document.getElementById('quickbar'))

    {

    if (!document.getElementById('content')){return;}

    var body = document.getElementById('content');

    }

    if (document.getElementById('contentSub').innerHTML.indexOf('Viewing log statistics ') !=-1)

    {alert("Results already shown."); return;}

    var protects = 0;

    var unprotects = 0;

    var deletes = 0;

    var undeletes = 0;

    var blocks = 0;

    var range_blocks = 0;

    var unblocks = 0;

    var moves = 0;

    var rights = 0;

    var botsf = 0;

    var botsd = 0;

    var renames = 0;

    var uploads = 0;

    var other = 0;

    if (!body.getElementsByTagName('ul')[0])

    {alert('No log events found!'); return;}

    var l = body.getElementsByTagName('ul')[0].getElementsByTagName('li');

    for (var i=0; i

    {

    var html = l[i].innerHTML;

    if (html.indexOf(') moved ) uploaded ") blocked "

    {range_blocks += 1;}

    else if (l[i].getElementsByTagName('a')[4].innerHTML.search(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d\d/) !=-1)

    {range_blocks += 1;}

    }

    else if (html.indexOf(') unblocked ) protected ) unprotected ) deleted ") restored "

    {rights += 1;}

    else if (html.indexOf('\(Renamed the user') !=-1)

    {renames += 1;}

    else if (html.indexOf('/a>) granted bot status to ) removed bot status from events shown on this page'

    //

    var TimeDATE = 'Time range: ' + Daylength + ' approximate day(s) of log items on this page
    ' + 'Current time: ' + current_date + ' || Oldest action on: ' + last_date + ' (UTC)
    ';

    //

    document.getElementById('bodyContent').innerHTML = '

    ' + document.getElementById('contentSub').innerHTML + '
    ' + TimeDATE + 'Average actions per day: ' + Math.round((100)*average)/100 + ' (for last ' + E + ' actions(s))
    ' + 'User actions:
    ' + 'Page moves: ' + Math.round((100)*(100*(moves)/E))/100 + '% (' + moves + ' actions(s))
    ' + 'Uploads: ' + Math.round((100)*(100*(uploads)/E))/100 + '% (' + uploads + ' actions(s))
    ' + 'Sysop actions:
    ' + 'Page protects: ' + Math.round((100)*(100*(protects)/E))/100 + '% (' + protects + ' actions(s))
    ' + 'Page unprotects: ' + Math.round((100)*(100*(unprotects)/E))/100 + '% (' + unprotects + ' actions(s))
    ' + 'Deletes: ' + Math.round((100)*(100*(deletes)/E))/100 + '% (' + deletes + ' actions(s))
    ' + 'Undeletes: ' + Math.round((100)*(100*(undeletes)/E))/100 + '% (' + undeletes + ' actions(s))
    ' + 'Blocks: ' + Math.round((100)*(100*(blocks)/E))/100 + '% (' + blocks + ' actions(s)) (' + range_blocks + ' range block(s))
    ' + 'Unblocks: ' + Math.round((100)*(100*(unblocks)/E))/100 + '% (' + unblocks + ' actions(s))
    ' + 'Bureaucrat actions:
    ' + 'Promotions: ' + Math.round((100)*(100*(rights)/E))/100 + '% (' + rights + ' actions(s))
    ' + 'Bot flaggings: ' + Math.round((100)*(100*(botsf)/E))/100 + '% (' + botsf + ' actions(s))
    ' + 'Bot de-flaggings: ' + Math.round((100)*(100*(botsd)/E))/100 + '% (' + botsd + ' actions(s))
    ' + 'Renames: ' + Math.round((100)*(100*(renames)/E))/100 + '% (' + renames + ' actions(s))
    ' + body.innerHTML.split('')[1];

    }

    function masterview(number)

    {

    if (location.href.search(/&limit=\d+/) !=-1)

    {

    var limit = location.href.match(/&limit=\d+/g)[0];

    var url = location.href.replace(limit,'&limit=' + number);

    }

    else if (location.href.indexOf('Special:Contributions/') !=-1)

    {

    var name = location.href.split('Special:Contributions/')[1];

    var url = '/w/index.php?title=Special:Contributions&limit=' + number + '&target=' + name;

    }

    else

    {var url = location.href + '&limit=' + number;}

    location.href = url;

    }

    //***********************

    //standard XML Support

    function HTTPClient()

    {

    var gml_http;

    if(window.XMLHttpRequest) {

    gml_http = new XMLHttpRequest();

    } else if (window.ActiveXObject) {

    try {

    gml_http = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

    try {

    gml_http = new ActiveXObject("Microsoft.XMLHTTP");

    } catch (E) {

    gml_http = false;

    }

    }

    }

    return gml_http;

    }

    function gml_XMLParse(string) {

    if (document.implementation.createDocument) {

    var gml_xmlparser = new DOMParser()

    return gml_xmlparser.parseFromString(string, "text/xml");

    } else if (window.ActiveXObject) {

    var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");

    gml_xmldoc.async = "false";

    ret = gml_xmldoc.loadXML(string);

    if (!ret)

    return null;

    return gml_xmldoc.documentElement;

    }

    return null;

    }

    //END

    //**********

    function get_userlist_xml()

    {

    document.getElementById('contentSub').innerHTML += '
    Searching for current usergroup information.' + '\n' + 'Please wait...';

    gml_xmlhttp = HTTPClient();

    if (!gml_xmlhttp)

    return;

    if (document.title.indexOf('User:') == 0)

    {user_name = document.title.split('User:')[1].split(' - ')[0];}

    else if (document.title.indexOf('User talk:') == 0)

    {user_name = document.title.split('User talk:')[1].split(' - ')[0];}

    else

    {user_name = document.getElementById('contentSub').getElementsByTagName('a')[0].innerHTML;}

    var pageurl = '/w/index.php?title=Special:Listusers&group=&username=' + user_name;

    gml_xmlhttp.open("GET", pageurl, true);

    gml_xmlhttp.onreadystatechange = alertget;

    gml_xmlhttp.send(null);

    }

    function getusergroup()

    {

    gml_xmlhttp = HTTPClient();

    if (!gml_xmlhttp)

    return;

    var pageurl = '/w/index.php?title=Special:Listusers&group=sysop&limit=5000';

    gml_xmlhttp.open("GET", pageurl, true);

    gml_xmlhttp.onreadystatechange = userget;

    gml_xmlhttp.send(null);

    }

    function alertget()

    {

    if (gml_xmlhttp.readyState != 4)

    return;

    xml = gml_xmlhttp.responseText.replace(//, '');

    doc = gml_XMLParse(xml);

    var rights = '(username invalid)';

    if (doc.getElementsByTagName('li')[0])

    {rights = doc.getElementsByTagName('li')[0].innerHTML;}

    if (user_name.indexOf('FAQ') !=-1)

    {user_name = document.getElementById('bodyContent').getElementsByTagName('a')[1].innerHTML;}

    document.getElementById('contentSub').innerHTML += '
    ' + rights + '';

    }

    function userget()

    {

    if (gml_xmlhttp.readyState != 4)

    return;

    alert("Usergroup list obtained. Seaching for " + user_name + ".");

    xml = gml_xmlhttp.responseText.replace(//, '');

    doc = gml_XMLParse(xml);

    var l = doc.getElementsByTagName('li');

    var user_name = document.getElementById('bodyContent').getElementsByTagName('a')[0].innerHTML;

    var user_sysop = 'no';

    for (i = 0; i < l.length; i++)

    {

    var name = l[i].getElementsByTagName('a')[0].innerHTML;

    if (user_name == name){user_sysop = 'yes'; break;}

    }

    return user_sysop;

    }

    //Summary percent use

    contribs_first = true;

    STATS_ALL_JS_RAN = false;

    function sumperentcuse()

    {

    if (document.getElementById('contentSub').innerHTML.indexOf('Viewing contribution data for') !=-1)

    {alert("Results already shown."); return;}

    //check name

    rights_status = '';

    Username = 'this user';

    if (location.href.indexOf('username=') !=-1)

    {Username = location.href.split('username=')[1].split('&')[0].replace(/\+/g,' ');}

    else

    {Username = document.getElementById('bodyContent').getElementsByTagName('a')[0].innerHTML;}

    theusername = 'user ' + Username + '';

    document.getElementById('contentSub').innerHTML += "
    Analyzing contributions...please wait";

    gml_xmlhttp = HTTPClient();

    var pageurl = '/w/index.php?title=Special:Log&type=upload&user=' + Username + '&page=&limit=5000&useskin=standard';

    gml_xmlhttp.open("GET", pageurl, true);

    gml_xmlhttp.onreadystatechange = sumperentcuse2;

    gml_xmlhttp.send(null);

    }

    edits_page_compared_js = 0;

    function sumperentcuse2()

    {

    if (gml_xmlhttp.readyState != 4) return;

    xml = gml_xmlhttp.responseText;

    document.getElementById('contentSub').innerHTML += "
    Analyzing uploads...";

    Uploads = 0;

    Uploads_length = 0;

    var up_list_unique = '|';

    if (xml.indexOf('

    ')[0] + '
    ')[1];

    //from wikibits.js

    histrowinit();

    //popups

    var body = document.getElementById('bodyContent');

    body.ranSetupTooltipsAlready=false;

    setupTooltips(body);

    }

    //END

    //