Jump to content

User:Novem Linguae/Scripts/DontForgetG12.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Novem Linguae (talk | contribs) at 11:41, 27 July 2021 (debug). 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.
// <nowiki>

/*
- Check if article is unreviewed
- If so, display a giant "copyright check" button at the top, to remind you to run Earwig's copyvio detector on the article first thing.
- Many submissions are copyright violations, and catching it before you perform a bunch of other steps in the NPP/AFC flowchart saves time.
*/

mw.loader.using('mediawiki.storage').then(function () {
	mw.storage.session.set( 'client-error-opt-out', '1' );
});

$(function() {
	/** returns the pagename, including the namespace name, but with spaces replaced by underscores */
	function getArticleName() {
		return mw.config.get('wgPageName');
	}
	
	function getWikicode(title) {
		// https://www.mediawiki.org/wiki/API:Get_the_contents_of_a_page#Method_1:_Use_the_Revisions_API
		// https://en.wikipedia.org/w/api.php?action=parse&page=Pet_door&prop=wikitext&formatversion=2
		var wikicode = '';
		title = encodeURIComponent(title);
		$.ajax({
			url: 'https://en.wikipedia.org/w/api.php?action=parse&page='+title+'&prop=wikitext&formatversion=2&format=json',
			success: function (result) {
				wikicode = result['parse']['wikitext'];
			},
			dataType: "json",
			async: false
		});
		return wikicode;
	}
	
	function pageIsCuratedFunction(title) {
		let pageIsCurated = '';
		mw.hook( 'ext.pageTriage.toolbar.ready' ).add( function ( queue ) {
			pageIsCurated = queue.reviewed();
		});
		return pageIsCurated;
	}
	
	function insertButton() {
		$('#contentSub').before(`
			<a style="display: inline-block; color: black; margin-top: 0.5em; border: 2px solid black; padding: 0.25em 3em; background-color: #FFDC00; font-size: 1.5em;" href="https://tools.wmflabs.org/copyvios/?lang=en&project=wikipedia&title=` + encodeURIComponent(title) + `" target="_blank">
				Copyvio check
			</a>
		`);
	}
	
	// don't run when not viewing articles
	let action = mw.config.get('wgAction');
	if ( action != 'view' ) return;
	
	// don't run when viewing diffs
	let isDiff = mw.config.get('wgDiffNewId');
	if ( isDiff ) return;
	
	// Only run in mainspace and draftspace
	let namespace = mw.config.get('wgNamespaceNumber');
	if ( ! [0, 118].includes(namespace) ) return;
	
	let title = getArticleName();
	let wikicode = getWikicode(title);
	
	// Only run if 1) article is uncurated or 2) draft is submitted
	let draftIsSubmitted = wikicode.match(/(?:{{AfC submission}}|{{AfC submission\|}}|{{AfC submission\|\|)/);
	// let pageIsNotCurated = $('.mwe-pt-mark-as-unreviewed-button').length;
	// let pageIsCurated = pageIsCuratedFunction();
	// console.log(pageIsCurated);
	if ( draftIsSubmitted ) {
		insertButton();
	}
	
	mw.hook( 'ext.pageTriage.toolbar.ready' ).add( function ( queue ) {
		let pageIsNotCurated = $('[title="Mark this page as reviewed"]').length;
		if ( pageIsNotCurated ) {
			console.log('Unreviewed article detected 2');
			insertButton();
		};
	});
});

// </nowiki>