User:Gerbrant/edit/top.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Gerbrant/edit/top. |
// This will add an [edit] link at the top of all pages except preview pages and the main page
// Originally by [[User:Pile0nades]], modified by [[User:Gerbrant]].
// Add an [edit] link to pages
hookEvent("load", function ()
{
if(mw.config.get('wgCanonicalNamespace') == "Special") return;
if(document.getElementById("difference")) return;
if(mw.config.get('wgTitle') == "Main Page") return;
if(mw.config.get('wgAction') == "view")
{
var divContainer = document.createElement("div");
divContainer.innerHTML = '<div class="editsection" style="float:right;margin-top:1em;font-size:100%;">[<a href="' + mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName') + '&action=edit§ion=0" title="Edit introduction">edit</a>]</div>';
var coos = document.getElementById("coordinates");
if(coos) coos.style.right = "4.5em";
document.getElementById("content").insertBefore(
divContainer, document.getElementsByTagName("h1")[0]);
}
else if(window.location.href.indexOf("&action=edit§ion=0") != -1)
{
e = document.getElementById("wpSummary");
if(e) e.value = "/* Intro */ " + e.value;
else alert("Cannot find the ‘Edit summary’ textbox.");
}
});