Jump to content

User:Gracenotes/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.
//if (wgNamespaceNumber == 6)
//  importScript('User:Gracenotes/wpPicmark.js');
//importScript('User:Gracenotes/fixStuff.js');
//importScript('User:Gracenotes/changesSince.js');
importScript('User:Gracenotes/amelvand.js');
importScript('User:Gracenotes/rollback.js');
importScript('User:Gracenotes/console.js');

//add (cur) link on contribution pages
if (wgPageName == 'Special:Contributions' && (((lim = document.location.href.match(/[&?]limit=([^&]*)/)) && parseInt(lim[1]) < 250) || !lim)) {
    addOnloadHook(function() {
        var contribs = document.getElementById('bodyContent').getElementsByTagName('li');
        var mainNode;
        var aNode;
        var links;
        for (var i = 0, leng = contribs.length; i < leng; i++) {
            links = contribs[i].getElementsByTagName('a');
            mainNode = document.createElement('span');
               mainNode.appendChild(document.createTextNode('('));
            aNode = document.createElement('a');
            aNode.href = links[1].href.replace('prev', 'cur');
            aNode.appendChild(document.createTextNode('cur'));
            mainNode.appendChild(aNode);
            mainNode.appendChild(document.createTextNode(') '));
            contribs[i].insertBefore(mainNode, links[2]);
        }
    });
}

//utility function: box() gets edit textarea value, box(text) sets it
function box(text) {
    if (text) {
        document.getElementById("wpTextbox1").value = text;
    } else {
        return document.getElementById("wpTextbox1").value;
    }
}

//adds "contibs" tab to user and user talk pages
if (wgNamespaceNumber == 2 || wgNamespaceNumber == 3) {
    var uname = wgPageName.match(/[^:]*:([^\/]*)/);
    if (uname.length > 1)
        addOnloadHook(function() {
            mw.util.addPortletLink("p-cactions",
                           "http://en.wiki.x.io/wiki/Special:Contributions/" + uname[1],                        
                           "contribs",
                           "ca-contribs",
                           "Contributions",
                           undefined,
                           document.getElementById("ca-move") || document.getElementById("ca-watch"));
        });
}

function replaceWithPoem(textbox) {
  var textbox = document.getElementById('wpTextbox1');
  var substr = textbox.value.substring(textbox.selectionStart, textbox.selectionEnd);
  if (substr.length == 0) return false;
  var substr2 = '<poem style="margin-left: 2em">\n' + substr.replace(/^:/gm, '').replace(/\<br.*?\>/g, '') + '\n</poem>';
  document.getElementById('wpTextbox1').value = textbox.value.replace(substr, substr2);
}

$(function() {
  var wform = document.forms["editform"];
  if (!wform) return false;
  mw.util.addPortletLink("p-tb", "javascript:replaceWithPoem()", "Replace with poem", "t-summary", "Replace selected text with poem");
  if (wgNamespaceNumber == 0)
    document.getElementById("wpMinoredit").checked = true;
  document.getElementById("wpSummary").setAttribute("maxlength", "250");
  mw.util.addPortletLink("p-tb", "javascript:prettifySummary()", "Unicodify summary", "t-summary", "Converts character entity references into the character, among other unpredictable behavior");
  document.getElementById("wpSummary").spellcheck = true;
});

$(function() {
    mw.util.addPortletLink("p-tb", "javascript:displayWgVars()", "Display page vars", "t-wgvars");
});

function displayWgVars() {
    var wgVars = document.getElementsByTagName('script')[0].firstChild.cloneNode(true);
    var wgVarsPre = document.createElement('pre');
    wgVarsPre.appendChild(wgVars);
    document.getElementById('siteSub').appendChild(wgVarsPre);
}

function prettifySummary() {
  //hack to unicodify summary
  var tempnode=document.createElement('span');
  var sumbox = document.getElementById('wpSummary');
  tempnode.innerHTML = sumbox.value;
  sumbox.value = tempnode.innerHTML;
}

if (document.location.href.indexOf("speedydiff") != -1)
$(function() {
    var k = getElementsByClassName(document.getElementById("wikiDiff"), "td", "diff-ntitle")[0];
    k.style.backgroundColor = "blue";
    k.onclick = function() {
        document.forms['editform'].submit();
    }
});

function linkChange(func) {
    var alinks = document.getElementsByTagName("a");
    var alink;
    for (var i = 0, leng = alinks.length; i < leng; i++)
        func(alinks[i]);
}
function linkAppend(str) {
    linkChange(function(link) {
        link.href += str;
    });
}

/* external
$(function() {
    var alinks = document.getElementsByTagName("a");
    var tablink;
    for (var i = 0, leng = alinks.length; i < leng; i++) {
        tablink = alinks[i];
        if (/\bexternal\b/.test(tablink.className) && tablink.href.indexOf("http://en.wiki.x.io") != 0)
            tablink.target = "_tab";
    }
});
*/


//following script based off of [[User:Ais523/votesymbols.js]]; mostly string functions modified
function lowerNoPunct(s)
{
  return s.toLowerCase().replace(/\.|,|:|;|\+/g, '');
} 
$(function() {
  if(wgNamespaceNumber==0 || wgPageName == "Wikipedia:Requests_for_adminship") return; //RFA is often rather long; may also add wgPageName.indexOf("Wikipedia:Articles_for_deletion/Log/") == 0
  var vt=
 ["http://up.wiki.x.io/wikipedia/commons/thumb/9/94/Symbol_support_vote.svg/15px-Symbol_support_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/d/d0/Symbol_keep_vote.svg/15px-Symbol_keep_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/7/7f/Symbol_oppose_vote.svg/15px-Symbol_oppose_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/8/89/Symbol_delete_vote.svg/15px-Symbol_delete_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/8/89/Symbol_neutral_vote.svg/15px-Symbol_neutral_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/b/b0/Symbol_merge_vote.svg/15px-Symbol_merge_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/5/50/Symbol_move_vote.svg/15px-Symbol_move_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/0/0c/Symbol_redirect_vote.svg/15px-Symbol_redirect_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/b/ba/Symbol_opinion_vote.svg/15px-Symbol_opinion_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/e/e0/Symbol_comment_vote.svg/15px-Symbol_comment_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/f/f6/Symbol_unsupport_vote.svg/15px-Symbol_unsupport_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/e/e0/Symbol_question.svg/15px-Symbol_question.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/a/aa/Symbol_divide_vote.svg/15px-Symbol_divide_vote.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/5/54/Symbol_wait.svg/15px-Symbol_wait.svg.png",
  "http://up.wiki.x.io/wikipedia/commons/thumb/b/bc/Face-grin.svg/15px-Face-grin.svg.png"];
  var la=[];
  la['support']=0; la['endorse']=0;
  la['keep']=1;
  la['oppose']=2; la['overturn']=2; la['object']=2;
  la['delete']=3;
  la['neutral']=4;
  la['merge']=5; la['upmerge']=5;
  la['move']=6; la['rename']=6; la['userfy']=6; la['transwiki']=6;
  la['redirect']=7;
  la['opinion']=8; la['relist']=8; la['subst']=8; la['salt']=8; la['change']=8;
  // Note that icon 8 on the list is often used for debate-specific !votes
  la['comment']=9; la['update']=9; la['note']=9;
  la['delist']=10;
  la['question']=11;
  la['split']=12;
  la['wait']=13;
  la['bjaodn']=14;
 
  var btc=document.body.getElementsByTagName("b");
  i=btc.length;
  while(i--)
  {
    var j,k;
    j=btc[i].innerHTML.replace(/<|>|\//g, " ").split(" ");
    k=0;
    var x="";
    while(k<j.length)
    {
      if(lowerNoPunct(j[k])=="don't"||lowerNoPunct(j[k])=='not'
       ||lowerNoPunct(j[k])=='no'||lowerNoPunct(j[k])=='without') break;
      var l=la[lowerNoPunct(j[k])];
      if(l!=undefined)
      {
        x+="<img src='"+vt[l]+"' alt='*' /> ";
      }
      k++;
    }
    if(x!="") btc[i].innerHTML=x+btc[i].innerHTML;
  }
});