User:Ajshul/common.js

Source: 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.
importScript('User:Opencooper/IPtoEmoji.js'); // Backlink: [[User:Opencooper/IPtoEmoji.js]]
mw.loader.load( '/w/index.php?title=User:RedWarn/.js&action=raw&ctype=text/javascript' ); // Backlink: [[User:RedWarn/.js]]
importScript('User:Evad37/MoveToDraft.js'); // Backlink: [[User:Evad37/MoveToDraft.js]]
importScript('User:SD0001/BDCS.js'); // Backlink: [[User:SD0001/BDCS.js]]
importScript('User:BrandonXLF/HotDefaultSort.js'); // Backlink: [[User:BrandonXLF/HotDefaultSort.js]]
importScript('User:P999/Toggle VF.js'); // Backlink: [[User:P999/Toggle VF.js]]
function addToolboxLink(url, name, id) {
    return mw.util.addPortletLink('p-navigation', url, name, id);
}
addToolboxLink("https://randomincategory.toolforge.org/?category=&server=en.wikipedia.org&cmnamespace=&cmtype=page", "Random in Category", "ric")

function addToolboxLink(url, name, id) {
    return mw.util.addPortletLink('p-tb', "https://randomincategory.toolforge.org/?category=&server=en.wikipedia.org&cmnamespace=&cmtype=page", "Random in Category", "ric");
}

importScript("User:GregU/randomlink.js")
importScript('Wikipedia:AutoEd/complete.js');
importScript( 'User:Novem Linguae/Scripts/CiteHighlighter.js' ); // Backlink: [[User:Novem Linguae/Scripts/CiteHighlighter.js]]

// <nowiki>

/*
- When you AFC accept or NPP "mark as reviewed", this script automatically adds the AFD PAGES of the reviewed page to your watchlist for 6 months
- This is so that you can see if a page you accept or mark as reviewed gets AFDd. You can then use this information to calibrate and improve your reviewing.
- Additionally, also adds a "Watchlist AFD" option to the More menu, that you can click on for any article.

- Bonus featured: Adds "Watchlist RFA" and "Watchlist SPI" to user pages.
*/

$(function() {
	async function addToWatchlist(title, watchForever = false) {
		let apiObject = {
			url: mw.util.wikiScript('api'),
			type: 'POST',
			dataType: 'json',
			data: {
				format: 'json',
				action: 'watch',
				expiry: '6 months',
				titles: title,
				token: mw.user.tokens.get('watchToken')
			},
		};
		if ( watchForever ) {
			delete apiObject.data.expiry;
		}
		let debugInfo = await $.ajax(apiObject);
		return debugInfo;
	}
	
	function getTitleWithoutNamespace() {
		let title = mw.config.get('wgPageName');
		title = title.replace(/^.*?:/, ''); // strip all namespaces
		return title;
	}
	
	function getTitleWithoutSubpages(title) {
		title = title.replace(/\/.*$/, ''); // strip all subpages
		return title;
	}
	
	// add options to More menu
	let namespace = mw.config.get('wgNamespaceNumber');
	let isUserPage = ( [2, 3].includes(namespace) );
	let isArticleOrDraft = ( [0, 1, 118, 119].includes(namespace) );
	if ( isArticleOrDraft ) {
		mw.util.addPortletLink (
			'p-cactions',
			'#',
			'Watchlist AFD',
			'WatchlistAFD'
		);
	}
	if ( isUserPage ) {
		mw.util.addPortletLink (
			'p-cactions',
			'#',
			'Watchlist RFA',
			'WatchlistRFA'
		);
		mw.util.addPortletLink (
			'p-cactions',
			'#',
			'Watchlist SPI',
			'WatchlistSPI'
		);
	}
	
	// listen for More menu clicks
	$('#WatchlistAFD').on('click', async function() {
		let title = getTitleWithoutNamespace();
		await addToWatchlist('Wikipedia:Articles for deletion/'+title);
		mw.notify(`Added AFD to watchlist.`);
	});
	$('#WatchlistRFA').on('click', async function() {
		let title = getTitleWithoutNamespace();
		title = getTitleWithoutSubpages(title);
		await addToWatchlist('Wikipedia:Requests for adminship/'+title, true);
		mw.notify(`Added RFA to watchlist.`);
	});
	$('#WatchlistSPI').on('click', async function() {
		let title = getTitleWithoutNamespace();
		title = getTitleWithoutSubpages(title);
		await addToWatchlist('Wikipedia:Sockpuppet investigations/'+title, true);
		mw.notify(`Added SPI to watchlist.`);
	});
	
	// listen for AFC accept
	$('body').on('DOMNodeInserted', '.accept #afchSubmitForm', function() {
		$('.accept #afchSubmitForm').on('click', function() {
			let title = mw.config.get('wgPageName');
			title = title.replace(/^Draft:/, '');
			addToWatchlist('Wikipedia:Articles for deletion/'+title);
		});
	});
	
	// listen for NPP mark as reviewed
	$('body').on('DOMNodeInserted', '#mwe-pt-mark-as-reviewed-button', function() {
		$('#mwe-pt-mark-as-reviewed-button').on('click', function() {
			let title = mw.config.get('wgPageName');
			addToWatchlist('Wikipedia:Articles for deletion/'+title);
		});
	});
});

// </nowiki>