/*
==addLink==
*/
function addLink(text, id, href, before) {
li = document.createElement('li');
a = document.createElement('a');
aHref = document.createAttribute('href');
aHref.value = href;
a.setAttributeNode(aHref);
a.appendChild(document.createTextNode(text));
liId = document.createAttribute('href');
liId.value = id;
li.setAttributeNode(liId);
li.appendChild(a);
aj = document.getElementById(before);
aj.parentNode.insertBefore(li, aj);
}
/*
== showEdit ==
*/
var data;
var link;
var title;
var vis = true;
function rc() {
if (window.location.href.indexOf('Recentchanges') == -1) return;
container = document.createElement('div');
container.setAttribute('style', 'padding: 0; margin: 0; width: 100%; border: 1px solid black; overflow: auto;');
nav = document.createElement('div');
nav.setAttribute('style', 'margin: 2px; padding: 0 2px; background-color: #BBB; font-size: 90%;');
//nav.appendChild(document.createTextNode('Navigation'));
nav.innerHTML = '<strong>ShowEdit:</strong> [<a href="javascript:void(open());">Open</a>] [<a href="javascript:void(popup());">Popup</a>] [<a href="javascript:void(revert());">Revert</a>] [<a href="javascript:void(toggleView());" id="toggleView">Hide</a>] - ';
title = document.createElement('strong');
nav.appendChild(title);
container.appendChild(nav);
data = document.createElement('div');
data.appendChild(document.createElement('div'));
container.appendChild(data);
a = document.evaluate("div[@class='rcoptions']", document.getElementById('bodyContent'),null,9,null).singleNodeValue.nextSibling;
a.parentNode.insertBefore(container, a);
nl = document.evaluate("//a[text()='diff']", document.getElementById('bodyContent'),null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
for (var i=0 ; i < nl.snapshotLength; i++) {
n = nl.snapshotItem(i);
t1 = document.createTextNode('; ');
n.parentNode.insertBefore(t1, n);
a = document.createElement('a');
a.setAttribute('href', 'javascript:void(showEdit("' + n.getAttribute('href') + '"));');
a.appendChild(document.createTextNode('show'));
t1.parentNode.insertBefore(a, t1)
}
}
function showEdit(url) {
link = url;
var x = new XMLHttpRequest();
x.overrideMimeType('text/xml')
x.open('GET', url, true);
x.onreadystatechange = function () {
if (x.readyState == 4) {
d = document.importNode(x.responseXML, true);
t = d.getElementsByTagName('table').item(0)
title.textContent = d.getElementsByTagName('title').item(0).textContent;
data.replaceChild(t, data.firstChild)
a = document.getElementById('differences-prevlink');
a.setAttribute('href', 'javascript:void(showEdit("' + a.getAttribute('href') + '"));');
a = document.getElementById('differences-nextlink');
if (a) a.setAttribute('href', 'javascript:void(showEdit("' + a.getAttribute('href') + '"));');
}
}
x.send(null)
}
function open() {
window.location.href = link;
}
function toggleView() {
a = document.getElementById('toggleView');
if (vis) {
a.textContent = 'Show';
data.style.display = 'none';
} else {
a.textContent = 'Hide';
data.style.display = 'block';
}
vis = !vis;
}
function popup() {
void(window.open(link, "ShowEdit - " + link, 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width=640,height=480'));
}
/*
=== Revert ===
*/
var oi = new RegExp('oldid\=([0-9]*)');
var tt = new RegExp('title\=([A-Za-z0-9_%:/]*)');
function revert() {
var x = new XMLHttpRequest();
x.overrideMimeType('text/xml')
x.open('GET', '/w/index.php?action=edit&' + oi.exec(link)[0] + '&' + tt.exec(link)[0], true);
x.onreadystatechange = function () {
if (x.readyState == 4) {
inputs = x.responseXML.getElementsByTagName('input');
textarea = x.responseXML.getElementsByTagName('textarea')[0];
postdata = 'wpSave=Save%20Page&wpSummary=Revert:%20Devandalized%20using%20%5B%5BUser%3ABryan_Tong_Minh/ShowEdit%7CShowEdit%5D%5D%20%28alpha%29&wpTextbox1=' + encodeURIComponent(textarea.textContent);
for (i=0; i<inputs.length; i++) {
if ((inputs[i].name.substr(0, 2) == 'wp') && (inputs[i].type != 'checkbox')) {
if (inputs[i].type != 'submit' && inputs[i].name != 'wpSummary')
postdata = postdata + "&" + inputs[i].name + "=" + encodeURIComponent(inputs[i].value);
}
}
var x2 = new XMLHttpRequest();
x2.open('POST', '/w/index.php?action=submit&' + tt.exec(link)[0], true);
x2.setRequestHeader('Referer', 'http://en.wikipedia.org/w/index.php?action=edit&' + oi.exec(link)[0] + '&' + tt.exec(link)[0]);
x2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');//'multipart/form-data; boundary=' + boundary);
x2.onreadystatechange = function () { if (x2.readyState == 4) { data.textContent = 'Devandalized'; }};
x2.send(postdata);
data.innerHTML = '<pre>' + postdata + '</pre>';
}
}
x.send(null);
}
/*
== Window Load ==
*/
window.onload = function () {
/* Adds a 'mijn volglijst' link in personal toolbar */
addLink('mijn volglijst', 'user-follow-nl', 'http://nl.wikipedia.org/wiki/Special:Watchlist', 'pt-mycontris');
addLink('Middle-earth', 'user-me', 'http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Middle-earth', 'pt-userpage');
rc();
}