User:RyanB88/twinklediff.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:RyanB88/twinklediff. |
//Status.debugLevel = 1;
/**
* Last diff tab, show difference between last revision and the one before
*/
function lastdiff()
{
if( wgNamespaceNumber >= 0 ) {
var query = {
'title': wgPageName,
'diff': 'cur',
'oldid': 'prev'
};
var l = mw.util.addPortletLink('p-cactions', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), 'last', '' );
l.lastChild.title="Show most recent diff";
}
}
$(lastdiff);
var dataXML;
var ntitle;
var me;
function diffSincePrevUserButton() {
if( wgNamespaceNumber < 0 ) {
return;
}
if( !QueryString.exists( 'diff' ) ) {
// Not diff page
return;
}
ntitle = getElementsByClassName( document.getElementById('bodyContent'), 'td' , 'diff-ntitle' )[0];
if( !ntitle ) {
// Nothing to see here, move along...
return;
}
var l = mw.util.addPortletLink('p-cactions', "javascript:diffSincePrevUserInit(false);", 'since', '' );
l.lastChild.title="Show difference between last diff and the revision made by previous user";
var l = mw.util.addPortletLink('p-cactions', "javascript:diffSincePrevUserInit(true);", 'since mine', '' );
l.lastChild.title="Show difference between last diff and my last revision";
}
$(diffSincePrevUserButton);
function diffSincePrevUserInit(me) {
try {
Status.init( document.getElementById('bodyContent') );
var rev = wgCurRevisionId;
var user;
if( me ) {
Status.debug( '"me" is choosen' );
user = wgUserName;
} else if( vandal ) {
Status.debug( 'vandal ' + vandal + ' already defined' );
// twinklefluff or simlar have already parsed this thingi
user = vandal;
} else {
Status.debug( 'testing 3:rd element' );
user = ntitle.getElementsByTagName('a')[3].firstChild.nodeValue;
Status.debug( '3:rd element: ' + user );
if( user == 'Current revision' ) {
Status.debug( 'testing 6:th element' );
user = ntitle.getElementsByTagName('a')[6].firstChild.nodeValue;
Status.debug( '6:th element: ' + user );
}
}
diffSincePrevUser( user, rev, me );
} catch(e) {
if(e.what){
alert(e.what())
} else {
alert(e);
}
}
}
function diffSincePrevUser( user, rev, pMe ) {
me = pMe;
dataXML = sajax_init_object();
dataXML.overrideMimeType('text/xml');
var query = {
'prop': 'revisions',
'format': 'xml',
'action': 'query',
'titles': wgPageName,
'rvlimit': 50,
'rvprop': 'user',
'rvendid': wgCurRevisionId
};
Status.debug( "Query string:" + QueryString.create( query ), 1 );
Status.status( 'Querying revisions' );
dataXML.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?" + QueryString.create( query ) , true );
dataXML.onreadystatechange = function() {
if ( dataXML.readyState != 4 ){
Status.progress('.');
return;
}
if( dataXML.status != 200 ){
Status.error('Bad status , bailing out');
return;
}
Status.progress(' Done.');
var doc = dataXML.responseXML.documentElement;
var revisions = doc.getElementsByTagName('rev');
Status.debug( 'length: ' + revisions.length, 1 );
var curNode = revisions[0];
Status.debug( 'curNode: ' + curNode, 1 );
Status.debug( 'user: ' + user, 1 );
Status.debug( "rev: " + rev, 1 );
var last = null;
Status.status( 'Finding last revision made by user...' );
while( curNode != null ) {
Status.debug( 'curNode: ' + curNode.getAttribute( 'revid' ), 1 );
if( me ) {
if( curNode.getAttribute( 'revid' ) < rev && curNode.getAttribute( 'user' ) == user ) {
Status.debug( "found rev and user", 1 );
last = curNode.getAttribute( 'revid' );
break;
}
} else {
if( curNode.getAttribute( 'revid' ) < rev && curNode.getAttribute( 'user' ) != user ) {
Status.debug( "found rev and user", 1 );
last = curNode.getAttribute( 'revid' );
break;
}
}
curNode = curNode.nextSibling;
}
if( last == null ) {
Status.error( [ 'No previos revision found, or ', user , ' is only contributor ' ] );
return;
}
var query = {
'title': wgPageName,
'oldid': last,
'diff': rev
};
window.location = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query );
};
dataXML.send( null );
}