跳转到内容

英文维基 | 中文维基 | 日文维基 | 草榴社区

User:Former User aDB0haVymg/Gadgets/Fork.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
"use strict";function forkAPageScopeMaker(){function a(){return!!l}function b(){const a=l.cloneNode(!0),b=a.querySelector("a");return a.id=q,b.href="",b.id="",b.title="",b.accesskey="",b.innerText=r,a.onclick=h,l.insertAdjacentElement("afterend",a),a}async function c(){!1==a()&&console.log(s),b()}function d(a){const b=mw.config.get("wgArticlePath").replace("$1",a);location.href=b}async function e(a){var b=!0;try{await m.readPage(a)}catch(a){if("missingtitle"===a.toString())b=!1;else throw a}return b}function f(){return t.replace("$TITLE",n).replace("$REVID",o)}async function g(a){const b=await m.readPage(n),c=f();await m.writePage(a,b,c)}async function h(a){try{a.preventDefault();const b=window.prompt(u);if(!b)return void mw.notify(w);if(!0===e(b)){const a=window.confirm(v.replace("$1",b));if(!1===a)return void mw.notify(w)}mw.notify(x),await g(b),mw.notify(y),await i(p),d(b)}catch(a){j(a)}}function i(a){return new Promise(b=>{setTimeout(b,a)})}function j(a){throw mw.notify(z.replace("$1",a.toString())),a}class k extends Error{constructor(a){super(a)}}const l=document.querySelector("#t-whatlinkshere"),m=new class a{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 k(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 k("Edit failed.");else return d.newrevid}},n=mw.config.get("wgPageName"),o=mw.config.get("wgRevisionId").toString(),p=1e3,q="t-fork-a-page",r="\u8907\u523B\u672C\u9801\u9762...",s="[fork-a-page.js] \u6B64\u9801\u9762\u4F3C\u4E4E\u4E0D\u662F\u5167\u5BB9\u9801\u9762\u3002",t="[\u534A\u81EA\u52D5] \u8907\u523B\u81EA\u300C[[$TITLE]]\u300D\u7684\u7248\u672C $REVID",u="\u8907\u523B\u5230\u54EA\u88E1\uFF1F",v="\u9801\u9762\u300C$1\u300D\u5DF2\u5B58\u5728\u3002\u8981\u8986\u84CB\u5B83\u55CE\uFF1F",w="\u7528\u6236\u53D6\u6D88\u64CD\u4F5C\u3002",x="\u6B63\u5728\u5BEB\u5165\u65B0\u9801\u9762...",y="\u8907\u523B\u5B8C\u6210\uFF1B\u5373\u5C07\u91CD\u5B9A\u5411...",z="[fork-a-page.js] \u932F\u8AA4: $1";try{c(),console.log("[Fork-A-Page.js] Initialised")}catch(a){j(a)}}forkAPageScopeMaker();