User:Gwern/monobook.js

From Wikipedia, the free encyclopedia

If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// jncsp-start The section below (up to jncsp-end) is maintained by [[Wikipedia:WikiProject_User_scripts/User-script_manager]]
// jncsp-config setupPopups addLastDiff addAdahLinks addUserTabs add_testn_Tabs
 
if (location.href == "http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/User-script_manager") 
   document.write('<script type="text/javascript" src="http://en.wikipedia.org/w' + 
                  '/index.php?title=User:Jitse_Niesen/Client-side_preferences/Main.js&action=raw&ctype=text/javascript"></script>'); 
 
// From [[Wikipedia:WikiProject User_scripts/Scripts/test-enhanced]], revision 87954483
 
function tnaddlilink(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);
 
  var txt = document.createTextNode(name);
  na.appendChild(txt);
 
  var li = document.createElement('li');
  li.appendChild(na);
  return li;
}
 
function testn(number)
{
  var page = prompt("Vandalism to which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + number + "-n|" + page + "}} ~" + "~" + "~" + "~";
  f.wpSummary.value = "Vandalism to [[" + page + "]] - warning " + number;
  f.submit();
}
 
function wA() {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + "welcome-anon-from|Where" + "}} ~" + "~" + "~" + "~";
  f.wpSummary.value = "Welcome to Wikipedia!";
  f.submit();
}
 
function wap() {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + "User:Where/pwelcome" + "}} ~" + "~" + "~" + "~";
  f.wpSummary.value = "Use preview; also, welcome!";
  f.submit();
}
 
 
function es() {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "==Edit summaries==\n{{subst:" + "Edit summary" + "}} ~" + "~" + "~" + "~";
  f.wpSummary.value = "Please use edit summaries";
  f.submit();
}
 
function add_testn_tabs()
{
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
 
  // Only add for pages with "Editing User talk:" somewhere in the title
  if (document.title.indexOf("Editing User talk:") != -1)
    {
      tabs.appendChild(tnaddlilink('javascript:es()', "ES"));
      tabs.appendChild(tnaddlilink('javascript:testn("test1")',"t1"));
      tabs.appendChild(tnaddlilink('javascript:testn("test1a")',"t1a"));
      tabs.appendChild(tnaddlilink('javascript:testn("test2")',"t2"));
      tabs.appendChild(tnaddlilink('javascript:testn("test2a")',"t2a"));
      tabs.appendChild(tnaddlilink('javascript:testn("test3")',"t3"));
      tabs.appendChild(tnaddlilink('javascript:testn("test4")',"t4"));
      tabs.appendChild(tnaddlilink('javascript:testn("bv")',"bv"));
      tabs.appendChild(tnaddlilink('javascript:testn("obscene")',"o"));
      tabs.appendChild(tnaddlilink('javascript:testn("joke")',"j"));
      tabs.appendChild(tnaddlilink('javascript:testn("welcomenpov")',"w-N"));
      tabs.appendChild(tnaddlilink('javascript:wA()',"w-A"));
      tabs.appendChild(tnaddlilink('javascript:wap()',"w-A-p"));
}}
addOnloadHook(add_testn_tabs);
 
// From [[Wikipedia:WikiProject User_scripts/Scripts/Get_Page_Name]], revision 73544616
 
/*Returns the name of the page. For example, if you were browsing the "[[foo]]" WP page, getPname() would return "foo".*/
function getPname() {
  return wgPageName.replace(/_/g, ' ');
}
 
 
// From [[Wikipedia:WikiProject User_scripts/Scripts/All_diffs_above_here]], revision 87965058
 
 
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() == 'Special: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);
 
 
 
 
// From [[Wikipedia:WikiProject User_scripts/Scripts/Add_LI_link]], revision 73544143
 
 
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;
}
 
 
 
// From [[Wikipedia:WikiProject User_scripts/Scripts/Add_tab]], revision 73544604
 
function addTab(url, name, id, title, key){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    return addlilink(tabs, url, name, id, title, key)
};
 
 
// From [[Wikipedia:WikiProject User_scripts/Scripts/User_tabs]], revision 73795341
 
 
//Please leave the following line
//[[user:Where/usertabs]]
 
addOnloadHook(function() {
   if (document.title.search("/") != -1 || document.title.search("- History -") != -1) { //no subpages or history
      return;
   }
   if (document.title.indexOf("User:") == 0 || document.title.indexOf("User talk:") == 0) {
      username_a = document.URL.match(/:.*:(.*)/);
      username=username_a[1];
      addTab("http://en.wikipedia.org/wiki/Special:Contributions/" + username, "contrib", "ca-contrib", "contribs", "");
      addTab("http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=move&user=" + username, "page moves", "ca-pagemoves", "page moves", "");
      addTab("http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=block&user=" + username, "block log", "ca-blog", "blog", "");
      addTab("http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=" + username, "edit count", "ca-kate", "kate", "");
   }
});
 
 
 
// From [[Wikipedia:WikiProject User_scripts/Scripts/Show_last_diff]], revision 67477415
 
//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 ? 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";
});
 
// jncsp-end
 
importScript('Wikipedia:WikiProject User scripts/Scripts/addLink'); importScript('Wikipedia:WikiProject User scripts/Scripts/Get Page Name'); importScript('Wikipedia:WikiProject User scripts/Scripts/Formatter'); importScript('User:Gwern/bits.js'); popupDelay=1; popupHideDelay=.2; popupStructure='fancy2'; popupSubpopups=false; popupFixRedirs=true; popupRedirAutoClick='wpSave'; popupRedlinkRemoval=true; popupFixDabs=true; imagePopupsForImages=false; importScript('User:AzaToth/morebits.js'); importScript('User:Haza-w/cactions.js'); var ctOriginalTabs = 1; var ctEditIntro = 1; var getReq; if(wgNamespaceNumber==0) addOnloadHook(getTalkPage)
function getTalkPage() { var tlink = document.getElementById('ca-talk'); if(tlink.className == 'new') return; var url = tlink.getElementsByTagName('a')[0].href; url += (url.indexOf('?')==-1) ? '?action=render' : '&action=render' ; var tp = document.createElement('div'); tp.style.border = '1px solid blue'; tp.style.margin = '.5em 0'; tp.style.padding = '.35em'; tp.style.height = '128em'; tp.style.overflow = 'auto'; tp.id = 'ajax-talkpage'; tp.appendChild(document.createTextNode('fetching talk page...')); document.getElementById('bodyContent').appendChild(tp); getXML(url,getTalkPageStateChange);}
function getTalkPageStateChange() { switch (getReq.readyState) { case 4:
if (getReq.status == 200) { var tp = document.getElementById('ajax-talkpage'); clearNode(tp); var txt = getReq.responseText; tp.innerHTML = txt;} else { tp.appendChild(document.createTextNode('** Problem ** ' + getReq.statusText))
}
break;}
}
function clearNode(obj) { while(obj.firstChild) obj.removeChild(obj.firstChild);}
function getText(obj) { if (obj.nodeType == 3) return obj.nodeValue; var txt = new Array(); var i=0; while(obj.childNodes[i]) { txt[txt.length] = getText(obj.childNodes[i]); i++;}
return txt.join('');}
function getXML(url,func) { if (window.XMLHttpRequest) { getReq = new XMLHttpRequest();} else if (window.ActiveXObject) { getReq = new ActiveXObject('Microsoft.XMLHTTP');}
if (getReq) { getReq.onreadystatechange = func; try { getReq.open('GET', url, true); getReq.send('');} catch (e) { alert(e);}
} else { alert('XMLHTTPRequest not supported');}
}
importScript('User:Tra/userwatchlist.js'); importScript('User:Alex Smotrov/histcomb.js');
 
// see http://www.nabble.com/Newbie-friendliness%2C-markup-hell%2C-and-editing-structure-to15969885.html
// importScript('User:Magnus Manske/less edit clutter.js');