User:NguoiDungKhongDinhDanh/LiveDiffLink.js

// Globalized LiveDiffLink. // For attribution: User:Equazcion/LiveDiffLink.js

$(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( $('').attr({			class: 'LDL-diffurl'		}).css({			border: '1px dashed #999999',			padding: '2px 4px'		}) );       	$('.LDL-diffurl').before($('').text(' → '));	// Event listener for copy buttons.	$('#pagehistory').on('click', '.LDL-copybuttons', function(e) { e.preventDefault; navigator.clipboard.writeText($($('.LDL-diffurl')[0]).text); mw.notify('Added diff wikilink to clipboard.', {			title: 'Copied!',			tag: 'livedifflinknotification',		}); });	// Set the Click event function for radio buttons	$('#pagehistory').on('click', '[name="diff"]:radio, [name="oldid"]:radio', function { // Clear existing revision size links $('.LDL-difflinks').remove;

// Grab the revision selection, place in appropriate var var diff = $('[name="diff"]:checked').val; var oldid = $('[name="oldid"]:checked').val; var link = getlink(diff, oldid);

// Update the main diff link URL, text, & tooltip $('.LDL-diffurl').attr({			href: link,			title: link		}).text('Special:Diff/' + oldid + '/' + diff + '');

// Add diff link before revision sizes $('[name="diff"]:checked, [name="oldid"]:checked').closest('li').find('.history-size').before(			$(' ').attr({ 'class': 'LDL-difflinks' }).append( '(',				$('').attr({ href: link, title: link }).text('diff'),				') ', $(' ').attr({					class: 'LDL-copybuttons'				}).css({					padding: '1px',					'font-size': '0.75em'				}).text('Copy'), ' . . '			)		);	});	$('[name="diff"]:radio, [name="oldid"]:radio').not('[disabled]').first.trigger('click'); });