Jump to content
Wikipedia The Free Encyclopedia

User:Novem Linguae/Scripts/DontForgetG12.js

From Wikipedia, the free encyclopedia
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.
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.
 */

 classDontForgetG12{
 constructor(){
 this.mw=mw;
 this.$=$;
 }

 asyncexecute(){
 if(!awaitthis.shouldRunOnThisPage()){
 return;
 }

 // Only run if 1) draft is submitted
 constisDraftspaceOrUserspace=[118,2].includes(this.namespace);
 constdraftIsSubmitted=this.wikicode.match(/(?:{{AfC submission}}|{{AfC submission\|}}|{{AfC submission\|\|)/i)&&isDraftspaceOrUserspace;
 if(draftIsSubmitted){
 this.insertButton(this.title);
 }

 // or 2) article is not marked as reviewed by NPP
 this.mw.hook('ext.pageTriage.toolbar.ready').add(asyncfunction(){
 constpageID=this.mw.config.get('wgArticleId');
 if(!(awaitthis.isReviewed(pageID))){
 this.insertButton(this.title);
 }
 }.bind(this));
 }

 asyncshouldRunOnThisPage(){
 // don't run when not viewing articles
 constaction=this.mw.config.get('wgAction');
 if(action!=='view'){
 returnfalse;
 }

 // don't run when viewing diffs
 constisDiff=this.mw.config.get('wgDiffNewId');
 if(isDiff){
 returnfalse;
 }

 constisDeletedPage=(!this.mw.config.get('wgCurRevisionId'));
 if(isDeletedPage){
 returnfalse;
 }

 this.namespace=this.mw.config.get('wgNamespaceNumber');
 constisMainspaceDraftspaceOrUserspace=[0,118,2].includes(this.namespace);
 if(!isMainspaceDraftspaceOrUserspace){
 returnfalse;
 }

 this.title=this.getArticleName();
 this.wikicode=awaitthis.getWikicode(this.title);

 // Don't run on redirect pages
 constisRedirect=this.wikicode.match(/^#REDIRECT \[\[/i);
 if(isRedirect){
 returnfalse;
 }

 returntrue;
 }

 /**
 	 * @return {string} pagename, including the namespace name, but with spaces replaced by underscores
 	 */
 getArticleName(){
 returnthis.mw.config.get('wgPageName');
 }

 asyncgetWikicode(title){
 if(!this.mw.config.get('wgCurRevisionId')){
 return'';
 }
 // if page is deleted, return blank
 letwikicode='';
 title=encodeURIComponent(title);
 awaitthis.$.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'
 });
 returnwikicode;
 }

 insertButton(title){
 this.$('#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://copyvios.toolforge.org/?lang=en&project=wikipedia&title=`+encodeURIComponent(title)+`" target="_blank">
 				Copyvio check
 			</a>
 		`);
 }

 asyncisReviewed(pageId){
 constapi=newthis.mw.Api();
 constresponse=awaitapi.get({
 action:'pagetriagelist',
 format:'json',
 page_id:pageId
 });

 // no result
 if(response.pagetriagelist.result!=='success'||response.pagetriagelist.pages.length===0){
 returntrue;
 // 1, 2, or 3
 }elseif(parseInt(response.pagetriagelist.pages[0].patrol_status)>0){
 returntrue;
 // 0
 }else{
 returnfalse;
 }
 }
 }

 $(asyncfunction(){
 awaitmw.loader.using(['mediawiki.api'],async()=>{
 await(newDontForgetG12(mw,$)).execute();
 });
 });

 // </nowiki>

AltStyle によって変換されたページ (->オリジナル) /