User:Gerbrant/edit/top.js

From OpenWetWare
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// 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(wgCanonicalNamespace == "Special") return;
	if(document.getElementById("difference‎")) return;
	if(wgTitle == "Main Page") return;

	if(wgAction == "view")
	{
		var divContainer = document.createElement("div");
		divContainer.innerHTML = '<div class="editsection" style="float:right;margin-top:1em;font-size:100%;">[<a href="' + wgScript + '?title=' + wgPageName + '&action=edit&section=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&section=0") != -1)
	{
		e = document.getElementById("wpSummary");
		if(e) e.value = "/* Intro */ " + e.value;
		else alert("Cannot find the ‘Edit summary’ textbox.");
	}
});