Jump to content

User:JJPMaster/diff.js

From Wikibooks, open books for an open world
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
  • Konqueror: simply click the Reload button, or press F5;
  • Opera users may need to completely clear their cache in Tools→Preferences.
if (mw.config.get("wgArticleId") > 0 && mw.config.get("wgNamespaceNumber") >= 0)
	mw.util.addPortletLink('luna-actions', mw.util.getUrl(mw.config.get('wgPageName'), { diff: 'curr', oldid: 'prev' }), 'Last', 'luna-last', 'Show most recent diff');
if (mw.config.get('wgDiffNewId')) {
	mw.util.addPortletLink('luna-actions', mw.util.getUrl(mw.config.get('wgPageName'), { diff: 'cur', oldid: mw.config.get('wgDiffNewId') }), 'Current', 'luna-current', 'Show difference to current revision');
	mw.util.addPortletLink('luna-actions', '#', 'Since', 'luna-since', 'Show difference between last diff and the revision made by previous user');
	mw.util.addPortletLink('luna-actions', '#', 'Since mine', 'luna-sincemine', 'Show difference between last diff and my last revision');
}
$("#luna-since").click(() => goToDiffLink($('#mw-diff-ntitle2').find('a').first().find('bdi').text()));
$("#luna-sincemine").click(() => goToDiffLink(mw.config.get("wgUserName")));
async function revisionQuery(user) {
	var params = {
		prop: 'revisions',
		action: 'query',
		titles: mw.config.get('wgPageName'),
		rvlimit: 1,
		rvprop: 'ids|user',
		rvstartid: mw.config.get('wgCurRevisionId') - 1,
		rvuser: user,
		format: 'json'
	},
	api = new mw.Api();
	const data = await api.get(params);
	return Object.values(data.query.pages)[0].revisions[0].revid;
}
async function goToDiffLink(user) {
	window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { diff: mw.config.get('wgCurRevisionId'), oldid: await revisionQuery(user) });
}