MyWiki:Tools/View source

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

// VIEW SOURCE

addOnloadHook(function () {

 if (location.href.indexOf('viewsource=1') != -1) {
   const sl = document.getElementById('wpSummaryLabel');
   sl.parentNode.removeChild(sl);
   const ed = document.getElementById('wpSummary').parentNode;
   ed.parentNode.removeChild(ed);
   return;
 }
 const editbutton = document.getElementById('ca-edit');
 if (editbutton && location.href.indexOf('action=edit') == -1) {
   const editlink = editbutton.getElementsByTagName('a')[0].href + '&viewsource=1';
   const tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
   const na = document.createElement('a');
   na.href = editlink;
   na.appendChild(document.createTextNode('view source'));
   const li = document.createElement('li');
   li.id = 'ca-viewsource';
   li.appendChild(na);
   tabs.insertBefore(li,editbutton);
 }

});