// Globalized LiveDiffLink.
// For attribution: ]
$(function() {
// Don't do anything unless we're on a History page.
if (mw.config.get('wgAction') !== 'history') return;
var sc = mw.config.get('wgScript');
var pn = mw.config.get('wgPageName');
var getlink = function(diff, oldid) {
return (new mw.Uri(sc)).extend({
title: pn,
diff: diff,
oldid: oldid,
unhide: 1
}).toString();
};
// Grab the Compare buttons, create an empty link after each, and grab the empty links
$('.mw-history-compareselectedversions-button').after(
$('<a>').attr({
class: 'LDL-diffurl'
}).css({
border: '1px dashed #999999',
padding: '2px 4px'
})
);
$('.LDL-diffurl').before($('<b>').text(' → '));
// Event listener for copy buttons.
$('#pagehistory').on('click', '.LDL-copybuttons', function(e) {
e.preventDefault();
navigator.clipboard.writeText($($('.LDL-diffurl')).text());
mw.notify('Added diff wikilink to clipboard.', {
title: 'Copied!',
tag: 'livedifflinknotification',
});
});
// Set the Click event function for radio buttons
$('#pagehistory').on('click', ':radio, :radio', function() {
// Clear existing revision size links
$('.LDL-difflinks').remove();
// Grab the revision selection, place in appropriate var
var diff = $(':checked').val();
var oldid = $(':checked').val();
var link = getlink(diff, oldid);
// Update the main diff link URL, text, & tooltip
$('.LDL-diffurl').attr({
href: link,
title: link
}).text(']');
// Add diff link before revision sizes
$(':checked, :checked').closest('li').find('.history-size').before(
$('<span>').attr({
'class': 'LDL-difflinks'
}).append(
'(',
$('<a>').attr({
href: link,
title: link
}).text('diff'),
') ',
$('<button>').attr({
class: 'LDL-copybuttons'
}).css({
padding: '1px',
'font-size': '0.75em'
}).text('Copy'),
' . . '
)
);
});
$(':radio, :radio').not('').first().trigger('click');
});