User:Novem Linguae/Scripts/DontForgetG12.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Novem Linguae/Scripts/DontForgetG12. |
// <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>