User:EMPee584/vector.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.
//originally taken from User:Misza13/viewSource.js

//<source lang="javascript">
 
// VIEW SOURCE
addOnloadHook(function () {
  if (location.href.indexOf('viewsource=1') != -1) {
    sl = document.getElementById('wpSummaryLabel'); sl.parentNode.removeChild(sl);
    ed = document.getElementById('wpSummary').parentNode; ed.parentNode.removeChild(ed);
    return;
  }
  editbutton = document.getElementById('ca-edit');
  if (editbutton && location.href.indexOf('action=edit')==-1) {
    editlink = editbutton.getElementsByTagName('a')[0].href + '&viewsource=1';
    tabs = document.getElementById('p-views').getElementsByTagName('ul')[0];
    span = document.createElement('span');
    span.appendChild(document.createTextNode('Source'));
    na = document.createElement('a');
    na.href = editlink;
    na.accesskey = 'e';
    na.title = 'View page source [alt-shift-e]';
    na.appendChild(span);
    li = document.createElement('li');
    li.id = 'ca-viewsource';
    li.appendChild(na);
    tabs.insertBefore(li,editbutton);
  }
});
 
//</source>