User:Krimpet/monobook.js

// PreloadedArticleTabs.js: Please see the talk page for ducmentation!

// From 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) };

/** function QueryString(qString) { this.string = qString; this.params = {}; if( qString.length == 0 ) { return; } qString.replace(/\+/, ' '); var args = qString.split('&'); for( var i in args ) { if( typeof( args[i] ) != 'string' ) { continue; } var pair = args[i].split( '=' ); var key = decodeURIComponent( pair[0] ), value = key; if( pair.length == 2 ) { value = decodeURIComponent( pair[1] ); } this.params[key] = value; } } QueryString.static = null; QueryString.staticInit = function { if( QueryString.static == null ) { QueryString.static = new QueryString(location.search.substring(1)); } } QueryString.get = function(key) { QueryString.staticInit; return QueryString.static.get(key); }; QueryString.prototype.get = function(key) { return this.params[key] ? this.params[key] : null; }; QueryString.exists = function(key) { QueryString.staticInit; return QueryString.static.exists(key); } QueryString.prototype.exists = function(key) { return this.params[key] ? true : false; } QueryString.equals = function(key, value) { QueryString.staticInit; return QueryString.static.equals(key, value); } QueryString.prototype.equals = function(key, value) { return this.params[key] == value ? true : false; } QueryString.toString = function { QueryString.staticInit; return QueryString.static.toString; } QueryString.prototype.toString = function { return this.string ? this.string : null; } QueryString.create = function( arr ) { var resarr = Array; for( var i in arr ) { if( typeof arr[i] == 'object' ){ var v = Array; for(var j in arr[i] ) { v[j] = encodeURIComponent( arr[i][j] ); } resarr.push( encodeURIComponent( i ) + '=' + v.join('|')  ); } else { resarr.push( encodeURIComponent( i ) + '=' + encodeURIComponent( arr[i] ) ); } } return resarr.join('&'); } QueryString.prototype.create = QueryString.create;
 * Maps the querystring to an object
 * Functions:
 * QueryString.exists(key)
 * returns true if the particular key is set
 * QueryString.get(key)
 * returns the value associated to the key
 * QueryString.equals(key, value)
 * returns true if the value associated with given key equals given value
 * QueryString.toString
 * returns the query string as a string
 * QueryString.create( hash )
 * creates an querystring and encodes strings via encodeURIComponent and joins arrays with |
 * In static context, the value of location.search.substring(1), else the value given to the constructor is going to be used. The mapped hash is saved in the object.
 * Example:
 * var value = QueryString.get('key');
 * var obj = new QueryString('foo=bar&baz=quux');
 * value = obj.get('foo');
 * Example:
 * var value = QueryString.get('key');
 * var obj = new QueryString('foo=bar&baz=quux');
 * value = obj.get('foo');
 * value = obj.get('foo');

// Preloaded Article Tabs

$(function { //check if called from stub request  if (wgAction == 'edit')  {    if (QueryString.exists("tag"))    {      var pos = 0;      if(QueryString.get("pos") == "adjective"){           pos = 1;      }      if(QueryString.get("pos") == "plural"){           pos = 2;      }      if(QueryString.get("pos") == "verb"){           pos = 3;      }      if(QueryString.get("pos") == "adverb"){           pos = 4;      }      var type = QueryString.get("tag");      if(pos == 0){           document.editform.wpTextbox1.value = "==Spanish==\n\n===Noun===\n" + "{" + "{es-noun-m}}\n\n# " + "" + type + "\n"+document.editform.wpTextbox1.value;      }if(pos == 1){           document.editform.wpTextbox1.value = "==Spanish==\n\n===Adjective===\n" + "{" + "{es-adj|f=}}\n\n# " + "" + type + "\n"+document.editform.wpTextbox1.value;      }if(pos == 2){           document.editform.wpTextbox1.value = "==Spanish==\n\n===Noun===\n" + "{" + "{subst:PAGENAME}}\n\n# " + "{" + "{plural of|lang=Spanish|" + type + "}}\n\n"+document.editform.wpTextbox1.value; }if(pos == 3){ document.editform.wpTextbox1.value = "==Spanish==\n\n===Verb===\n" + "{" + "{es-verb-ar|stem=}}\n\n# to " + "" + type + "\n\n====Conjugation====\n" + "{" + "{es-conj-ar|}}\n"+document.editform.wpTextbox1.value; }if(pos == 4){ document.editform.wpTextbox1.value = "==Spanish==\n\n===Adverb===\n" + "{" + "{subst:PAGENAME}}\n\n# " + "" + type + "\n"+document.editform.wpTextbox1.value; }     document.editform.wpMinoredit.checked = false; document.editform.wpSummary.value = ""; return; } } if (wgCanonicalNamespace == "Special"){ return; } mw.util.addPortletLink("p-cactions", "javascript:easyTagNoun", "Noun", "ca-tagt", "Create noun article.", ""); mw.util.addPortletLink("p-cactions", "javascript:easyTagAdjective", "Adjective", "ca-tagt", "Create adjective form.", ""); mw.util.addPortletLink("p-cactions", "javascript:easyTagPlural", "Plural", "ca-tagt", "Create plural form.", ""); mw.util.addPortletLink("p-cactions", "javascript:easyTagVerb", "Verb", "ca-tagt", "Create verb form.", ""); mw.util.addPortletLink("p-cactions", "javascript:easyTagAdverb", "Adverb", "ca-tagt", "Create adverb form.", ""); }); function easyTagNoun { var title = encodeURIComponent(mw.config.get('wgPageName'));  var tag = window.prompt("Enter noun translation.");  if(tag == null){     return;  }  location.assign("/w/index.php?action=edit&tag=" + tag + "&pos=noun&title=" + title); } function easyTagAdjective {  var title = encodeURIComponent(mw.config.get('wgPageName'));  var tag = window.prompt("Enter adjective translation.");  if(tag == null){     return;  }  location.assign("/w/index.php?action=edit&tag=" + tag + "&pos=adjective&title=" + title); } function easyTagPlural {  var title = encodeURIComponent(mw.config.get('wgPageName'));  var tag = window.prompt("Enter lemma name.");  if(tag == null){     return;  }  location.assign("/w/index.php?action=edit&tag=" + tag + "&pos=plural&title=" + title); } function easyTagVerb {  var title = encodeURIComponent(mw.config.get('wgPageName'));  var tag = window.prompt("Enter verb translation."); if(tag == null){ return; } location.assign("/w/index.php?action=edit&tag=" + tag + "&pos=verb&title=" + title); } function easyTagAdverb { var title = encodeURIComponent(mw.config.get('wgPageName')); var tag = window.prompt("Enter adverb translation."); if(tag == null){ return; } location.assign("/w/index.php?action=edit&tag=" + tag + "&pos=adverb&title=" + title); }

if (window.location.search.indexOf("_auto_") != -1) { where = window.location.search.indexOf("_auto_") + 6; what = window.location.search.substring(where, window.location.search.indexOf("_=", where));

from = document.referrer; if (from.indexOf("/wiki/") != -1) { from = from.substring(from.indexOf("/wiki/") + 6); if (from.indexOf("#") != -1) from = from.substring(0, from.indexOf("#")); if (from.indexOf("?") != -1) from = from.substring(0, from.indexOf("?")); } else if (from.indexOf("title=") {       from = from.substring(from.indexOf("title=") + 6);        if (from.indexOf("&") != -1) from.substring(0, from.indexOf("&"));    }    from = unescape(from.replace("_", " ")); }