Jump to content

User:Maxim's JS test account/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Maxim's JS test account (talk | contribs) at 14:17, 14 October 2007. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
addOnloadHook(function () {
	var url = unescape(document.location.toString()).replace('_', ' ');

	if (url.indexOf('&diff=') > -1) {
		var otitle1 = document.getElementById('mw-diff-otitle1');

		if (otitle1) {
			var oldlink = otitle1.getElementsByTagName('a')[0];

			if (oldlink) {
				var oldid = oldlink.href.substring(oldlink.href.indexOf('oldid=') + 6)
				var title;

				if (url.indexOf('http://en.wikipedia.org/wiki/') >= 0) {
					title = url.substring(url.indexOf('http://en.wikipedia.org/wiki/') + 29);
					if (title.indexOf('?') >= 0) title = title.substring(0, title.indexOf('?'));

				} else if (url.indexOf('title=') >= 0) {
					title = url.substring(url.indexOf('title=') + 6);
					if (title.indexOf('&') >= 0) title = title.substring(0, title.indexOf('&'));
				}

				if (title) {
					var rvSpan = document.createElement('span');
					rvSpan.id = 'mw-diff-orevertto';
					rvSpan.style.fontWeight = 'bold';
					otitle1.insertBefore(rvSpan, otitle1.lastChild.nextSibling);

					var rvLink = document.createElement('a');
					rvLink.href = 'http://en.wikipedia.org/w/index.php?title=' + title 
						+ '&action=edit&oldid=' + oldid + '&script=rv';
					rvLink.innerHTML = 'revert-to';
					rvLink.title = 'revert';
					rvLink.accessKey = 'r';
					rvSpan.insertBefore(rvLink, rvSpan.lastChild);
					rvSpan.innerHTML = ' [' + rvSpan.innerHTML + ']';
				}
			}

			var prevLink = document.getElementById('differences-prevlink');
			if (prevLink) prevLink.accessKey = 'z';

			var nextLink = document.getElementById('differences-nextlink');
			if (nextLink) nextLink.accessKey = 'x';
		}
	}

	if (url.indexOf('&script=rv') > -1) {
		var wpSummary = document.getElementById('wpSummary');

		if (wpSummary) {
			wpSummary.value = 'revert';
			var editForm = document.getElementById('editform');
			if (editForm) editForm.submit();
		}
	}

	if (url.indexOf('Special:Recentchanges') > -1) {
		var rcOptionsQuery = document.evaluate('//div[@class="rcoptions"]',
			document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

		if (rcOptionsQuery.snapshotItem(0)) {
			var rcOptions = rcOptionsQuery.snapshotItem(0);

			if (url.indexOf('&script=rcopenall') > -1) {
				var newChangesFrom = rcOptions.getElementsByTagName('a')[14];

				if (newChangesFrom) {
					var newChangesFromHref = newChangesFrom.href;

					var openAllDiv = document.createElement('div');
					openAllDiv.id = 'mw-openall';
					openAllDiv.style.fontWeight = 'bold';
					rcOptions.insertBefore(openAllDiv, rcOptions.lastChild.nextSibling);

					var openAllLink = document.createElement('a');
					openAllLink.href = newChangesFromHref + '&namespace=0&script=rcopenall';
					openAllLink.innerHTML = 'Open next batch in tabs';
					openAllLink.accessKey = 'q';
					openAllDiv.insertBefore(openAllLink, openAllDiv.lastChild);
				}

				var rcListQuery = document.evaluate('//ul[@class="special"]',
					document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

				if (rcListQuery.snapshotItem(0)) {
					var rcList = rcListQuery.snapshotItem(0);

					for (var i = 0; i < rcList.childNodes.length; i++) {
						var rcLink = rcList.childNodes[i].childNodes[1];
						if (rcLink) window.open(rcLink.href);
					}
				}

			} else {
				var openAllLink = document.createElement('a');
				openAllLink.href = 'http://en.wikipedia.org/wiki/Special:Recentchanges?limit=10&namespace=0&hideliu=1&script=rcopenall';
				openAllLink.innerHTML = 'Open next batch in tabs';
				rcOptions.insertBefore(openAllLink, rcOptions.lastChild.nextSibling);
			}
		}
	}
});