Gebruiker:Zanaq/Zeusmode/revert.js
Van Wikipedia
Hulp bij het instellen van uw voorkeuren Let op! Nadat u de veranderingen heeft opgeslagen, moet u de cache van uw browser nog legen om ze daadwerkelijk te zien.
Mozilla (incl. Firefox) | Ctrl+Shift+R |
Internet Explorer | Ctrl+F5 |
Opera | F5 |
Safari | Cmd+R |
Konqueror | F5 |
//<pre><nowiki> //------------------------------------------------------------- // Provide revert capability from history view, diffs and user-contributions // From [[user:Zanaq/Zeusmode]] //------------------------------------------------------------- function placeOldVersion(oldid, timestamp, editor) { pov_oldid=oldid; pov_timestamp=timestamp; pov_editor=editor; xmlhttp = HTTPClient(); if (!xmlhttp) return; var thetitle=document.title.slice(0, String(document.title).indexOf(" - ")); document.getElementById('bodyContent').innerHTML=txtPlaceOld + '<br>'; wpComment = prompt(txtComment, ''); if (wpComment == null) return; wpComment = (wpComment == '') ? '' : (' - ' + wpComment); wpComment = txtPlace.replace(/\$1/g, oldid).replace(/\$2/g, timestamp).replace(/\$3/g, editor) + wpComment; SavePage(thetitle + '&oldid='+oldid, '$1', wpComment, 1, wgCurRevisionId); } function addPlaceLinksHist() { versions=document.getElementById('bodyContent').getElementsByTagName('li'); //alert('ok'); startFrom = (versions[0].getElementsByTagName('a')[0].textContent == txtDiffPrevious) ? 1 : 0; for (i=startFrom;i<versions.length;i++) { versionLink=versions[i].getElementsByTagName('a')[2]; oldid=versionLink.href.substring(versionLink.href.indexOf('&oldid=')+7); timestamp=versionLink.textContent; editor=versions[i].getElementsByTagName('a')[3].textContent; var placeLink = document.createElement('span'); placeLink.innerHTML = ' [<a href=\'JavaScript:placeOldVersion("' + oldid + '","'+ timestamp + '","' + editor + '");\'>' + txtPlaceLink + '</a>]'; versions[i].appendChild(placeLink); } } function addPlaceLinksDiff() { l = document.getElementById('bodyContent').getElementsByTagName('tr'); for (i = 0;i<2;i++) { a = l[0].getElementsByTagName('td')[i].getElementsByTagName('a'); if (a[0].href.indexOf('&oldid=') > 0) { timestamp=a[0].textContent.substring(lenRevisionOf); editor=a[2+i].textContent; oldid=a[0].href.substring(a[0].href.indexOf('&oldid=')+7); l[0].getElementsByTagName('td')[i].innerHTML += ' [<a href=\'JavaScript:placeOldVersion("' + oldid + '","'+ timestamp + '","' + editor + '");\'><b>' + txtPlaceLink + '</b></a>]'; } } } if (document.location.href.indexOf('&action=history') != -1) window.addEventListener ('DOMContentLoaded',addPlaceLinksHist,false); if (document.location.href.indexOf('&diff=') != -1) window.addEventListener ('DOMContentLoaded',addPlaceLinksDiff,false); // ----------------------------------------------------------------------------- // Hide users and patrolled edits by default // ----------------------------------------------------------------------------- function recentchangeslink() { var a=document.getElementById('p-navigation') a=a.getElementsByTagName('a'); a[3].href=a[3].href + '?hidepatrolled=1&hideliu=1&limit=500'; } if (document.location.href.indexOf(':Recentchanges') == -1) window.addEventListener("DOMContentLoaded", recentchangeslink, false); // ----------------------------------------------------------------------------- // Sam Hocevar's nice Revert functions // taken from // ----------------------------------------------------------------------------- // God-like Monobook skin // (c) 2005 Sam Hocevar <sam@zoy.org> // $Id: godmode-light.js 980 2005-11-12 01:51:51Z sam $ // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- var gml_vandal, gml_editor, gml_url, gml_curid; function PerformRevert(url, vandal, curid) { gml_url= url; gml_vandal=vandal; gml_curid = curid; document.getElementById('bodyContent').innerHTML = txtPleaseWait + gml_vandal + '...'; xmlhttp = HTTPClient(); if (!xmlhttp) return; document.getElementById('bodyContent').innerHTML += '<br />' + txtGetHist + ' (' + gml_url + '&action=history&limit=50):'; xmlhttp.open("GET", "/w/index.php?title="+gml_url + '&action=history&limit=50', true); xmlhttp.onreadystatechange = RevertStepTwo; xmlhttp.send(null); //alert(gml_url + '&action=history&limit=50'); } function RevertStepTwo() { if (xmlhttp.readyState != 4) return document.getElementById('bodyContent').innerHTML+=txtOk + '<br>'; if (gml_curid == 0) { gml_curid=xmlhttp.responseText.indexOf('var wgCurRevisionId = "'); gml_curid=xmlhttp.responseText.substring(gml_curid + 23); gml_curid=gml_curid.substring(0, gml_curid.indexOf('";')); } var l; var oldid; document.getElementById('bodyContent').innerHTML+= txtParseHist ; // Get the vandal and new editor names gml_vandal = gml_vandal.replace(/_/g, ' '); gml_editor = ''; doc = XMLParse(xmlhttp.responseText); l = doc.getElementById('pagehistory').getElementsByTagName('li'); //l = doc.selectSingleNode('//*[@id="pagehistory"]').getElementsByTagName('li'); for (i = 0; i < l.length; i++) { var name = l[i].getElementsByTagName('span')[0].getElementsByTagName('a')[0].innerHTML.replace(/_/g, ' '); if (i == 0 && name != gml_vandal) { document.getElementById('bodyContent').innerHTML += '<br />' + txtLastErr.replace(/\$1/g, name).replace(/\$2/g, gml_vandal); return; } else if (i > 0 && name != gml_vandal) { oldid = l[i].getElementsByTagName('input')[0].value; gml_editor = name; break; } } if (gml_editor == '') { document.getElementById('bodyContent').innerHTML += '<br />' + txtOnlyErr.replace(/\$1/g, gml_vandal); return; } document.getElementById('bodyContent').innerHTML+=txtOk + '<br>'; wpComment = prompt(txtComment, ''); if (wpComment == null) return; wpComment = (wpComment == '') ? '' : (' - ' + wpComment); wpComment = revertpage.replace(/\$1/g, gml_editor).replace(/\$2/g, gml_vandal) + wpComment; SavePage(gml_url + '&oldid='+oldid, '$1', wpComment, 1, gml_curid ); /* xmlhttp = HTTPClient(); if (!xmlhttp) return; document.getElementById('bodyContent').innerHTML += '<br />Getting article edit form (GET' + gml_url + '&action=edit&oldid=' + oldid + ')...'; xmlhttp.open('GET', gml_url + '&action=edit&oldid=' + oldid, true); xmlhttp.onreadystatechange = RevertStepThree; xmlhttp.send(null); */ } // ----------------------------------------------------------------------------- // Add revert buttons to the page // ----------------------------------------------------------------------------- function AddRevertButtons() { var l, article = '', vandal; // Add 'revert' links to a diff page l = document.getElementById('bodyContent').getElementsByTagName('td'); for (i = 0; i < l.length; i++) { if (l[i].className == 'diff-otitle') { article = l[i].getElementsByTagName('a')[0].href.split('&')[0].replace(/[^\/]*\/\/[^\/]*/, ''); } else if (l[i].className == 'diff-ntitle') { var toplink = l[i].getElementsByTagName('a')[0].href; vandal = l[i].getElementsByTagName('a')[3].textContent.replace(/ /g, '_'); var t = l[i].innerHTML n = t.indexOf('</a>) <br') + t.indexOf('</A>) <BR') + 1; // XXX: WOW HACK!!!! if (n >= 0 && article != '' && toplink.indexOf('oldid=') == -1) { a=document.location.href.indexOf('?title=')+7; b=document.location.href.indexOf('&diff='); articlename=document.location.href.substring(a,b); //alert(articlename); l[i].innerHTML = t.substring(0, n + 5) + ' <strong>[<a href=Javascript:PerformRevert("' + articlename + '","' + vandal + '","' + wgCurRevisionId + '")>' + rollbacklink + '</a>]</strong> ' + t.substring(n + 5, t.length); } } } // Add 'revert' links to a contributions page if ( (location.href.indexOf(':Contributions') != -1) ) { var c = document.getElementById('contentSub'); var a = c.getElementsByTagName('a'); if (a.length == 3) { vandal=c.getElementsByTagName('a')[0].href.substring(c.getElementsByTagName('a')[0].href.indexOf(':',6)+1); } else { vandal=c.getElementsByTagName('a')[0].innerHTML; // alert(vandal); } l = document.getElementById('bodyContent').getElementsByTagName('li'); for (i = 0; i < l.length; i++) { var t = l[i].innerHTML // If we are already a sysop on this wiki, abort if (t.indexOf('>' + rollbacklink + '</a>]') != -1) break; //if (t.indexOf('&diff=0') != -1) { if (t.indexOf('<strong> (') != -1) { article = l[i].getElementsByTagName('a')[0].href.split('&')[0].replace(/[^\/]*\/\/[^\/]*/, ''); article=article.substring(19); l[i].innerHTML += ' [<a href=Javascript:PerformRevert("' + article + '","' + vandal + '","' + wgCurRevisionId + '")>' + rollbacklink + '</a>]'; } } } } // ----------------------------------------------------------------------------- // Modify the page once it is loaded // ----------------------------------------------------------------------------- if (isSysop != true) { if (window.addEventListener) { window.addEventListener("DOMContentLoaded", AddRevertButtons, false); } else if (window.attachEvent) { window.attachEvent("DOMContentLoaded", AddRevertButtons); } } //</nowiki></pre>