Jump to content

User:Extremecircuitz/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Extremecircuitz (talk | contribs) at 02:04, 8 October 2007. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Twinkle
importScript('User:AzaToth/twinkle.js');
importScript('User:TheJosh/Scripts/NewPagePatrol.js');
// Etcetera
importScript("Wikipedia:WikiProject_User_scripts/Scripts/Easy_db");

//<pre><nowiki>
//IMPORTS
importScript('User:Voice_of_All/Addtabs/monobook.js');
importScript('User:Voice_of_All/UTCclock.js');
importScript('User:Voice_of_All/Revert.js');
importScript('User:Voice_of_All/History/monobook.js');
 
importScript('User:Lightdarkness/aiv.js');
//</nowiki></pre>
 
//<pre><nowiki>
// [[User:Lupin/popupsdev.js]] - please include this line 
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popupsdev.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
popupStructure='shortmenus';
popupSubpopups=false;
// [[User:Lupin/recent2.js]] - please include this line
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/recent2.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//</nowiki></pre>
 
//<pre><nowiki>
// ============= test-n.js ==============
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 IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "test" + number + "}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " test" + number;
}
 
function warningn()
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "bv" + "}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " bv";
}
 
function testbl(number)
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "Blank" + number + "}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " Blank" + number;
}
 
function spam()
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "spam}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " spam";
}
 
function spamn(number)
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "spam" + number + "}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " spam" + number;
}

function welcome()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="==Welcome==\n{{welcome}} ~~~~ ([[User:Mike.lifeguard|This]] talk page)";
  f.wpSummary.value = "Welcome new user";
}
 
//LAST DIFF TAB
function lastdiff() 
    {
    if (document.title.indexOf("Editing ") != -1)
    {return;}
    z=document.getElementById("content").childNodes;
    for (var n=0;n<z.length;n++) { 
      if (z[n].className=="firstHeading") 
      {
  var pname = URLEncoding(z[n].innerHTML);
      }
    }
    var l=addTab("http://en.wikipedia.org/w/index.php?title=" + pname + "&diff=cur&oldid=prev", 'last', '');
    l.lastChild.title="Show most recent diff";
}
function getParamValue(paramName) {
  var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
  var h=document.location;
  var m;
  if (m=cmdRe.exec(h)) {
    try { 
      return decodeURI(m[1]);
    } catch (someError) {}
  }
  return null;
};
 
function substitute(data,cmdBody) {
  // alert('sub\nfrom: '+cmdBody.from+'\nto: '+cmdBody.to+'\nflags: '+cmdBody.flags);
  var fromRe=RegExp(cmdBody.from, cmdBody.flags);
  return data.replace(fromRe, cmdBody.to);
};
 
function execCmds(data, cmdList) {
  for (var i=0; i<cmdList.length; ++i) {
    data=cmdList[i].action(data, cmdList[i]);
  }
  return data;
}
 
function parseCmd(str) {
  // returns a list of commands
  if (!str.length) return [];
  var p=false;
  switch (str.charAt(0)) {
  case 's':
    p=parseSubstitute(str);
    break;
  case 'j':
    p=parseJavascript(str);
    break;
  default:
    return false;
  }
  if (p) return [p].concat(parseCmd(p.remainder));
  return false;
};
 
function unEscape(str, sep) {
  return str.split('\\\\').join('\\')
        .split('\\'+sep).join(sep)
        .split('\\n').join('\n');
};
 
 
function runJavascript(data, argWrapper) {
  // flags aren't used (yet)
 
  // from the user's viewpoint,
  // data is a special variable may appear inside code
  // and gets assigned the text in the edit box
 
  // alert('eval-ing '+argWrapper.code);
 
  return eval(argWrapper.code);
};
 
function parseJavascript(str) {
  // takes a string like j/code/;othercmds and parses it
 
  var tmp,code,flags;
 
  if (str.length<3) return false;
  var sep=str.charAt(1);
  str=str.substring(2);
 
  tmp=skipOver(str,sep);
  if (tmp) { code=tmp.segment.split('\n').join('\\n'); str=tmp.remainder; }
  else return false;
 
  flags='';
  if (str.length) {
    tmp=skipOver(str,';') || skipToEnd(str, ';');
    if (tmp) {flags=tmp.segment; str=tmp.remainder; }
  }
 
  return { action: runJavascript, code: code, flags: flags, remainder: str };
};
 
function parseSubstitute(str) {
  // takes a string like s/a/b/flags;othercmds and parses it
 
  var from,to,flags,tmp;
 
  if (str.length<4) return false;
  var sep=str.charAt(1);
  str=str.substring(2);
 
  tmp=skipOver(str,sep);
  if (tmp) { from=tmp.segment; str=tmp.remainder; } 
  else return false;
 
  tmp=skipOver(str,sep);
  if (tmp) { to=tmp.segment; str=tmp.remainder; } 
  else return false;
 
  flags='';
  if (str.length) {
    tmp=skipOver(str,';') || skipToEnd(str, ';');
    if (tmp) {flags=tmp.segment; str=tmp.remainder; }
  }
 
  return {action: substitute, from: from, to: to, flags: flags, remainder: str};
 
};
 
function skipOver(str,sep) {
  var endSegment=findNext(str,sep);
  if (endSegment<0) return false;
  var segment=unEscape(str.substring(0,endSegment), sep);
  return {segment: segment, remainder: str.substring(endSegment+1)};
}
 
function skipToEnd(str,sep) {
  return {segment: str, remainder: ''};
}
 
function findNext(str, ch) {
  for (var i=0; i<str.length; ++i) {
    if (str.charAt(i)=='\\') i+=2;
    if (str.charAt(i)==ch) return i;
  }
  return -1;
};
 
function runOnLoad(f) {
  if (window.addEventListener) {
    window.addEventListener("load",f,false);
  }
  else if (window.attachEvent) {
    window.attachEvent("onload",f);
  }
  else {
    window._old_popup_autoedit_onload = window.onload;
    window.onload = function() {
      window._old_popup_autoedit_onload();
      f();
    }
  }
};
 
window.autoEdit=function() {
  if (window.autoEdit.alreadyRan) return false;
  window.autoEdit.alreadyRan=true;
  var cmdString=getParamValue('autoedit');
  if (cmdString) {
    try { 
      var editbox=document.editform.wpTextbox1;
    } catch (dang) { return; }
    var cmdList=parseCmd(cmdString);
    var input=editbox.value;
    var output=execCmds(input, cmdList);
    editbox.value=output;
  }
 
  var summary=getParamValue('autosummary');
  if (summary) document.editform.wpSummary.value=summary;
 
  var minor=getParamValue('autominor');
  if (minor) {
    switch (minor) {
    case '1':
    case 'yes':
    case 'true':
      document.editform.wpMinoredit.checked=true;
      break;
    case '0':
    case 'no':
    case 'false':
      document.editform.wpMinoredit.checked=false;
    }
  }
 
  var btn=getParamValue('autoclick');
  if (btn) {
    if (document.editform && document.editform[btn]) {
      var headings=document.getElementsByTagName('h1');
      if (headings) {
        var div=document.createElement('div');
        var button=document.editform[btn];
        div.innerHTML='<font size=+1><b>The "' + button.value + 
          '" button has been automatically clicked.' + 
          ' Please wait for the next page to load.</b></font>';
        document.title='('+document.title+')';
        headings[0].parentNode.insertBefore(div, headings[0]);
        button.click();
      }
    } else {
      alert('autoedit.js\n\nautoclick: could not find button "'+ btn +'".');
    }  
  }
}; 
runOnLoad(autoedit);
var a = document.getElementsByTagName('a');
for(i=0; i<a.length; i++) {
  if(a[i].href.match('/w/index.php?title=User_talk:'+$1+'&action=edit') && a[i].attribute.match(class, 'new')){
    var welcome = "{{welcome}} ~~~~ ([[User:Mike.lifeguard|This]] talk page)";
    var welcomelink = document.createElement('a');
    var welcometxt  = document.createTextNode('wel');
    welcomelink.setAttribute('href', '/w/index.php?title=User_talk:'+$regExp1+'&action=edit&autoedit='+welcome+'&autoclick=wpSave&autosummary=Welcome%20new%20user');
    welcomelink.appendChild(welcometxt);
    welcomelink.appendNode(document.createTextNode('|'));
    a[i].appendNode(document.createTextNode('|').appendNode(welcomelink));
  }
}
//<pre><nowiki>
//Please leave the following line
//[[user:Where/easy db]]
//Start db script
//modded by VoA
addOnloadHook(function()
{
  //check if called from deletion request
  if (document.title.indexOf("Editing ") != -1 && wgNamespaceNumber !=-1)
  {
    if (document.URL.lastIndexOf("&fakeaction=huff") == -1)
      return;
    if (document.URL.lastIndexOf("&reason=off") != -1)
    {
      var type = prompt("Enter criteria for speedy deletion, e.g. A1, G3");
      var f = document.editform, t = f.wpTextbox1;
      t.value = "{{db-" + type.toLowerCase() + "}}\n" + t.value;
      f.wpSummary.value = "JS: Requesting speedy deletion ([[WP:CSD#" + type + "|CSD " + type + "]])";
      f.wpSave.click();
      return;
    }
    else if (document.URL.lastIndexOf("&reason=on") != -1)
    {
      var type = prompt("Enter reason for speedy deletion");
      var f = document.editform, t = f.wpTextbox1;
      t.value = "{{db|" + type + "}}\n" + t.value;
      f.wpSummary.value = "JS: Requesting speedy deletion";
      f.wpSave.click();
      return;
    }
  }
  if (window.location.href.search(/Special:|&action=/) != -1)
    return;
 
  addTab("javascript:easyDb(0)", "Tag SpeedyDelete (csd)", "ca-db0", "Request speedy deletion according to WP:CSD", "");
  addTab("javascript:easyDb(1)", "Tag SpeedyDelete (reason)", "ca-db0", "Request speedy deletion with reason", "");
});
 
function easyDb(n)
{
  if (n == 0)
  {
    //edit page
    var title = document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
    location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=huff&reason=off");
  }  
 
  if (n == 1)
  {
    //edit page
    var title = document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
    location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=huff&reason=on");
  }
}
//</nowiki></pre>

// 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
addOnloadHook(function () {
 // if this is preview page or generated page, stop
 if(
 document.getElementById("wikiPreview") ||
 document.getElementById("histlegend‎") ||
 document.getElementById("difference‎") ||
 document.getElementById("watchdetails") ||
 document.getElementById("ca-viewsource") ||
 window.location.href.indexOf("/wiki/Special:") != -1
 ) {
 if(window.location.href.indexOf("&action=edit&section=0") != -1) {
 document.getElementById("wpSummary").value = "/* Top section */ ";
 }
 return;
 };

 // get the page title
 var pageTitle = wgPageName;

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="editsection">[<a href="/w/index.php?title='+pageTitle+'&action=edit&section=0" title="Edit section: '+pageTitle+'"></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]);
 }

});

// Welcome msg script
// returns <li><a href="url">name</a></li>
function addlilink(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;
}
 
// appends msg to the currently-editted page, sets the summary to summ,
// and marks or unmarks the Watch this page checkbox according to watch.
function edit_summary_watch(msg, summ, watch)
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += msg;
  f.wpSummary.value = summ;
  f.wpWatchthis.checked = watch;
}