跳转到内容

User:Former User aDB0haVymg/Gadgets/MWEasyRedirect.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
"use strict";function MWEasyRedirect_Scopemaker(){function a(){return!!b()}function b(){return s||(s=document.querySelector("#t-whatlinkshere")),s}function c(){var a=b().cloneNode(!1);return a.appendChild(document.createElement("a")),a.querySelector("a").innerText=j,a.addEventListener("click",f),a}function d(a){b().insertAdjacentElement("afterend",a)}async function e(a,b){const c=new i;var d=!0;try{await c.readPage(a)}catch(a){if("missingtitle"===a.toString())d=!1;else throw a}if(d){const b=window.confirm(o.replace("$1",a));if(!1===b)throw new Error(r)}const e=q.replace("$1",b);await c.writePage(a,e,p.replace("$2",b))}async function f(a){a.preventDefault();const b=mw.config.get("wgPageName"),c=window.prompt(k);if(!c)return void mw.notify(r);const d=window.confirm(l.replace("$1",c));if(!1===d)return void mw.notify(r);mw.notify(m);try{await e(c,b)}catch(a){return void mw.notify(a.toString())}mw.notify(n)}function g(){const a=c();d(a)}class h extends Error{constructor(a){super(a)}}class i{constructor(){this.apiInterface=new mw.Api}async readPage(a){var b=(await this.apiInterface.get({action:"parse",format:"json",page:a,prop:"wikitext"})).parse;if(b.error)throw new h(b.error.toString());var c=b.wikitext["*"];return c}async writePage(a,b,c=""){var d=(await this.apiInterface.postWithEditToken({action:"edit",format:"json",title:a,text:b,summary:c})).edit;if("success"!=d.result.toLowerCase())throw new h("Edit failed.");else return d.newrevid}}const j="\u5EFA\u7ACB\u91CD\u5B9A\u5411...",k="\u8ACB\u6307\u5B9A\u91CD\u5B9A\u5411\u6A19\u984C",l="\u78BA\u5B9A\u81EA\u300C$1\u300D\u5EFA\u7ACB\u91CD\u5B9A\u5411\uFF1F",m="\u6B63\u5728\u5EFA\u7ACB\u91CD\u5B9A\u5411...",n="\u5EFA\u7ACB\u5B8C\u6210\u3002",o="\u300C$1\u300D\u9801\u9762\u5DF2\u5B58\u5728\u3002\u5C07\u5176\u66FF\u63DB\u70BA\u91CD\u5B9A\u5411\uFF1F",p="\u81EA\u52D5\u5EFA\u7ACB\u91CD\u5B9A\u5411\u81F3\u300C$2\u300D",q="#redirect [[$1]]",r="\u7528\u6236\u53D6\u6D88\u64CD\u4F5C\u3002";var s=null;return async function(){const b=a();return!1===b?void console.log("[MWEasyRedirect] \u4E0D\u9069\u7528\u65BC\u6B64\u9801\u9762"):void g()}()}MWEasyRedirect_Scopemaker();