User:Superm401/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.
<!----><pre>
var url=window.location.href;
var docTitle=document.title;
 
if(wgAction == 'view' || wgAction == "purge" && wgEnableAPI) {
  var url = wgServer + wgScriptPath + '/api.php?action=query&prop=images|templates&callback=watchTemplatesImages&format=json&titles=' + encodeURIComponent(wgPageName);
  var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',url);
  scriptElem.setAttribute('type','text/javascript');
  document.getElementsByTagName('head')[0].appendChild(scriptElem);
  var imagesHere = new Array();
  var templatesHere = new Array();
  addOnloadHook(function() {
    addPortletLink('p-cactions','javascript:watchTemplatesImagesDo()','Watch All','ca-watchall','Watch all templates and images in this page');
  });
}
 
function watchTemplatesImages(obj) {
  if(!obj['query'] || !obj['query']['pages'] || !obj['query']['pages'][wgArticleId]) return
  imagesHere = obj['query']['pages'][wgArticleId]['images'];
  templatesHere = obj['query']['pages'][wgArticleId]['templates'];
  if(!imagesHere) imagesHere = [];
  if(!templatesHere) templatesHere = [];
}
 
function watchTemplatesImagesDo() {
  var list = "";
 
  for(var i=0;i<imagesHere.length - 1;i++) {
    list += imagesHere[i].title + '|';
    //alert("adding image: " + imagesHere[i].title)
  }
  list += imagesHere[imagesHere.length - 1].title;
 
  if(templatesHere.length > 0)
    list += "|";
 
  for(var i = 0;i < templatesHere.length - 1; i++) {
    list += templatesHere[i].title + '|';
    //alert("adding template: " + templatesHere[i].title)
  }
    list += templatesHere[templatesHere.length - 1].title;
 
  url = wgServer + wgScriptPath + '/api.php?action=query&prop=info&callback=getExistingIncludes&format=json&titles=' + encodeURIComponent(list);
  var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',url);
  scriptElem.setAttribute('type','text/javascript');
  document.getElementsByTagName('head')[0].appendChild(scriptElem);
}
 
function getExistingIncludes(obj)
{
  //alert("Entering getExistingIncludes");
 
  var pageList = obj["query"]["pages"];
 
  var existList = "";
 
  for(var i in pageList)
  {
    if(pageList[i]["missing"] == null)
    {
      existList += pageList[i]["title"] + "\n";
    }
    else
    {
      //alert(pageList[i]["title"] + " does not exist!");
    }
  }
 
  //genWatchBox(existList);
  watchItems(existList);
}
 
var lastWatchSuccess;
 
function watchItems(existList)
{ 
 
  var existArray = existList.split("\n");
  var success, allsuccess;
 
  for(var i = 0; i < existArray.length - 1; i++) // there is blank at end
  {
     watchPage(existArray[i]);
     success = lastWatchSuccess;     
 
     if(!success)
     {
       allSuccess = false;
       alert("Failed to watch: " + existArray[i]);
     }
  }
 
  alert("All successful: " + allSuccess);
}
 
function tempImageProcessResult(request)
{
  alert("Entering tempImageProcessResult");
 
 if(!wgAjaxWatch.supported) {
		return;
	}
	var response = request.responseText;
	alert(response);
 
        if( response.match(/^<w#>/) ) {
		lastWatchSuccess = true;
	} else if( response.match(/^<u#>/) ) {
		lastWatchSuccess = true;
	} else {
		lastWatchSuccess = false;
		return;
	}
	jsMsg( response.substr(4), 'watch' );
	wgAjaxWatch.inprogress = false;
	if(wgAjaxWatch.timeoutID) {
		window.clearTimeout(wgAjaxWatch.timeoutID);
	}
	return;
}
 
 
function watchPage(curName)
{
   if(!wgAjaxWatch.supported) {
     return true;
   } else if (wgAjaxWatch.inprogress) {
     return false;
   }
   if(!wfSupportsAjax()) { 
     // Lazy initialization so we don't toss up
     // ActiveX warnings on initial page load
     // for IE 6 users with security settings.
     wgAjaxWatch.supported = false;
     return true;
   }  
 
   wgAjaxWatch.inprogress = true;
   //wgAjaxWatch.setLinkText( wgAjaxWatch.watching ? wgAjaxWatch.unwatchingMsg : wgAjaxWatch.watchingMsg);
 
   sajax_do_call(
		"wfAjaxWatch",
		[curName, (wgAjaxWatch.watching ? "u" : "w")], 
		tempImageProcessResult
   );
   // if the request isn't done in 10 seconds, allow user to try again
   wgAjaxWatch.timeoutID = window.setTimeout(
		function() { wgAjaxWatch.inprogress = false; },
		10000
   );
   return false;
}
 
 
function genWatchBox(list)
{
 //half-assed watchlist/addendum-generator thing
  var cs = document.getElementById('contentSub');
  if(!cs) return;
  var wall = document.createElement('div');
  wall.style.backgroundColor = '#bbffbb';
  wall.style.padding = '8px';
  wall.appendChild(document.createTextNode('WATCH ALL: Please copy the text in the textarea below to your '));
  var wlink = document.createElement('a');
  wlink.setAttribute('href',wgServer + wgScript + '?title=Special:Watchlist/raw');
  wlink.appendChild(document.createTextNode('Raw watchlist'));
  wall.appendChild(wlink);
  var wlta = document.createElement('textarea');
  wlta.value = list;
  wlta.setAttribute('id','wlta');
  wlta.setAttribute('readonly','readonly');
  wlta.style.height = '6em';
  wlta.style.backgroundColor = '#fff6dd';
  wall.appendChild(wlta);
  cs.appendChild(wall);
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
importScript("MediaWiki:Gadget-addsection-plus.js"); // makes the add section link a "+", rather than "new section", to save space.
 
// Override http://en.wikipedia.org/w/index.php?title=MediaWiki:Monobook.css&diff=206765744&oldid=201250491 , going back to http://en.wikipedia.org/skins-1.5/monobook/main.css
function fixPlusStyle()
{
  var addSectionTab = document.getElementById("ca-addsection");
  if(addSectionTab && addSectionTab != null)
  {
    plusLink = addSectionTab.firstChild;
    plusLink.style.paddingLeft = ".4em";
    plusLink.style.paddingRight = ".4em";
  }
}
addOnloadHook(fixPlusStyle);
 
if(url.indexOf('action=delete')>=0 && url.indexOf('title=Image:')>=0 && url.indexOf('&image=')==-1)
{
var imgName=url.substring(url.indexOf('title=Image:')+12,url.indexOf('&action=delete'));
window.location.href=url+'&image='+imgName;
}
 
//Originally based on http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510
//See [[Wikipedia:WikiProject User scripts/Scripts/Show last diff]]
// addLastDiff
function addLastDiff()
{
  addPortletLink('p-cactions', wgServer + wgScriptPath + '/index.php?title=' + wgPageName + "&diff=cur&oldid=prev", 'last', 'ca-last', 'Show most recent diff');
}
 
function addEditZero () {
    var x;
    if (!(x = document.getElementById('ca-edit') )) return;
    var url;
    if (!(url = x.getElementsByTagName('a')[0] )) return;
    if (!(url = url.href )) return;
    var y = addPortletLink('p-cactions', url+"&section=0", '0', 'ca-edit-0',
                           'Edit the lead section of this page', '0', x.nextSibling);
 
    y.className = x.className;  // steal classes from the the edit tab...
    x.className = 'istalk';     // ...and make the edit tab have no right margin
 
    // exception: don't steal the "selected" class unless actually editing section 0:
    if (/(^| )selected( |$)/.test(y.className)) {
        if (!document.editform || !document.editform.wpSection
            || document.editform.wpSection.value != "0") {
            y.className = y.className.replace(/(^| )selected( |$)/g, "$1");
            x.className += ' selected';
        }
    }
};
 
function addPurge()
{
  addPortletLink("p-cactions", wgServer + wgScriptPath + '/index.php?title=' + wgPageName + '&action=purge', 'purge', 'ca-purge', 'Purge the internal cache for this page');
}
 
//Should only run if page has a history (i.e. is or could be editable)
function doHistorical()
{
  var hist = document.getElementById('ca-history');
  if(hist) 
  {
    //addLastDiff();
    addPurge();
    addEditZero();
  }
}
addOnloadHook(doHistorical);
 
// From [[User:Lunchboxhero/monobook.js]]
/*
var magicURL = "http://www.amazon.com/gp/search?ie=UTF8&field-isbn=MAGICNUMBER&tag=wikipedia08-20"
importScript('User:Lunchboxhero/externISBN.js');
*/
function addLink(where, url, name, id, title, key, after){
    //* where is the id of the toolbar where the button should be added;
    //   i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb".
    //* url is the URL which will be called when the button is clicked.
    //   javascript: urls can be used to do more complex things.
    //* name is what will appear as the name of the button.
    //* id is the id of the button; it's best to define one.  
    //   Use a prefix to make sure its unique. Optional.
    //* title is the tooltip title that gives a longer description 
    //   of the button; if you define a accesskey, mention it here. Optional.
    //* key is the char you want for the accesskey. Optional.
    //* after is the id of the button you want to follow this one. Optional.
    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);
    var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
    if(after) {
        tabs.insertBefore(li,document.getElementById(after));
    } else {
        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;
}
 
function doTag(tag, summary, minor, watch)
{
document.editform.wpTextbox1.value = "{{" + tag + "}}" + "\n\n" + document.editform.wpTextbox1.value;
document.editform.wpSummary.value = summary;
document.editform.wpMinoredit.checked = minor;
document.editform.wpWatchthis.checked = watch;
}
 
function doWPUI() {
  document.editform.wpSummary.value = "Thousands of pictures are untagged. [[WP:UI|You can help!]]";
  document.editform.wpMinoredit.checked = false;
  document.editform.wpWatchthis.checked = false;
  document.editform.submit();
}
 
function addNoSource() {
  addLink("p-cactions","javascript:doTag(\"subst:nsd\", \"No source, uploader notified. [[WP:UI]]\", false, true)", "no s", "ca-nosource", "Tag as No source", null);
}
 
function addNoLicense() {
  addLink("p-cactions", "javascript:doTag(\"subst:nld\", \"No © tag, uploader notified. [[WP:UI]]\", false, true)", "no ©", "ca-nolicense", "Tag as No license", null);
}
 
function addIfD() {
  addLink("p-cactions", "javascript:doTag(\"IFD\", \"Image is now listed for [[WP:IFD|deletion]], uploader notified. [[WP:UI]]\", false, true);", "ifd", "ca-ifd", "Tag for deletion", null);
}
function addORCR() {
  addLink("p-cactions","javascript:addTag(\"or-cr|~~~~~\", \"[[:Category:Orphaned unfree image|unfree orphan]], [[WP:UI]]\", false, true);", "ORCR", "ca-ORFU", "Tag as orphan unfree image", null);
}
 
function addWPUI() {
  addLink("p-cactions","javascript:doWPUI()", "WP:UI", "ca-WPUI", "WP:UI summary", null);
}
 
if (document.title.indexOf("Editing Image:") == 0) {
  addOnloadHook(addNoSource);
  addOnloadHook(addNoLicense);
  addOnloadHook(addIfD);
  addOnloadHook(addORCR);
  addOnloadHook(addWPUI);
  addOnloadHook(akeytt);
}
 
// [[User:Krimpet/CH2.js]]
importScript('User:Superm401/CH2.js');
 
function addUserLogs()
{
  var user = wgTitle;
  addLink("p-tb", "/w/index.php?title=Special:Log&type=block&page=User:" + user, "Block log", "t-blocklog", null, null, "t-blockip");
  //addLink("p-tb", "/w/index.php?title=Special:Log&user=" + user, "User log", "t-userlog", null, null, "t-blocklog");
  addEditCount(user);
}
 
function addEditCount(user)
{
  addLink("p-tb", "http://tools.wikimedia.de/~river/cgi-bin/count_edits?user=" + user + "&dbname=enwiki_p", "Edit count", "t-editcount", null, null, "t-log");
 
}
 
function addPageLog()
{
  addLink("p-tb", "/w/index.php?title=Special%3ALog&page=" + wgPageName, "Log", "t-pagelog", null, null, "t-whatlinkshere");
}
 
if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") 
{
  addOnloadHook(addUserLogs);
}
 
if (wgCanonicalNamespace == "Special" && wgTitle == "Contributions")
{
  addOnloadHook(addContribLinks);
}
 
function addContribLinks()
{
  var allForms = document.getElementsByTagName("form");
  var contribForm = allForms[0];
 
  var targetInput;
  var i = 0;
  var allInputs = contribForm.getElementsByTagName("input");
 
  while((targetInput == null || targetInput.getAttribute("name") != "target") && i < allInputs.length)
  {
    targetInput = allInputs[i];
    i++;
  }
 
  username = targetInput.getAttribute("value");
  addEditCount(username);
}
 
if(wgCanonicalNamespace != "Special")
{
  addOnloadHook(addPageLog);
}
 
// [[User:Lupin/popups.js]]
 
 
popupAdminLinks=true;
popupActionsMenu=false;
popupHistoryLimit=1000;
popupFixRedirs=true; 
popupOnEditSelection=false;
popupDiffDatePrinter='toUTCString';
 
 
importScript("User:Lupin/popups.js");
 
/*
importScript("User:Lupin/popupsdev.js");
*/
 
importScript('User:AzaToth/twinkle.js');
 
//add quick-delete
/*document.write('<sc'+'ript type="text/javascript" src="'
             + 'http://en.wikipedia.org/w/index.php?title=User:Superm401/quickDelete.js'
             + '&action=raw&ctype=text/javascript&dontcountme=s"></sc'+'ript>');*/
 
function fixSearch()
{
  var searchInput=document.getElementById("searchInput");
  searchInput.setAttribute("name","q");
 
  var searchForm=document.getElementById("searchform"); 
  searchForm.setAttribute("action","http://www.google.com/search"); 
 
  var siteSearch=document.createElement("input");
  siteSearch.setAttribute("type","hidden");
  siteSearch.setAttribute("name","sitesearch");
  siteSearch.setAttribute("value",window.location.host);
  searchForm.appendChild(siteSearch);
 
  var goButton=document.getElementById("searchGoButton");
  goButton.setAttribute("type","button");
  goButton.addEventListener("click",function () {var queryBox=document.getElementById("searchInput");window.location= wgServer + "/wiki/" + queryBox.value;}, false); 
}
addOnloadHook(fixSearch);
 
function fixCompare()
{
  var histForm=document.getElementsByTagName("form")[0];
  var finalButton=document.getElementById("historysubmit");
  if(!finalButton || finalButton == null)
    return;
 
  var firstButton=histForm.getElementsByTagName("input")[1];
  histForm.removeChild(finalButton);
  histForm.removeChild(firstButton);
  var compareLink=document.createElement("a");
  var genLink = wgServer + wgScript + "?title=" + histForm.title.value + "&diff=" + histForm.diff[0].value + "&oldid=" + histForm.oldid[1].value;
  compareLink.setAttribute("href", genLink);
  compareLink.appendChild(document.createTextNode("Compare selected versions"));
  histForm.insertBefore(compareLink, document.getElementById("pagehistory"));
  var endLink=compareLink.cloneNode(true);
  histForm.appendChild(endLink);
  var diffList=document.getElementById("pagehistory");
  diffList.setAttribute("onchange", "updateCompare()");
}
function updateCompare()
{
  var histForm=document.getElementsByTagName("form")[0];
  var diffList=document.getElementById("pagehistory");
  var compareLink=diffList.previousSibling;
  var endLink=diffList.nextSibling;
  var oldInd=-1;
  var i=0;
  while(oldInd==-1 & i<histForm.oldid.length)
  {
    if(histForm.oldid[i].checked)
      oldInd=i;
    i++;
  }
  var diffInd=-1;
  var j=0;
  while(diffInd==-1 & j<histForm.diff.length)
  {
    if(histForm.diff[j].checked)
      diffInd=j;
    j++;
  }
var genLink = wgServer + wgScript + "?title=" + histForm.title.value + "&diff=" + histForm.diff[diffInd].value + "&oldid=" + histForm.oldid[oldInd].value;
  compareLink.setAttribute("href", genLink);
  endLink.setAttribute("href", genLink);
}
if(url.indexOf("action=history")!=-1)
addOnloadHook(fixCompare);
 
if (url.indexOf("Special:Statistics")!=-1)
setTimeout("window.location.reload()",30000);
 
function removeKeys()
 {
  var saveBtn=document.getElementById("wpSave");
  saveBtn.removeAttribute("accesskey");
  saveBtn.removeAttribute("title");
  var previewBtn=document.getElementById("wpPreview");
  previewBtn.removeAttribute("accesskey");
  previewBtn.removeAttribute("title");
  var diffBtn=document.getElementById("wpDiff");
  diffBtn.removeAttribute("accesskey");
  diffBtn.removeAttribute("title");
 }
 if(window.location.href.indexOf("action=edit")!=-1)
 addOnloadHook(removeKeys);
 
<!----></pre>