User:J. Finkelstein/monobook.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

//<pre>
//*************Navigation Pop-ups start here
// [[User:Lupin/popups.js]]

document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

popupFixDabs=true;
popupRedlinkRemoval=true;

// initialize the array - only do this once
extraPopupFilters=[];

// define the function
function popupFilterHtmlTable (wikiText) {
  if (/<table/i.test(wikiText)) return 'HTML TABLE';
  else return '';
};

function popupFilterNumberedLists (wikiText) {
  if (/1\./i.test(wikiText)) return 'NUMBERED LIST';
  else return '';
};

// add the function to the array (you can repeat this for lots of functions)
extraPopupFilters.push(popupFilterHtmlTable);
extraPopupFilters.push(popupFilterNumberedLists);

//*************Navigation Pop-ups end here

//*************Interiot's Tool 2 starts here

//Interiot's javascript edit counter TOOL2
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>'); }

  //  Add a "Interiot" link to your monobook "personal menu" list at the very
  //  top of the page.
  //
  //  Indicate where you would like "Interiot" to appear:
  //    pt-userpage, pt-mytalk, pt-preferences,
  //    pt-watchlist, pt-mycontris, pt-logout
  //

gsInteriotInsertBefore = 'pt-mycontris'; // leave blank to append after "logout"

function InteriotLink()
{
  var user = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  user = user.substring(user.indexOf('title=') + 6, user.lastIndexOf('&action=edit'));
  user = user.substring(user.indexOf(':') + 1);

  var li = document.createElement( 'li' );
    li.id = 'pt-interiot';

    var a = document.createElement( 'a' );
      a.appendChild( document.createTextNode( 'user stats' ) ); // eh, the css makes the text lowercase
// KATE"S TOOL LINK 
// a.href = 'http://tools.wikimedia.de/~kate/cgi-bin/count_edits?dbname=enwiki&user=' + user;
//INTERIOT'S TOOL
//      a.href = 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki&user=' + user;
//INTERIOT'S TOOL2
   a.href = 'http://en.wikipedia.org/wiki/User:Interiot/Tool2/code.js?username=' + user;

    li.appendChild( a );

  if ( ! gsInteriotInsertBefore ) // append to end (right) of list
  {  document.getElementById( 'pt-logout' ).parentNode.appendChild( li );
  }
  else
  {  var before = document.getElementById( gsInteriotInsertBefore );
      before.appendChild( li, before );
  }
}
   if ( window.addEventListener ) window.addEventListener( 'load', InteriotLink, false );
else if ( window.attachEvent ) window.attachEvent   ( 'onload', InteriotLink );
//Interiot's Tool ENDS HERE**************************************

//*************Picture pop-ups start here
// [[User:Zocky/PicturePopups.js]] - please include this line 
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Zocky/PicturePopups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//*************Picture pop-ups end here

//*************Edit top starts here
//If you are not editing a page, a tab will appear allowing you to edit the 0th section of a page (the top area usually used as an introduction.

function addEditSection0() {
  ta['ca-edit-0'] = ['', 'Edit the zeroth section of this page'];
  if (!document.getElementById) return;
  x = document.getElementById('ca-edit');
  if(!x) return;
  y = document.createElement('LI');
  y.id = 'ca-edit-0';
  if (x.className == 'selected') {
    if (/&action=edit&section=0$/.test(window.location.href)) {
      x.className = 'istalk';
      y.className = 'selected';
    } else {
      x.className = 'selected istalk';
    }
  } else if (x.className == 'selected istalk') {
    if (/&action=edit&section=0$/.test(window.location.href)) {
      x.className = 'istalk';
      y.className = 'selected istalk';
    } else {
      y.className = 'istalk';
    }
  } else {
    y.className = x.className;
    x.className = 'istalk';
  }
  z = document.createElement('A');
  if (x.children) {
    z.href = x.children[0].href + '&section=0';
    z.appendChild(document.createTextNode('edit top'));
    y.appendChild(z);
    document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling);
  } else {
    z.href = x.childNodes[0].href + '&section=0';
    z.appendChild(document.createTextNode('edit top'));
    y.appendChild(z);
    document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling);
  }
}

if (document.title.indexOf("Editing ") == -1) {
  addOnloadHook(addEditSection0);
}

// 
//*************Edit top ends here

//*************Since tab starts here

//From http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510
//function addSinceTab() {
//    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
//   if (window.location.href.indexOf("&action=history&gotosince=true")!=-1) {
//       do_since_I_last_edited()
//    }
//    else if (!/wiki\/Special:|w\/index.php?title=Special:/.test(window.location.href)) {
//       var thetitle=document.title.slice(0, String(document.title).indexOf(" - "));
//       var l=addlilink(tabs, "/w/index.php?title="+thetitle+"&action=history&gotosince=true", 'since mine', '');
//       l.lastChild.title="Changes since I last edited";
//    }
//}
//function do_since_I_last_edited() {
//        var csub=document.getElementById("contentSub");
//        var msg=document.createElement("p");
//        msg.appendChild(document.createTextNode
//                        ("Parsing history... please wait..."));
//        msg.className="error";
//        csub.insertBefore(msg, csub.firstChild)
//
//        var username=document.getElementById("pt-userpage").textContent;
//        var hists=document.getElementById("pagehistory").childNodes;
//        for (n=0;n<hists.length;n++) {
//            if (hists[n].getElementsByTagName("span")[0].textContent==username) {
//                document.location=hists[n].childNodes[1].href; 
//                return;
//            }
//        }
//
//        msg.replaceChild(document.createTextNode
//                         ("You have not edited this page! (recently)"),
//                         msg.firstChild);
//}
//
//addOnloadHook(addSinceTab);
//
//*************Since tab ends here

//*************Last change tab starts here

//From http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510

// addLastDiff
addOnloadHook(function () {
    z=document.getElementById("content").childNodes;
    for (var n=0;n<z.length;n++) { 
      if (z[n].className=="firstHeading") {
        var pname=z[n].textContent;
      }
    }
    var l=addTab("http://en.wikipedia.org/w/index.php?title=" + pname + "&diff=cur&oldid=prev", 'last', '');
    l.lastChild.title="Show most recent diff";
});

//*************Last change tab ends here

//*************Add LI link starts here
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;
}

//*************add LI link ends here

//*************add tab starts here
function addTab(url, name, id, title, key){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    return addlilink(tabs, url, name, id, title, key);
}
//*************add tab ends here

//*************pagename function starts here
function getPname() {
  z=document.getElementById("content").childNodes;
  for (var n=0;n<z.length;n++) { 
    if (z[n].className=="firstHeading") return z[n].textContent;
  };
}

/* This code may be problematic when it comes to titles with ampersands, etc, which are stored as ''& amp ;'' in HTML (without the spaces).
  A solution that solves this is the following:
    return document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
*/

//*************pagename function ends here

//*************all diffs above here starts here

function openAdahLinks(kk)
{
  var as = document.getElementsByTagName('a');
  var k = 0;
  for (n=0; n<as.length; n++) {
    if (as[n].innerHTML == 'diff') {
      if (k <= kk) {
        window.open(as[n].href, '_blank');
      }
      k++;
    }
  }
}

function addAdahLinks() 
{
  if (getPname() == 'My watchlist') {
    var as = document.getElementsByTagName('a');
    var k = 0;
    for (n=0; n<as.length; n++) {
      if (as[n].innerHTML == 'diff') {
        var tn = document.createTextNode(') (');
        var link = document.createElement('a');
        link.href = 'javascript:openAdahLinks(' + (k++) + ')';
        link.appendChild(document.createTextNode('adah'), null);
        as[n].parentNode.insertBefore(tn , as[n].nextSibling.nextSibling);
        as[n].parentNode.insertBefore(link , as[n].nextSibling.nextSibling);
      }
    }
  }
}

addOnloadHook(addAdahLinks);

//*************all diffs above here ends here

//*************remove from watch starts here

addOnloadHook(function () {
    var query_prefix = "title=Special:Watchlist&action=submit&remove=1&id[]=";
    var query_prefix = "action=unwatch&title=";

    if (window.location.href.indexOf("Special:Watchlist") == -1) return;
    var links = document.getElementById('content').getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {
        if (links[i].href.substring(links[i].href.length-15) != '&action=history')
            continue;
        var unwatch = document.createElement('a');
        unwatch.href = "/w/index.php?" + query_prefix + encodeURIComponent(links[i].title);
        unwatch.title = "Unwatch "+links[i].title;
        unwatch.appendChild(document.createTextNode("unwatch"));
        links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);
        // kluge to handle case where "diff" is unlinked:
        var delim = links[i].previousSibling;
        delim = (delim.nodeType == 3 ? delim.nodeValue : "");
        links[i].parentNode.insertBefore(document.createTextNode(delim.replace(/^.*diff/, "")), unwatch);
    }
});

//*************remove from watch ends here

//</pre>