注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
?_=1
来访问最新页面。https://mzh.moegirl.org.cn/User:BearBin/js/FileUsedNotLinked.js?_=1
var _addText = '{{Documentation|content=* 工具介绍见[[User:BearBin/js#FileUsedNotLinked]]。\n* 源代码见[https://github.com/BearBin1215/MoegirlPedia/blob/master/src/gadgets/FileUsedNotLinked GitHub]。}}'; // <nowiki> (()=>{"use strict";const e=async e=>{const t=new mw.Api,n=await t.post({action:"query",prop:"revisions",titles:e,rvprop:"content"}),[i]=Object.values(n.query.pages);if("revisions"in i)return i.revisions?.[0]["*"];if("missing"in i)throw"missingtitle"};$((()=>(async()=>{if(6===mw.config.get("wgNamespaceNumber")){await mw.loader.using(["mediawiki.api","mediawiki.ForeignApi","mediawiki.notification","oojs-ui"]);const t=new mw.Api,n=new mw.ForeignApi("https://mzh.moegirl.org.cn/api.php",{anonymous:!0}),i=mw.config.get("wgTitle"),o=mw.config.get("wgPageName");let l=[];const a='<div id="funl-note">请注意:对过短的文件名使用本工具可能会出现误判,建议手动检查。</div>';mw.config.get("wgIsRedirect")?$(".redirectMsg").after("<hr/>",a):$("#filelinks").after(a);const s=new OO.ui.ButtonWidget({label:"查询非链入使用",flags:"progressive",icon:"search"}),r=s.$element.children("a");$("#funl-note").after(s.$element);const c=new OO.ui.ButtonWidget({label:"标记非链入使用",flags:"progressive",icon:"tag"}),m=c.$element.children("a");s.$element.after(c.$element);const p=new OO.ui.ButtonWidget({label:"移除非链入标记",flags:"progressive",icon:"tag"}),g=p.$element.children("a");c.$element.after(p.$element),c.$element.hide(),p.$element.hide(),p.$element.after('<div id="search-result" style="margin:.6em 0"><div id="result-overview"></div><ul id="result-list"></ul></div><hr/>');const d=()=>$(".mw-gu-onwiki-zh_moegirl_org_cn a").map(((e,{text:t})=>t)).get(),w=async e=>await n.get({action:"query",list:"search",srnamespace:["0","4","10","12","14","274","828"],srwhat:"text",srprop:"snippet",srsearch:e}),u=async()=>{const[e,t]=await Promise.all([w(`insource:"${i.replaceAll('"'," ")}"`),w(`insource:"${encodeURI(i).replaceAll('"'," ").replaceAll("%20"," ")}"`)]),n=[];[...t.query.search,...e.query.search].forEach((e=>{const t=e.snippet.replaceAll("_"," ").replaceAll('<span class="searchmatch">',"").replaceAll("</span>","");(t.includes(i.replaceAll("_"," "))||t.includes(encodeURI(i.replaceAll("_"," ")))||t.includes(encodeURI(i.replaceAll("_"," ")).replaceAll("%20"," ")))&&n.push(e.title)}));const o=new Set([...d()]);let l=n.filter((e=>!o.has(e)));return 0===l.length?($("#result-overview").text("zh站没有查找到非链入使用此文件的页面。"),[]):($("#result-overview").text("文件在以下页面以非内链形式使用:"),l=[...new Set(l)],$("#result-list").append(...l.map((e=>`<li><a href="https://zh.moegirl.org.cn/${e}">zhmoe:${e}</a></li>`))),r.removeClass("oo-ui-pendingElement-pending"),l)},h=async()=>{mw.notify("正在标记……"),m.addClass("oo-ui-pendingElement-pending");const e=l.map((e=>`[[zhmoe:${e}]]`)).join("、");try{await t.postWithToken("csrf",{format:"json",action:"edit",watchlist:"nochange",tags:"Automation tool",minor:!0,title:o,appendtext:`{{非链入使用|${e}}}`,summary:"标记非链入使用的文件"}).done((()=>{mw.notify("标记成功!将在2秒后刷新……"),m.removeClass("oo-ui-pendingElement-pending"),setTimeout((()=>{window.location.reload()}),2e3)}))}catch(e){mw.notify(`标记失败:${e}`,{type:"error"})}},f=async()=>{mw.notify("正在移除标记……"),g.addClass("oo-ui-pendingElement-pending");try{const n=(await e(o)).replace(/\{\{非链入使用\|[^{}]*\}\}/g,"");await t.postWithToken("csrf",{format:"json",action:"edit",watchlist:"nochange",tags:"Automation tool",minor:!0,nocreate:!0,title:o,text:n,summary:"移除非链入使用标记"}).done((()=>{mw.notify("移除成功!将在2秒后刷新……"),g.removeClass("oo-ui-pendingElement-pending"),setTimeout((()=>{window.location.reload()}),2e3)}))}catch(e){mw.notify(`移除失败:${e}`,{type:"error"})}};s.on("click",(async()=>{mw.notify("正在查询……"),r.addClass("oo-ui-pendingElement-pending"),l=await u(),l.length&&0===$(".used-not-linked").length?c.$element.show():0===l.length&&$(".used-not-linked").length&&p.$element.show(),mw.notify("查询完毕"),r.removeClass("oo-ui-pendingElement-pending")})),c.on("click",h),p.on("click",f)}})()))})(); // </nowiki>