Jump to content

User:WhyBeNormal/monobook.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.
//Interiot's javascript edit counter
if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) {
  mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js&action=raw&ctype=text/javascript'); }
//Edit and "revert to" JS
//addOnloadHook(adddifflinks)
function adddifflinks()
{
var editlink = '<strong><span style="color:black;">[</span>edit this version<span style="color:black;">]</span></strong> ';
var rvname = ' <strong><span style="color:black;">[</span><span style="color:red;">restore this revision</span><span style="color:black;">]</span></strong><br>';
var user_name = document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML;
if (location.href.indexOf('diff=') != -1 && location.href.indexOf('&oldid=') != -1)
  {
  var doctd = document.getElementById('bodyContent').getElementsByTagName('td');
  var good_user = doctd[0].getElementsByTagName('a')[2].innerHTML;
  var link = doctd[0].getElementsByTagName('a')[0].href.replace('&amp;','&') + "&action=edit";
  var rvlink = doctd[0].getElementsByTagName('a')[0].href.replace('&amp;','&') + "&action=edit&fakeaction=autorevert&byuser=" + escape(user_name) + "&oldrvtouser=" + escape(good_user);
    document.getElementById('bodyContent').getElementsByTagName('td')[0].innerHTML = '<a href="' + rvlink + '">' + rvname + '</a>' + document.getElementById('bodyContent').getElementsByTagName('td')[0].innerHTML;
   }
}
//END

$(IEhistory_revert)
function IEhistory_revert()
{
if (location.href.indexOf('&action=history&limit=8&fakeaction=IEnormalrevert&user=') != -1)
  { 
  var found = 0;
  var user_name = document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML;
  if (unescape(location.href.split('&byuser=')[1]) != user_name){alert('Invalid user match'); return;}
  var vandal = unescape(location.href.split('&fakeaction=IEnormalrevert&user=')[1].split('&byuser=')[0]);
  var l = document.getElementsByTagName('li');
  if (l[0].getElementsByTagName('a')[2].innerHTML != vandal)
  {alert('Could not rollback. Last contributor has changed.'); return;}
  for (i = 1; i < l.length; i++)
      {
     if (!l[i].getElementsByTagName('a')[3]){alert('Could not find a version of this page that is not by the user you attempted to rollback from.' + '\n' + 'Most likely, the user is the only author of the page.' + '\n' + 'This revert function only looks at the last 6 page edits, so you may want to look back further and use "restore".'); history.go(-1); return;}
     if (l[i].getElementsByTagName('a')[3].innerHTML != vandal)
         {
     var good_user = l[i].getElementsByTagName('a')[3].innerHTML;
     var URL = l[i].getElementsByTagName('a')[2].href + "&action=edit&fakeaction=autorevert&byuser=" + escape(user_name) + "&oldrvtouser=" + escape(good_user) + "&revertfromuser=" + escape(vandal);
     location.href = URL;
     found = 1;
     break;
         }
      }
   if (found == 0)
  {alert('Could not find a version of this page that is not by the user you attempted to rollback from.' + '\n' + 'Most likely, the user is the only author of the page.' + '\n' + 'This revert function only looks at the last 6 page edits, so you may want to look back further and use "restore".'); history.go(-1);}
   }
if (location.href.indexOf('&action=history&limit=8&fakeaction=IErollback&vandal=') != -1)
  { 
  var found = 0;
  var user_name = document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML;
  if (unescape(location.href.split('&byuser=')[1]) != user_name){alert('Invalid user match'); return;}
  var vandal = unescape(location.href.split('&fakeaction=IErollback&vandal=')[1].split('&byuser=')[0]);
  var l = document.getElementsByTagName('li');
  if (l[0].getElementsByTagName('a')[2].innerHTML != vandal)
  {alert('Could not rollback vandal. Last contributor has changed.'); return;}
  for (i = 1; i < l.length; i++)
      {
     if (!l[i].getElementsByTagName('a')[3]){alert('Could not find a version of this page that is not by the user you attempted to rollback from.' + '\n' + 'Most likely, the user is the only author of the page.' + '\n' + 'This revert function only looks at the last 6 page edits, so you may want to look back further and use "restore".'); history.go(-1); return;}
     if (l[i].getElementsByTagName('a')[3].innerHTML != vandal)
         {
     var good_user = l[i].getElementsByTagName('a')[3].innerHTML;
     var URL = l[i].getElementsByTagName('a')[2].href + "&action=edit&fakeaction=autorevertvandal&byuser=" + escape(user_name) + "&oldrvtouser=" + escape(good_user) + "&revertfromuser=" + escape(vandal);
     location.href = URL;
     found = 1;
     break;
         }
      }
   if (found == 0)
  {alert('Could not find a version of this page that is not by the user you attempted to rollback from.' + '\n' + 'Most likely, the user is the only author of the page.' + '\n' + 'This revert function only looks at the last 6 page edits, so you may want to look back further and use "restore".'); history.go(-1);}
   }
}
//END

function autosave()
{
user_name = escape(document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML);
if (location.href.indexOf("&fakeaction=autorevert&byuser=" + user_name) != -1 || location.href.indexOf("&fakeaction=autorevertvandal&byuser=" + user_name) != -1) 
    {
  if (location.href.indexOf('&revertfromuser') == -1 && location.href.indexOf('&fakeaction=autorevertvandal') == -1)
  {
  var message = "Are you sure you want to revert to this revision?"; 
  var return_value = confirm(message); 
  if (return_value != true){history.go(-1); return;}
  }
  var good_user = unescape(location.href.split("&oldrvtouser=")[1].split('&revertfromuser=')[0]);
  var ID = location.href.split("&oldid=")[1].split("&action=edit")[0];
  form = document.getElementById('bodyContent');
  l = form.getElementsByTagName('input');
  for (i = 0; i < l.length; i++)
      {
    if (l[i].name == 'wpMinoredit')
      {l[i].value = '1'; l[i].checked=true;}
      }
if (location.href.indexOf('&fakeaction=autorevertvandal') != -1)
       { 
var artname = document.title.split('Editing ')[1].split(' - ')[0];
var vandal = unescape(location.href.split('&revertfromuser=')[1]);
document.editform.wpSummary.value += 'JS: Reverted [[WP:VAND|vandalism]] by [[Special:contributions/' + vandal + '|' + vandal + ']] to last version by ' + good_user + '.';
var form = document.getElementById('editform');
window.open('http://en.wikipedia.org/w/index.php?title=User talk:' + vandal + '&action=edit' + '&action=edit&vanarticle=' + artname,
              'targetname',
    'location=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=1024,height=768');
form.submit();
        }
else if (location.href.indexOf('&revertfromuser=') != -1)
       { 
var vandal = unescape(location.href.split('&revertfromuser=')[1]);
document.editform.wpSummary.value += 'JS: Reverted edits by [[Special:contributions/' + vandal + '|' + vandal + ']] to last version by ' + good_user + '.';
var form = document.getElementById('editform');
form.submit();
       }
else
       {
document.editform.wpSummary.value += 'JS: Revert to revision ' + ID + ' by [[User:' + good_user + '|' + good_user + ']].';
var form = document.getElementById('editform');
form.submit();
       }
    }
}
//END

//Revert options
$(NArevertfunctions)
function NArevertfunctions()
{
adddifflinks();
autosave();
}
// Script from [[User:Lupin/recent2.js]]
mw.loader.load(
             'https://en.wikipedia.org/w/index.php?title=User:Lupin/recent2.js'
             + '&action=raw&ctype=text/javascript&dontcountme=s');
//This code will change ISBN links to point to the url of your choice,
//instead of Special:Book_sources. 
//
//How to use it:
//
//First, you must copy this code to your user javascript page. This is 
//at User:<your username>/monobook.js . My username is Lunchboxhero so
//my javascript page is User:Lunchboxhero/monobook.js . You must be logged
//in to edit your javascript page.
//
//Once you have copied the code and saved the page, you need to refresh your
//browser's cache. For Mozilla/Safari/Konqueror: hold down Shift while clicking 
//Reload (or press Ctrl-Shift-R), IE: press Ctrl-F5, Opera: press F5.
//
//The code should now work, as long as you are logged in.
//
//You can change the destination url by simply modifying the quoted url that
//follows document.links[i].href=
//
//Good luck, and if you have any questions, leave me a comment on the discussion
//page of User:Lunchboxhero/monobook.js .
//
//(Every line that starts with "//" is a comment and can be discarded.)

function externISBN() {
  for (var i = 0; i < document.links.length; i++) 
    {       
         var ln = document.links[i].href.match(/isbn=(.*)/);
         if (ln) {
           document.links[i].href='http://www.amazon.com/exec/obidos/ASIN/'+RegExp.$1;
         }
    }

}

$(externISBN);
// This will add an [edit top] link at the top of all pages except preview pages
// by User:Pile0nades

setTimeout("editTopLink()", 0) // this is equivalent of onload
function editTopLink() {
  // if this is preview page or generated page, stop
  if(document.getElementById("wikiPreview") || window.location.href.indexOf("w/index.php?title=Special:") != -1) return;

  // get the page title
  var pageTitle = document.title.split(" - ")[0].replace(" ", "_"); 

  // create div and set innerHTML to link
  var divContainer = document.createElement("div");
  divContainer.innerHTML = '<div class="editsection" style="float:right;margin-left:5px;margin-top:3px;">[<a href="/w/index.php?title='+pageTitle+'&action=edit&section=0" title="'+document.title.split(" - ")[0]+'">edit top</a>]</div>';

  // insert divContainer into the DOM before the h1
  document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);

}