Jump to content

User:Sander Säde/viewsource.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.
//script to view source quickly
$(ViewSourceButton);
function ViewSourceButton() {
   mw.util.addPortletLink("p-cactions", "javascript:viewSourceQuick()", "source");
}

function viewSourceQuick() {
  var ssourceajax = sajax_init_object();
  var addr =  mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=" + mw.config.get('wgPageName') + "&action=raw"    
  ssourceajax.open("GET", addr, true);
  ssourceajax.onreadystatechange = function()
  {
     if(ssourceajax.readyState != 4) return;
     var csub = document.getElementById("contentSub");
     if (mw.config.get('wgTitle') == "Main Page") {
       var p = document.createElement("code");
       csub = document.getElementById("top").appendChild(p);    
     }
 csub.innerHTML = "<nowiki>" + ssourceajax.responseText.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br/>") + "</nowiki>";
  };
  ssourceajax.send(null);
}