User:Vf/monobook.js

//

function main { addRevert; addHistoryEdit; setEditForm; };

function addHistoryEdit { var pageHistory = document.getElementById('pagehistory'); if (!pageHistory) return;

var links = document.evaluate("//li[input[@type='radio']]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); var curLink; var xp_name1 = document.evaluate("//li[input[@type='radio']][1]/descendant::a[last]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); if (!xp_name1) return; var name1 = xp_name1.singleNodeValue; var i; var curLink; for (i = 0; i < links.snapshotLength; i++) { var n = i + 1; curLink = links.snapshotItem(i); var xp_name2 = document.evaluate("//li[input[@type='radio']][" + n + "]/descendant::input/following::a[2]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); if (!xp_name2) return; var xp_link = document.evaluate("//li[input[@type='radio']][" + n + "]/descendant::input/following::a[1]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); if (!xp_link) return; var name2 = xp_name2.singleNodeValue; var link = xp_link.singleNodeValue; if (i == 0) { curLink.innerHTML = '(edit) ' + curLink.innerHTML; } else { curLink.innerHTML = '( edit ) ' + curLink.innerHTML; } } };

function addRevert { if(!queryString("diff")) return; var xpath = "//html/body/div/div[2]/table/tbody/tr[1]/td[1]/strong/a"; if (!document.evaluate) return; var result = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null); var xname1 = "/html/body/div/div[2]/table[1]/tbody/tr[1]/td[1]/a[1]" var name1 = document.evaluate(xname1, document, null, XPathResult.ANY_TYPE, null).iterateNext.textContent; var xname2 = "/html/body/div/div[2]/table[1]/tbody/tr[1]/td[2]/a[1]" var name2 = document.evaluate(xname2, document, null, XPathResult.ANY_TYPE, null).iterateNext.textContent;

var link = result.iterateNext; var revertLink = document.createElement("a"); var summaryText = "Reverted edit of " + name2 + " to previous one by " + name1

revertLink.textContent = "Auto-Revert"; revertLink.href = link.href + "&action=edit&setsubmit=wpSave&setsummary=" + summaryText + "&setwatch=0"; var space = insertAfter(link.parentNode, document.createTextNode(" ("), link);	insertAfter(link.parentNode, revertLink, space);	insertAfter(link.parentNode, document.createTextNode(")"), revertLink); };

function insertAfter(parent, node, referenceNode) { if(referenceNode.nextSibling) { return parent.insertBefore(node, referenceNode.nextSibling); } else { return parent.appendChild(node); } }

function setEditForm { var editform = document.getElementById("editform"); if (!editform) return; var summaryText = queryString('setsummary'); if (summaryText) { var summary = document.getElementsByName("wpSummary")[0]; if (summary) summary.value = summaryText; }	var setMinor = queryString('setminor'); if (setMinor) { var minor = document.getElementById("wpMinoredit"); if (minor) minor.checked = (setMinor == '1'); }	var setWatch = queryString('setwatch'); if (setWatch) { var watch = document.getElementById("wpWatchthis"); if (watch) watch.checked = (setWatch == '1'); }

var setSubmit = queryString('setsubmit'); if (setSubmit) { var btn = document.getElementById(setSubmit); if (document.getElementById("editform") && btn) { btn.textContent += " (auto clicking...)"; btn.click; }	} };

function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { }	}	return null; };

window.addEventListener("load", main, false);

//