User:Eejit43/scripts/AFCRHS.js

//

// Note: This script was compiled and minified from TypeScript. For a more readable version, see https://github.com/Eejit43/wikipedia-scripts/blob/main/scripts/AFCRHS.ts

"use strict";(()=>{(function(){if(mw.config.get("wgPageName")!=="Wikipedia:Articles_for_creation/Redirects"&&mw.config.get("wgPageName")!=="Wikipedia:Articles_for_creation/Categories")return;let w=mw.config.get("wgPageName").replaceAll("_"," "),v=[],k=[],N=" (AFCRHS 2)",x=0,I=0,V=[],T=[],j={exists:"The title you suggested already exists on Wikipedia",blank:"We cannot accept empty submissions","no-target":" A redirect cannot be created unless the target is an existing article. Either you have not specified the target, or the target does not exist",unlikely:"The title you suggested seems unlikely. Could you provide a source showing that it is a commonly used alternate name?","not-redirect":"This request is not a redirect request",custom:""},M={exists:"The category you suggested already exists on Wikipedia",blank:"We cannot accept empty submissions",unlikely:"It seems unlikely that there are enough pages to support this category","not-category":"This request is not a category request",custom:""};async function D(){let e=await E(w);e=z(e);let l=/==.*?==/;e=e.slice(Math.max(0,e.search(l))),k=e.match(/^==.*?==$((\r?\n?)(?!==[^=]).*)*/gim);for(let[a,t]of k.entries())if(!/({{\s*afc(?!\s+comment)|this is an archived discussion)/i.test(t)){let s=t.match(l)[0];if(s.search(/redirect request/i)!==-1){let r=/\[\[(\s*[^=]*?)*?]]/g,n=s.match(r);if(!n)continue;for(let _=0;_\/g,""),n[_].charAt(0)===":"&&(n[_]=n[_].slice(1));/target of redirect:\s*\[\[([^[\]]*)]]/i.test(t);let d=$.trim(RegExp.$1),A=/reason:[\t ]*?(.+)/i.exec(t),H=A&&A[1].trim()?A[1]:null,g=/source.*?:[\t ]*?(.+)/i.exec(t),f=g&&g[1].trim()?g[1]:null,h={type:"redirect",from:[],section:a,to:d,title:d,reason:H,source:f};for(let _ of n){let P={type:"redirect",to:d,id:x,title:_,action:""};h.from.push(P),V.push(P),x++}v.push(h)}else if(s.search(/category request/i)!==-1){let r=/\[\^[\+]]/.exec(s);if(!r)continue;r=r[0],r=r.replaceAll(/\/g,""),r=r.replaceAll(/category\s*:\s*/gi,"Category:"),r.charAt(0)===":"&&(r=r.slice(1));let n=t.slice(s.length),p=n.indexOf("Parent category/categories");p>=0&&(n=n.slice(Math.max(0,p)));let d=[],u=null,A=/\[\[\s*:\s*(category:[^[\]]*)]]/gi;do u=A.exec(n),u&&d.push(u[1]);while(u);let H={type:"category",title:r,section:a,id:x,action:"",parents:d.join(",")};x++,v.push(H),V.push(H)}}let i=$("

Reviewing AfC redirect requests

");W(i);let m=i.parent(),c=1,o=[{label:"Accept",value:"accept"},{label:"Decline",value:"decline"},{label:"Comment",value:"comment"},{label:"None",selected:!0,value:"none"}];for(let a of v){let t;t=a.to===void 0?"":a.to.replaceAll(/\s/g,"");let b=$("
    "),s=$("
  • ");if(a.type==="redirect"){if(s.append("Redirect(s) to "),t){if(!a.to)for(let n=a.from.length-1;n>=0;n--)T.push({id:a.from[n].id,reason:"not-redirect"})}else for(let n=a.from.length-1;n>=0;n--)T.push({id:a.from[n].id,reason:"no-target"});a===""||a===" "?(s.append("Empty submission #"+c),c++):t.length>0?s.append($("").attr("href",mw.config.get("wgArticlePath").replace("$1",encodeURIComponent(a.to))).attr("target","_blank").text(a.to)):s.append("no target given: ");let r=$("
      ").appendTo(s);for(let n=0;nno title specified, check the request details");let u=$("
        ");a.reason&&u.append("
      • Reason: "+a.reason+"
      • "),a.source&&u.append("
      • Source: "+a.source+"
      • ");let A='http://www.google.com/search?q="'+encodeURIComponent(d)+'"+-wikipedia.org';r.append($("
      • ").append("From: "+d+" (Google · what links here)
        ').append(u).append($("