User:Mafmafmaf/monobook.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//////////////////////////////////////
//POPUPS// [[User:Lupin/popups.js]]
//////////////////////////////////////

mw.loader.load(
             'https://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js'
             + '&action=raw&ctype=text/javascript&dontcountme=s');

popupQueriedRevertSummary='Revert to revision $1 of $2 by $3';

//////////////////////////////////////
// This will add an [edit] link at the top of all pages except preview pages and the main page
//////////////////////////////////////
// by User:Pile0nades
// Add an [edit] link to pages
$(function () {
// if this is preview page or generated page, stop
  if(document.getElementById("wikiPreview") || window.location.href.indexOf("/wiki/Special:") != -1) return;
  // if this is a revision history, stop
  if(document.getElementById("histlegend‎") || window.location.href.indexOf("/wiki/Special:") != -1) return;
  // if this is a diff page, stop
  if(document.getElementById("difference‎") || window.location.href.indexOf("/wiki/Special:") != -1) return;
  // if this is a watchlist, stop
  if(document.getElementById("watchdetails") || window.location.href.indexOf("/wiki/Special:") != -1) return;
  // if this is the main page, stop
  if(document.getElementById("mainpage") || window.location.href.indexOf("/wiki/Special:") != -1) return;
  // get the page title
  var pageTitle = document.title.split(" - ")[0].replace(" ", "_");
  // create div and set innerHTML to link
  var divContainer = document.createElement("div");
  divContainer.innerHTML = '<div class="editsection" style="float:right;margin-left:5px;margin-right:0px;margin-top:47px;">[<a href="/w/index.php?title='+pageTitle+'&action=edit&section=0" title="'+document.title.split(" - ")[0]+'">edit</a>]</div>';
  // insert divContainer into the DOM below the h1
  if(window.location.href.indexOf("&action=edit") == -1)
    document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
  if(window.location.href.indexOf("&action=edit&section=0") != -1)
    document.getElementById("wpSummary").value = "/* Intro */ ";
});

//////////////////////////////////////
//AUX:Add LI link//
//////////////////////////////////////
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 tab
function addTab(url, name, id, title, key){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    return addlilink(tabs, url, name, id, title, key)
};

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

//////////////////////////////////////
//VIEW SOURCE
//////////////////////////////////////
$(function () {
  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);
  }
});

//////////////////////////////////////
//Revert tools by Lorian
//////////////////////////////////////
function getElementsByClass(searchClass,node,tag) {
  // Function from http://www.dustindiaz.com/getelementsbyclass/
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}
// _GET code from NoGray JS Library http://www.nogray.com/new_site/
var _GET = new Array();
var _uri = location.href;
var _temp_get_arr = _uri.substring(_uri.indexOf('?')+1, _uri.length).split("&");
var _temp_get_arr_1 = new Array();
for(_get_arr_i=0; _get_arr_i<_temp_get_arr.length; _get_arr_i++){
  _temp_get_arr_1 = _temp_get_arr[_get_arr_i].split("=");
  _GET[decodeURI(_temp_get_arr_1[0])] = decodeURI(_temp_get_arr_1[1]);
}
delete _uri; delete _temp_get_arr; delete _temp_get_arr_1;
function getMessage (where, user1, user2) {
  var message = prompt ('What message would you like to leave?', '');
  window.location = 'http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&'+where+'=2&user1='+user1+'&user2='+user2+'&message='+message;
}
$(function (){
  if (location.href.match(/diff=/)) {
    // Get username of submitter
    var user1 = getElementsByClass('diff-otitle',null,'td'); user1 = user1[0].getElementsByTagName('a')[2].innerHTML;
    var user2 = getElementsByClass('diff-ntitle',null,'td'); user2 = user2[0].getElementsByTagName('a')[2].innerHTML;
    document.getElementById('contentSub').innerHTML = '(<a href="http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&revert=1&user1='+user1+'&user2='+user2+'">Revert</a> / <a href="javascript:var message = getMessage(\'revert\', \''+user1+'\', \''+user2+'\');">Message</a>) (<a href="http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&vandalism=1&user1='+user1+'&user2='+user2+'">Vandalism</a> / <a href="javascript:var message = getMessage(\'vandalism\', \''+user1+'\', \''+user2+'\');">Message</a>) (Warn: <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=1">Test</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=2">Blatant</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=3">Nonsense</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=4">Blanking</a>)';
  } else if (location.href.match(/revert=1/)) {
    document.getElementById('wpSummary').value = 'Reverted edits by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']]';
    document.getElementById('editform').submit();
  } else if (location.href.match(/revert=2/)) {
    document.getElementById('wpSummary').value = 'Reverted edits by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']] ('+_GET['message']+')';
    document.getElementById('editform').submit();
  } else if (location.href.match(/vandalism=1/)) {
    document.getElementById('wpSummary').value = 'Reverted vandalism by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']]';
    document.getElementById('editform').submit();
  } else if (location.href.match(/vandalism=2/)) {
    document.getElementById('wpSummary').value = 'Reverted vandalism by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']] ('+_GET['message']+')';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=1/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:test}} ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=2/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:blatantvandal}} ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=3/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:test2}} ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=4/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:test2a}} ~~'+'~~';
    document.getElementById('editform').submit();
  }
});

//Benutzer:ASM/quickedit.js
//////////////////////////////////////
document.write('<script src="'
 * + 'http://de.wikipedia.org/w/index.php?title=Benutzer:ASM/quickedit.js'
 * + '&action=raw&ctype=text/javascript"></script>');