User:DannyS712/Pretty rights log.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. |
This user script seems to have a documentation page at User:DannyS712/Pretty rights log. |
// Install with:
// <code><nowiki> {{subst:Iusc|User:DannyS712/Pretty righs log.js}} </nowiki></code>
// or with
// <code><nowiki> importScript( 'User:DannyS712/Pretty righs log' ); // Backlink: [[User:DannyS712/Pretty righs log.js]] </nowiki></code>
//
// If forking this script, please note my contributions / give me credit
//<nowiki>
$(function (){
mw.loader.using( 'mediawiki.util', function () {
$(document).ready( function () {
if ( mw.config.get('wgCanonicalNamespace') === 'Special' && (mw.config.get('wgCanonicalSpecialPageName') === 'Log' || mw.config.get('wgCanonicalSpecialPageName') === 'Userrights') ){
$('[data-mw-logaction="rights/rights"]').each( function() {
this.innerHTML = this.innerHTML.replace( /(changed group membership for <a.*?>.*?<\/a>) (.*?)( <span class="comment">|\s+\(<a class="mw-thanks-thank-link")/, replacer );
});
}
} );
} );
function replacer( match, p1, p2, p3, offset, string ){
console.log( p2 );
var np2 = filter( p2 );
return( p1 + ': ' + np2 + p3 );
}
function filter( p2 ){
var split = p2.split( " to " );
from = split[0].replace( /^from /, '' ).replace( /, (until|\d)/g, ',_$1' ).replace( / and /, ', ');
to = split[1].replace( /, (until|\d)/g, ',_$1' ).replace( / and /, ', ');
var fromA = from.split( ', ' );
var toA = to.split( ', ' );
var fromAF = [];
var toAF = [];
for ( var iii = 0; iii < fromA.length; iii++ ){
if ( toA.indexOf( fromA[iii] ) === -1 ){
fromAF.push( fromA[iii] );
}
}
for ( var jjj = 0; jjj < toA.length; jjj++ ){
if ( fromA.indexOf( toA[jjj] ) === -1 ){
toAF.push( toA[jjj] );
}
}
var removed = fromAF.join( ', ' );
if ( removed === '' ){
removed = '(none)';
}
var added = toAF.join( ', ' );
if ( added === '' ){
added = '(none)';
}
var change = 'removed ' + removed + ', added ' + added;
change = change.replace( /_/g, ' ' );
console.log( split, from, to, fromA, toA, fromAF, toAF, removed, added, change );
return change;
}
});
//</nowiki>