User:Garzfoth/Scripts/CompareLink.js

// Migrated from https://en.wikipedia.org/wiki/User:Garzfoth/common.js on 2021-05-04

// Notes:

// • Variable naming: I believe I stripped the dollar sign prefixes for readability. IIRC they were only in use as an informal way to denote jQuery variables, and I believe they were being misused for sloppy variable declaration as well...

// • Major changes: Wrapped mw.util.addCSS() inside mw.loader expression

// FROM: https://en.wikipedia.org/wiki/User:Mattflaschen/Compare_link.js

// SINCE: 7/21/2015

/**

* Convert the "Compare selected versions" button to a link

* (Based on w:en:User:Superm401/Compare_link.js)

* @source: http://www.mediawiki.org/wiki/Snippets/Compare_link

* @rev: 2

* @see: bugzilla:16165

* Copyright 2006-2013 Matthew Flaschen (User:Superm401), User:Helder.wiki

*/

function fixCompareSelectedVersionsButton() {

var histForm = $('#mw-history-compare');

var diffList = $('#pagehistory');

var buttons = histForm.find('input.historysubmit');

if (buttons.length === 0) {

// Only one version, so do nothing

return;

}

var buttonText = buttons.remove().first().val();

var compareLink = $('', {

'class': 'compare-link',

'text': buttonText

});

histForm.prepend(compareLink).append(compareLink.clone());

var updateCompare = function (){

var radio = histForm.find('input[type=radio]:checked');

var genLink = mw.config.get('wgScript') + '?title=' + mw.util.wikiUrlencode(mw.config.get('wgPageName')) + '&diff=' + radio.eq(0).val() + '&oldid=' + radio.eq(1).val();

$('.compare-link').each(function () {

$(this).attr('href', genLink);

});

};

updateCompare();

diffList.change(updateCompare);

}

if (mw.config.get('wgAction') === 'history') {

$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( function () {

mw.util.addCSS('.compare-link { border-radius:5px; color:black; text-decoration:none; border-width:1px 2px 2px 1px; border-style:solid; border-color:#DDDDDD #BBBBBB #BBBBBB #DDDDDD; padding:0.2em 1em; background-color:#EEEEEE; white-space:nowrap; } .compare-link:active{ border-width:0.1em; margin:0.1em; }');

});

$(fixCompareSelectedVersionsButton);

}