Jump to content

User:Nardog/CatChangeLinker.js

From Wikipedia, the free encyclopedia
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.get('wgAction') !== 'history' &&
mw.loader.using('mediawiki.util', function catChangeLinker() {
	mw.hook('wikipage.content').add($content => {
		$content.find('li.mw-changeslist-src-mw-categorize').each(function () {
			let titleLink = this.querySelector('.comment > a');
			let title = titleLink ? titleLink.textContent : '';
			let $diff = $(this.querySelector('.mw-changeslist-links > span')).wrapInner(
				$('<a>').attr({
					class: 'mw-changeslist-diff',
					href: mw.util.getUrl(title, {
						diff: 'prev',
						oldid: this.dataset.mwRevid
					}),
					title: title
				})
			);
			if (!title) return;
			$diff.next().wrapInner(
				$('<a>').attr({
					class: 'mw-changeslist-history',
					href: mw.util.getUrl(title, { action: 'history' }),
					title: title
				})
			);
		});
	});
});