Jump to content

User:Fred Gandt/showSpecialDiffLink.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.
$( document ).ready( () => {
	"use strict";
	const DIFF = mw.config.get( "wgDiffNewId" ),
		OLDID = mw.config.get( "wgDiffOldId" );
	if ( DIFF && OLDID ) {
		const DT = document.querySelector( "tr.diff-title" );
		if ( DT ) {
			const OLD_DATE = document.querySelector( "#mw-diff-otitle1 a" ).textContent.replace( /^(?:latest )?revision as of /i, "" ),
				NEW_DATE = document.querySelector( "#mw-diff-ntitle1 a" ).textContent.replace( /^(?:latest )?revision as of /i, "" ),
				CODE = document.createElement( "code" ),
				TR = document.createElement( "tr" ),
				TD = document.createElement( "td" );
			TD.setAttribute( "colspan", "4" );
			TD.classList.add( "center" );
			CODE.innerHTML = `[[Special:Diff/${OLDID}/${DIFF}|${mw.config.get( "wgTitle" )}: ${OLD_DATE}${NEW_DATE}]]`;
			TD.append( CODE );
			TR.append( TD );
			DT.after( TR );
		}
	}
} );