Jump to content

User:Nardog/SymmetricalChanges.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nardog (talk | contribs) at 14:08, 7 July 2022 (suppress portlet additions). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(mw.config.exists('wgDiffNewId') || mw.config.get('wgAction') !== 'view' ||
[-1, 14].includes(mw.config.get('wgNamespaceNumber'))) &&
$(function symmetricalChanges() {
	if (!document.getElementById('p-tb')) return;
	mw.hook('wikipage.diff').add($diff => {
		let $rows = $diff
			.find('.diff-deletedline:not(.diff-empty) ~ .diff-addedline:not(.diff-empty)')
			.parent();
		if (!$rows.length) return;
		$rows.addClass('symmetricalchange');
		if (document.getElementById('t-symmetricalchanges')) return;
		mw.loader.using('mediawiki.util', () => {
			mw.util.addPortletLink('p-tb', '#', 'Toggle symmetrical changes', 't-symmetricalchanges').firstElementChild.addEventListener('click', e => {
				e.preventDefault();
				document.body.classList.toggle('symmetricalchanges-enabled');
			});
		});
	});
});