Jump to content

User:Rschmertz/monobook.js

From Wikipedia, the free encyclopedia
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.
// VIEW SOURCE
$(function () {
   console.log("in anonymous function for adding viewsource tab");

  if (location.href.indexOf('viewsource=1') != -1) {
    sl = document.getElementById('wpSummaryLabel');
    sl.parentNode.removeChild(sl);

    ed = document.getElementById('wpSummary').parentNode;
    ed.parentNode.removeChild(ed);
    return;
  }
  editbutton = document.getElementById('ca-edit');
  if (editbutton && location.href.indexOf('action=edit')==-1) {
    editlink = editbutton.getElementsByTagName('a')[0].href + '&viewsource=1';
    tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    na = document.createElement('a');
    na.href = editlink;
    na.appendChild(document.createTextNode('view source'));
    li = document.createElement('li');
    li.id = 'ca-viewsource';
    li.appendChild(na);
    tabs.insertBefore(li,editbutton);
  }
});

/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

add_viewsrces = function () {
    //alert("entering add_viewsrces");
    var editdivs = getElementsByClassName(document, "div", "editsection");
    if (!editdivs.length) return;
    var firstnode = editdivs[0];
    //alert("before firstnode.getElementsByTagName");
    var thelink = firstnode.getElementsByTagName("a");
    //alert ("jujst past middle of add_viewsrces; thelink");
    var linkwords = thelink[0].childNodes[0];
    linkwords.data = "fixme";
}

amdd_viewsrces = function () {};

$(add_viewsrces);

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;
}

/* Takes the wikipage "page" and includes its raw text as javascript. */
function import_module(page){
    if( document.createElement && document.childNodes ) {
        var url = 
            'http://en.wikipedia.org/w/index.php?title=' + 
            page.replace(/ /g, "_") + 
            '&action=raw&ctype=text/javascript&dontcountme=s';
        var scriptElem = document.createElement('script');
        scriptElem.setAttribute('src',url);
        scriptElem.setAttribute('type','text/javascript');
        document.getElementsByTagName('head')[0].appendChild(scriptElem);
    }
}

import_module('Wikipedia:WikiProject_User_scripts/Scripts/Changes_since_I_last_edited');