User:Blue-Haired Lawyer/monobook.js

From Wikipedia, the free encyclopedia

If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// A very simple srcipt to put an edit tag beside the page title, right were it should be.
// Assuming you're using monobook, just copy the page and paste it into your own monobook.js
// file in your own user name space or in other words [[User:YOUR_USER_NAME_HERE/monobook.js]].
// I've tested this script on Firefox2 and Safari2 on Mac X, but it should work with other
// browsers. 
function showLedeEditTag() {
	if(document.getElementsByTagName('SPAN')) {
		var len = document.getElementsByTagName('SPAN').length;
		for(var j = 0; j < len; j++) {
			obj = document.getElementsByTagName('SPAN')[j];
			if(obj.className == 'editsection') {
				var ref = obj.getElementsByTagName('A')[0].href.slice(0, -1) + '0';			
				var newspan = document.createElement('span');
				newspan.setAttribute('class', 'editsection');
				newspan.innerHTML = '[<a href="' + ref + '" title="Edit lede">edit</a>]';
				document.getElementsByTagName('h1')[0].innerHTML = ' ' + document.getElementsByTagName('h1')[0].innerHTML;
				document.getElementsByTagName('h1')[0].insertBefore(newspan, document.getElementsByTagName('h1')[0].firstChild);
				break;
			}
		}
	}
}
 
if(window.addEventListener) {
	window.addEventListener("load", showLedeEditTag, false);
} else if(window.attachEvent) {
	window.attachEvent("onload", showLedeEditTag);
}
// Written by [[User:Caveat lector|Caveat lector]].