Jump to content

User:Fry/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.
importScript('User:AzaToth/twinklespeedy.js');
importScript('User:Ioeth/friendlytag.js');
importScript('User:AzaToth/morebits.js');

 addOnloadHook(initNewusers);
 
 function initNewusers(){
  var list = document.getElementsByTagName("A");
  var ignore = [ ];
  for(i = 0; i < list.length; i++){
   link = list[i];
   if(link == null){
     continue;
   }
   if(ignore.indexOf(link.title) != -1){
    continue;
   }
   if(link.parentNode.innerHTML.indexOf("created new account") != -1){
    continue;
   }
   if(link.className == "new"){
    if(link.title.indexOf("User talk:") != -1){
     link.innerHTML = "<i>Welcome</i>";
     link.style.color = "green";
     ignore[ignore.length] = link.title;
     var orighref = link.href;
     var uname = link.title.replace("User talk:", "");
     var template = "User:Fry/welcome|border=black|heading=true|headtext=Hello from Fry";
     var page = 1;
     if(wgPageName.indexOf("Newpages") != -1){
      page = 3;
     }
     if(page == 2){
      template = "User:Fry/welcome|heading=true|headtext=Hello from Fry";
     }
     var unameProcessed = uname.replace(".", "").replace(".", "").replace(".", "");
     if(unameProcessed.length == (uname.length-3)){
      template = "Welcome-anon";
     }
     link.href = link.href + "&tag=subst:" + template;
     //link.parentNode.innerHTML = link.parentNode.innerHTML.replace(link.href, link.href+"&tag=subst:" + template);
     link.className = "";
     link.parentNode.innerHTML = link.parentNode.innerHTML.replace(" | <a", " | <a href=\"" + orighref + "\" class=\"new\" title=\"" + link.title + "\">Talk</a> | <a");
    }
   }
  }
 }


//Import
importScript("User:TheFearow/qstring.js");
//Start stub script

$(function()
{
  //check if called from stub request
  if (wgAction == 'edit')
  {
    if (QueryString.exists("tag"))
    {
      document.getElementById("contentSub").innerHTML = "<h" + "2>The Save button has automatically been clicked, please wait while you are redirected.</h" + "2>";
      welcome();
    }
  }
  if(QueryString.exists("redir")){
      var redir = QueryString.get("redir");
      location.href = "http://en.wikipedia.org/wiki/" + redir;
  }
  if (wgCanonicalNamespace == "Special"){
    return;
  }
});
 
function easyTag()
{
  var title = encodeURIComponent(mw.config.get('wgPageName'));
  var tag = window.prompt("Enter template name");
  if(tag == null){
     return;
  }
  location.assign("/w/index.php?action=edit&tag=" + tag + "&title=" + title);
}
function easyTagBottom()
{
  var title = encodeURIComponent(mw.config.get('wgPageName'));
  var tag = window.prompt("Enter template name");
  if(tag == null){
     return;
  }
  location.assign("/w/index.php?action=edit&tag=" + tag + "&loc=bottom&title=" + title);
}


//End tag script
//


// <nowiki>

// Edit top
if (wgAction == 'view' && wgNamespaceNumber >=0)
$(function(){
 var h2s = document.getElementsByTagName('H2');
 var h2 = h2s[0];
 if (!h2) return;
 if (h2.parentNode.id == 'toctitle') h2 = h2s[1];
 if (!h2) return;
 var span = h2.firstChild;
 if (!span || span.className != 'editsection') return;
 var zero = span.cloneNode(true);
 var parent = document.getElementById('bodyContent');
 parent.insertBefore(zero, parent.firstChild);
 var a = zero.getElementsByTagName('A')[0];
 a.title = a.title.replace(/:.*$/,': 0');
 a.setAttribute('href', a.href.replace(/&section=1/,'&section=0'));
})








// addPurge
$(function () {
    var hist; var url;
    if (!(hist = document.getElementById('ca-history') )) return;
    if (!(url = hist.getElementsByTagName('a')[0] )) return;
    if (!(url = url.href )) return;
    mw.util.addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
                   'purge', 'ca-purge', 'Purge server cache for this page', '0');
});

// 




// [[User:Zocky/PicturePopups.js]]
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Zocky/PicturePopups.js' 
             + '&action=raw&ctype=text/javascript');

$(function () {
 var caAdd = document.getElementById('ca-addsection');
 if (caAdd) caAdd.firstChild.innerHTML = '+';
})

// Stub tag tab. By [[User:ais523]], on a request by [[User:thesublime514]].
// ([[User:ais523/stubtagtab.js]])
// <source lang="javascript">
$(function(){
  if(wgNamespaceNumber==0&&wgAction=="view")
  {
    if(document.getElementById("ca-edit"))
      mw.util.addPortletLink('p-cactions', 'javascript:stubtagtab()', 'stub', 'ca-stubtag',
                                   'Add a stub tag to this page', '');
  }
  if(location.href.indexOf("&autoaddstubtag=")!=-1&&document.getElementById('wpTextbox1')!=null)
  {
    var x=decodeURIComponent(location.href.split("&autoaddstubtag=")[1]);
    if(x=="") x="stub"; else x+="-stub";
    document.getElementById('wpTextbox1').value+="\n{"+"{"+x+"}}"; //add to the end of the article
    document.getElementById('wpSummary').value=
      "Tagging with {"+"{"+x+"}} using [[WP:US/S|user scripts]]";
    document.getElementById('wpPreview').click();
  }
});
 
function stubtagtab()
{
  var x=prompt("Which stub tag? (Leave blank for {"+
               "{stub}}; otherwise -stub will be added to the name)");
  if(x==null) return;
  location.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+                                  
                "&action=edit&autoaddstubtag="+encodeURIComponent(x);
}
 
// </source> [[Category:Wikipedia scripts]]






var qPreviewKey = '`';
var qPreviewName = 'QPreview';
 
function qPreviewButton(){ 
	addToolbarButton(qPreviewName, qPreview, 'btnQPreview', 'Quick Preview', qPreviewKey);
}
$(qPreviewButton);
 
function qPreview(){
 var divPreview = document.getElementById('wikiPreview');
 if (!divPreview) return;
 var btnQPreview = document.getElementById('btnQPreview');
 if (btnQPreview) btnQPreview.value = 'Wait...';
 a = sajax_init_object();
 a.open('POST', document.editform.action+'&live', true);
 var Boundary = '--------p1415';
 a.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+Boundary);
 var PostData = '--' + Boundary 
  + '\nContent-Disposition: form-data; name="wpTextbox1"\n\n'
  + document.getElementById('wpTextbox1').value + '\n--'+Boundary;
 if (a.overrideMimeType) a.overrideMimeType('text/html');
 a.send(PostData);
 a.onreadystatechange = function(){
  if (a.readyState != 4) return;
	var html = a.responseText;
	html = html.replace(/&gt;/g,'>').replace(/&lt;/g,'<').replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&apos;/g,"'");
	divPreview.innerHTML = html;
	if (btnQPreview)  btnQPreview.value =  qPreviewName;
 };
}
 
//Adds a text button to edit toolbar
function addToolbarButton(name, onclick, id, tooltip, accesskey){
	var toolbar = document.getElementById('toolbar');
	if (!toolbar) return;
	var newBtn = document.createElement('input');
	newBtn.type = 'button'; 
	newBtn.style.background = '#adbede';
	newBtn.style.height = '22px'; 
	newBtn.style.verticalAlign = 'middle';
	if (name) newBtn.value = name; 
	if (onclick) newBtn.onclick = onclick;
	if (id) newBtn.id = id;
	if (tooltip) newBtn.title = tooltip; 
	if (accesskey) newBtn.accessKey = accesskey; 
	toolbar.appendChild(newBtn);
	return newBtn;
}
















//Unwatch:

if (wgCanonicalSpecialPageName && wgCanonicalSpecialPageName=='Watchlist' && wgAction=='view') 
$(function () {
 var frm = document.getElementsByTagName('form')[0];
 frm.parentNode.insertBefore(document.createTextNode(' | '), frm);
 var lnk = document.createElement('a');
 lnk.appendChild(document.createTextNode('Unwatch…'));
 lnk.href = 'javascript:importScript("User:Alex_Smotrov/wlunwatch.js")';
 frm.parentNode.insertBefore(lnk, frm);
})






// 

// Adds a drop-down menu to the search box to choose the namespace to search in.

$(function () {
    var searchGoButton = document.getElementById('searchGoButton');
    if (!searchGoButton) return;

    var searchNsHidden = document.createElement('input');
    searchNsHidden.id = 'searchNsHidden';
    searchNsHidden.type = 'hidden';
    searchNsHidden.name = 'ns0';
    searchNsHidden.value = '1';

    var searchNsMenu = document.createElement('select');
    searchNsMenu.id = 'searchNsMenu';
    searchNsMenu.name = 'ns';
    searchNsMenu.options[searchNsMenu.options.length] = new Option('(Main)', 0);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Talk', 1);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('User', 2);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('User talk', 3);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Wikipedia', 4);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Wikipedia talk', 5);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Image', 6);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Image talk', 7);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('MediaWiki', 8);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('MediaWiki talk', 9);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Template', 10);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Template talk', 11);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Help', 12);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Help talk', 13);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Category', 14);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Category talk', 15);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Portal', 100);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Portal talk', 101);
    searchNsMenu.onchange = function () {
        searchNsHidden.name = 'ns' + (this.selectedIndex < 0 ? '0' : 
this.options[this.selectedIndex].value);
    };
    // From /skins-1.5/monobook/main.css?5:
    searchNsMenu.style.width = '10.9em';
    searchNsMenu.style.margin = '0';
    searchNsMenu.style.fontSize = '95%';
    searchGoButton.parentNode.insertBefore(searchNsHidden, searchGoButton);
    searchGoButton.parentNode.insertBefore(searchNsMenu, searchGoButton);
});





















importScript('User:AzaToth/morebits.js');
importScript('User:AzaToth/twinklefluff.js');
importScript('User:AzaToth/twinklewarn.js');
importScript('User:AzaToth/twinklearv.js');
importScript('User:AzaToth/twinklediff.js');


$(function(){
 addPortletLink ('p-tb', 'http://en.wikipedia.org/wiki/Special:Newpages', 'New pages');
 addPortletLink ('p-tb', 'http://en.wikipedia.org/wiki/Special:Log/Newusers', 'New users');
 addPortletLink ('p-personal', 'http://en.wikipedia.org/w/index.php?title=User:Fry/monobook.css&action=edit', 'css');
 addPortletLink ('p-personal', 'http://en.wikipedia.org/w/index.php?title=User:Fry/monobook.js&action=edit', 'js');
})

// If you are editing a page, click the wikify button on your tab bar to add "{{Wikify|July 2007}}" to the top, set "Marked for wikification" as the edit summary, mark it as a minor edit, and submit.

function doQwikify() {
  document.editform.wpTextbox1.value = '{' + '{' + 'Wikify|' + '{' + '{' + 'subst:CURRENTMONTHNAME}} ' + '{' + '{' + 'subst:CURRENTYEAR}}}}\n\n' + document.editform.wpTextbox1.value;
  document.editform.wpSummary.value = 'Marked for wikification';
  document.editform.wpMinoredit.checked = true;
  document.editform.submit();
}

$(function() {
  if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {
     // wouldn't it make more sense to just check for wgCanonicalNamespace != "", or am I missing something?
     return;
  }
  if (document.editform) {
     mw.util.addPortletLink("p-cactions", "javascript:doQwikify()", "wikify", "ca-wikify", "Mark for wikification", "");
  }
});

// by [[User:Raylu|raylu]]

if (wgNamespaceNumber >= 0)
$(function(){
 var pCactions = document.getElementById('p-cactions');
 if (!pCactions) return;
 var caMain = pCactions.getElementsByTagName('li')[0];
 var caTalk = document.getElementById('ca-talk');
 var caEdit = document.getElementById('ca-edit');
 if (!caEdit) caEdit = document.getElementById('ca-viewsource');
 var caHistory = document.getElementById('ca-history');
 if (!caMain || !caTalk || !caEdit || !caHistory) return;
 var el_move, el_create, id2;
 if (wgNamespaceNumber % 2) { //talk space
   el_move = caTalk; el_create = caMain; id2 = '';
 } else {
   el_move = caMain; el_create = caTalk; id2 = 'discussion';
 }
 caEdit.firstChild.innerHTML = 'edit';
 caHistory.firstChild.innerHTML = 'hist';
 el_move.parentNode.insertBefore(caHistory, el_move.nextSibling);
 el_move.parentNode.insertBefore(caEdit, el_move.nextSibling);
 var href = el_create.firstChild.getAttribute('href', 2);
 if (el_create.className.indexOf('new') < 0){
   mw.util.addPortletLink('p-cactions', href + '?action=history', 'hist',
     'ca-history-'+id2, id2+' history', '', el_create.nextSibling);
   mw.util.addPortletLink('p-cactions', href + '?action=edit', 'edit',
     'ca-edit-'+id2, 'Edit '+id2, '', el_create.nextSibling);
 } 
  caMain.style.marginRight = '0.3em'; 
  caTalk.style.marginRight = '0.3em'; 
  caTalk.style.marginLeft  = '1.6em'; 
})

if ((wgNamespaceNumber % 2 || wgNamespaceNumber==4) 
 &&  document.URL.match(/&action=(edit|submit)/))
$(function(){

 var wpSave = document.getElementById('wpSave');
 if (!wpSave) return;

 if (window.sigText) //change normal sig button as well
   mwEditButtons[9].tagOpen = sigText;
 else 
   sigText = ' — [[User:Fry|Fry]] <small>• ([[User talk:Fry|talk]]) • 02:45, July 27, 2007 (UTC)</small>';

 //create button
 var btn = document.createElement('input');
 btn.type='button'; btn.value = '~';
 btn.onclick = function(){ insertTags(sigText,'','') };
 btn.style.marginRight = '4px'; 
 btn.title = 'Put your signature';
 if (window.sigAccessKey){
   btn.accessKey = sigAccessKey;
   btn.title += ' [' + tooltipAccessKeyPrefix + btn.accessKey + ']';
 } 
 wpSave.parentNode.insertBefore(btn, wpSave);
 
  //for 'Wikipedia:' namespace: Sig is ok on Forum pages, on all others put it after Save button
 if ( ( wgNamespaceNumber == 4 )
  && ( !wgTitle.match('^(Village pump [(]|Reference desk/|Deletion review/|Articles for deletion/|Templates for deletion/|.*noticeboard.*|Requests for (adminship|checkuser|arbitration|feedback|page protection|mediation)|Bot requests|Help desk|Editor review|Adminship survey|Cleanup|Miscellany for deletion|New contributors\' help page|Media copyright questions)')  ) ) 
 {
   wpSave.parentNode.insertBefore(btn, wpSave.nextSibling);
   return; //avoid warning below
 }

 //warn if saving without signature 
 wpSave.onclick = function(){
 if (document.editform.wpTextbox1.value.indexOf('— [[UserFry|Fry]] <small>• ([[User talk:Fry|talk]]) • 02:45, July 27, 2007 (UTC)</small>') >= 0 )
  return true
 else 
  return confirm('No signature?')
 }
})



// HistoryCount
$(function (){
    var N = 250;      // <<== CHANGE TO YOUR LIKING
    var x = document.getElementById('ca-history');
    if(!x) return;
    x.getElementsByTagName('a')[0].href += "&limit=" + N;
});


//Please leave the following line
//[[user:Where/easy db]]
//Start db script

$(function()
{
  //check if called from deletion request
  if (document.title.indexOf("Editing ") != -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");
      if (type == null)
        return;
      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");
      if (type == null)
        return;
      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 (wgCanonicalNamespace == "Special")
    return;

  mw.util.addPortletLink("p-cactions", "javascript:easyDb(0)", "(csd)", "ca-db0", "Request speedy deletion according to WP:CSD", "");
  mw.util.addPortletLink("p-cactions", "javascript:easyDb(1)", "(reason)", "ca-db1", "Request speedy deletion with reason", "");
});
 
function easyDb(n)
{
  if (n == 0)
  {
    //edit page

    location.assign("/w/index.php?title=" + wgPageName + "&action=edit&fakeaction=huff&reason=off");
  }  
   
  if (n == 1)
  {
    //edit page

    location.assign("/w/index.php?title=" + wgPageName + "&action=edit&fakeaction=huff&reason=on");
  }
}

//End db script


function welcome() {

    // Find the edit box
    var txt = document.editform.wpTextbox1;

    //The welcome template you are wanting to use
    var welcome_msg = 'User:Fry/welcome|heading=true|headtext=Hello from [[User:Fry|Fry]]'

    // The tag to be included is an welcome message
    var tag = '{{'+'subst'+':'+ welcome_msg +'}}';

    // If the edit box doesn't already have this tag...
    if (txt.value.indexOf(tag) == -1) {

        // Append the tag
        txt.value += tag;
        
        // Add an edit summary
        document.editform.wpSummary.value = 'Welcome to Wikipedia!';    

        // Press the Save page button
        document.editform.submit();
    } 

    // If the tag was already there, turn the tab background red to indicate 
    // that the script is functioning properly, but that there is no action 
    // to do.  This doesn't interrupt the user's work like an alert() would.
    else {
        document.getElementById('ca-unverified').firstChild.style.backgroundColor = "#ff4444";
        document.getElementById('ca-unverified').style.backgroundColor = "#ff4444";
    }
}

// Create a tab that calls this function when pressed
$(function () {
    if(document.title.indexOf("Editing User talk:") == 0) {
        mw.util.addPortletLink('p-cactions', 'javascript:welcome()', 'welcome', 'ca-welcome', 'Adds a welcome note to a new user', '', '');
    }
});

/* This is to keep track of who is using this extension: [[User:Nmajdan/welcome_newuser.js]] */


// Autolink [[wikilinks]] and {{templates}} (especially useful for monobook.js and similar pages)

$(function () {
    // Get the HTML of just the main body of the page, not including textareas hopefully
    if (document.title.indexOf("Editing ") != 0 && document.title.indexOf("Template:") != 0) {
        targetdiv = document.getElementById('bodyContent');  // bodyContent div for most pages
    } else 
    if (document.getElementById('wikiPreview')) {
        targetdiv = document.getElementById('wikiPreview');  // wikiPreview if it's there
    } else
    if (document.getElementById('wikiDiff')) {
        targetdiv = document.getElementById('wikiDiff');   // wikiDiff if it's there
    } else {
        return;
    }
    content = targetdiv.innerHTML;
    content = content.replace(/([^\[])\[{2}([^\[\]\|\<\>\n]*)([^\[\]\<\>\n]*?)?\]{2}([^\]])/g, '$1<a class="autolink" href="/wiki/$2">[[$2$3]]</a>$4'); // Make wikilink code into links
    content = content.replace(/([^\{])\{{2}(subst\:|msg\:)?([^\{\}\|\<\>\n]*)([^\{\}\<\>\n]*?)?\}{2}([^\}])/g, '$1<a class="autolink" href="/wiki/Template:$3">{{$2$3$4}}</a>$5'); // Make template code into links
    targetdiv.innerHTML = content; // Write it back
});


// Please leave the following line
// [[user:Where/usertabs]]
 
$(function() {
  if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1)  //no subpages or history
     return;
  if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {
     var username = encodeURIComponent( wgTitle );
     mw.util.addPortletLink("p-cactions", wgServer + "/wiki/Special:Contributions/" + username, "Contribs", "ca-contrib", "User contributions");
     mw.util.addPortletLink("p-cactions", "http://tools.wikimedia.de/~interiot/cgi-bin/Tool1/wannabe_kate?username=" + username + "&site=en.wikipedia.org", "count", "ca-editcount", "Edit count from Interiot's Tool1");
     mw.util.addPortletLink("p-cactions", wgServer + "/w/index.php?title=Special:Prefixindex&from=" + username + "/" + "&namespace=2", "space", "", "List of pages in this user's userspace");

  }
});














//Conflicts with force edit summary script!
 
var scIndex = 0;
var scKeys = new Array();
var scValues = new Array();
 
function scFormSubmit() {
   var i=0
   var textArea = document.getElementById("wpTextbox1");
   var text = textArea.value;
   while (i<scIndex) {
      text = text.replace(scKeys[i], scValues[i]);
      ++i;
   }
   textArea.value = text;
}
 
$(function() {
   if (document.title.indexOf("Editing ") != 0) {return;}
   document.getElementById("wpSave").onclick = scFormSubmit;
   document.getElementById("wpPreview").onclick = scFormSubmit;
   document.getElementById("wpDiff").onclick = scFormSubmit;
   //TODO: make it work with previews too!
});
 
 
$(function() {
   if (document.title.indexOf("Editing ") != 0) {return;}
   var textArea = document.getElementById("wpTextbox1");
   var text = textArea.value;
   var re = /<!--\[\[User:Where\/sigContract\]\];(.*)-->.*<!--ESC:(.*)-->/g;
   var lastIndex = 0;
/*   while (1) {
      var textSubstr = text.substr(lastIndex);
      alert(lastIndex);
      alert(textSubstr); //TODO: remove
      var newIndex = textSubstr.search(re);
      alert("newindex:" + newIndex);
      if (newIndex == -1) {
	 break;
      }
      lastIndex += newIndex+1;*/
      text = text.replace(re,
	 function(str, p1, p2, offset, s) {
//	    alert("In replacement function");
	    if (p1 == p2) {
	       var newString = "-[[User:" + p1 + "|" + p1 + "]]";
	       scKeys[scIndex] = newString;
	       scValues[scIndex] = str;
	       ++scIndex;
	       return newString;
	    }
	    else {
	       return str;
	    }
	 });
   //}
   textArea.value = text;
});

// </nowiki>