MediaWiki:Gadget-site-js.js

来自Vocawiki
星幻丶碎梦留言 | 贡献2025年9月13日 (六) 18:21的版本 (搬运自萌娘百科,依CC BY-NC-SA 3.0 CN导入)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转到导航 跳转到搜索

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
/* <pre> */

"use strict";(async()=>{const e=mw.config.get("wgUserGroups"),t=e.includes("patroller")||e.includes("sysop"),o=mw.config.get("wgNamespaceNumber"),a=mw.config.get("wgAction"),l=document.body,i=document.documentElement,n=$(l),r=$(window),sleep=(e=1e3)=>new Promise(t=>setTimeout(t,e));if(["ViewAvatar","Listfiles","ListDuplicatedFiles","Unusedimages","Uncategorizedimages","MediaStatistics","TimedMediaHandler"].includes(mw.config.get("wgCanonicalSpecialPageName"))){const e=new mw.Uri;e.host=e.host.replace(/^[^.]+/g,"commons"),e.path=mw.config.get("wgScript"),e.query.title=`${mw.config.get("wgCanonicalNamespace")}:${mw.config.get("wgCanonicalSpecialPageName")}`,location.replace(e)}const d=["hidden","clip"];r.on("resize",()=>{const e=window.innerWidth;let t;if(d.includes(getComputedStyle(l).overflowY))if(d.includes(getComputedStyle(i).overflowY)){const o=l.style.overflowY;l.style.overflowY="scroll",t=e-l.clientWidth,l.style.overflowY=o}else t=e-i.clientWidth;else t=e-l.clientWidth;n[t<=0?"addClass":"removeClass"]("overlay-scrollbars")}).trigger("resize"),$(".annotation").each((e,t)=>{const o=new OO.ui.PopupWidget({$content:$(t).children(".annotation-content"),padded:!0,autoFlip:!1});$(t).append(o.$element).on("mouseover",()=>{o.toggle(!0)}).on("mouseout",()=>{o.toggle(!1)})});const c=[".heimu",".colormu",".just-kidding-text"],s=["s","del",...c].join(", "),domainChangedAlert=()=>{n.before('<div style="background: #3366CC; color: white; text-align: center; padding: .5rem; position: static;" id="domainChangedAlert"><p>萌娘百科已将域名替换为 <code>*.moegirl.org<b><u>.cn</u></b></code>,原有域名可能访问困难,请更换您的书签等的页面地址。</p></div>'),n.css({"background-position-y":$("#domainChangedAlert").outerHeight(),position:"relative"})},m=/^[\da-f]{2}$/i,g=/^[\da-f]{4}$/i,b=Document.prototype.createElement.bind(document),f=Element.prototype.getAttribute,p=Element.prototype.setAttribute,u=Node.prototype.cloneNode,w=Node.prototype.appendChild.bind(document.body),h=Node.prototype.contains.bind(document.body),watermark=(e,t)=>{const o=`position: fixed !important; z-index: 99999 !important; inset: 0px !important; background-image: url("data:image/svg+xml;base64,${btoa(`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><foreignObject width="${t}" height="${t}"><html xmlns="http://www.w3.org/1999/xhtml" style="width: ${t}px; height: ${t}px;"><head></head><body style="width: ${t}px; height: ${t}px; margin: 0px;"><div style="width: 100% !important; height: 100% !important; opacity: .17 !important; font-size: 24px !important; position: relative !important; color: black !important;"><div style="transform: rotate(-15deg) translateX(-50%) translateY(-50%) !important; word-break: break-all !important; top: 36% !important; left: 50% !important; position: absolute !important; width: 100% !important; text-align: center !important;">${(e=>{const t=`${e}`;let o="";const a=t.length;let l,i,n=0;for(;n<a;){if(l=t.charAt(n++),"%"===l)if("u"===t.charAt(n)){if(i=t.slice(n+1,n+5),g.exec(i)){o+=String.fromCharCode(parseInt(i,16)),n+=5;continue}}else if(i=t.slice(n,n+2),m.exec(i)){o+=String.fromCharCode(parseInt(i,16)),n+=2;continue}o+=l}return o})(encodeURIComponent(e))}</div></div></body></html></foreignObject></svg>`)}") !important; background-repeat: repeat !important; pointer-events: none !important; display: block !important; visibility: visible !important; width: unset !important; height: unset !important; opacity: unset !important; background-color: unset !important;`,a=b("div");p.bind(a)("style",o);let l=w(u.bind(a)(!0));setInterval(()=>{const e=[];if(h(l)||e.push("not in body"),f.bind(l)("style")!==o&&e.push("styleString not match"),e.length>0){console.info("[watermark] Recreate watermark:",e);try{l.remove()}catch{}l=w(u.bind(a)(!0))}},1e3)};await $.ready;try{let e;try{e=top.location.host}catch{e=""}const t=!/\.moegirl\.org(?:\.cn)?$/i.test(location.host);if(top!==window||t){const o=t?location.host:e;oouiDialog.alert(`<p>您当前是在${t?"非萌百域名":"嵌套窗口"}访问,请注意不要在此域名下输入您的用户名或密码,以策安全!</p><p>${o?`${t?"当前":"顶层窗口"}域名为 <code>${o}</code>,`:""}萌百域名是以 <code>.moegirl.org.cn</code> 结尾的。</p>`,{title:"萌娘百科提醒您",size:"medium"})}else location.hostname.endsWith(".moegirl.org.cn")||$(domainChangedAlert)}catch(e){console.debug(e)}if(function tabs(){const e={purple:{labelColor:" ",labelBackgroundColor:"#9070c0",labelBorderColor:"#b090e0 #7050a0 #9070c0 #b090e0",labelPadding:".2em .3em .2em .3em",textBorderColor:"#9070c0",textBackgroundColor:"#f0edf5",textPadding:"1em"},green:{labelColor:" ",labelBackgroundColor:"#75c045",labelBorderColor:"#90d060 #60b030 #75c045 #90d060",labelPadding:".2em .3em .2em .3em",textBorderColor:"#75c045 #60b030 #60b030 #75c045",textBackgroundColor:"#f5fffa",textPadding:"1em"},red:{labelColor:" ",labelBackgroundColor:"#FF0000",labelBorderColor:"#FF8888 #CC0000 #FF0000 #FF8888",labelPadding:".2em .3em .2em .3em",textBorderColor:"#FF0000 #CC0000 #CC0000 #FF0000",textBackgroundColor:"#fffafa",textPadding:"1em"},blue:{labelColor:" ",labelBackgroundColor:"#5b8dd6",labelBorderColor:"#88abde #3379de #5b8dd6 #88abde",labelPadding:".2em .3em .2em .3em",textBackgroundColor:"#f0f8ff",textBorderColor:"#5b8dd6 #3379de #3379de #5b8dd6",textPadding:"1em"},yellow:{labelColor:" ",labelBackgroundColor:"#ffe147",labelBorderColor:"#ffe977 #ffd813 #ffe147 #ffe977",labelPadding:".2em .3em .2em .3em",textBackgroundColor:"#fffce8",textBorderColor:"#ffe147 #ffd813 #ffd813 #ffe147",textPadding:"1em"},orange:{labelColor:" ",labelBackgroundColor:"#ff9d42",labelBorderColor:"#ffac5d #ff820e #ff9d42 #ffac5d",labelPadding:".2em .3em .2em .3em",textBackgroundColor:"#ffeedd",textBorderColor:"#ff9d42 #ff820e #ff820e #ff9d42",textPadding:"1em"},black:{labelColor:" ",labelBackgroundColor:"#7f7f7f",labelBorderColor:"#999999 #4c4c4c #7f7f7f #999999",labelPadding:".2em .3em .2em .3em",textBackgroundColor:"#e5e5e5",textBorderColor:"#7f7f7f #4c4c4c #4c4c4c #7f7f7f",textPadding:"1em"}},t={top:{className:"tabLabelTop",labelColorSide:"top",labelBorderSide:["left","right"],labelColorSideReverse:"bottom",dividerSizeType:"height"},bottom:{className:"tabLabelBottom",labelColorSide:"bottom",labelBorderSide:["left","right"],labelColorSideReverse:"top",dividerSizeType:"height"},left:{className:"tabLabelLeft",labelColorSide:"left",labelBorderSide:["top","bottom"],labelColorSideReverse:"right",dividerSizeType:"width"},right:{className:"tabLabelRight",labelColorSide:"right",labelBorderSide:["top","bottom"],labelColorSideReverse:"left",dividerSizeType:"width"}},o=["1","on","true","yes"];n.addClass("tab");const getOwnPropertyNamesLength=e=>Reflect.ownKeys(e).length;mw.hook("wikipage.content").add(a=>{a.find(".Tabs").each(function(){const a=$(this);if(a.children(".TabLabel")[0])return!0;const l=Array.from(this.classList).filter(t=>Reflect.has(e,t)),i=$.extend({labelPadding:"2px",labelBorderColor:"#aaa",labelColor:"green",labelBackgroundColor:$("#content").css("background-color")||"rgba(247,251,255,0.8)",textPadding:"20px 30px",textBorderColor:"#aaa",textBackgroundColor:"white",defaultTab:1},l[0]&&e[l[0]]||{},this.dataset||{}),n={label:{},text:{}},d=a.append('<div class="TabLabel"></div>').children(".TabLabel"),c=a.append('<div class="TabDivider"></div>').children(".TabDivider"),s=a.append('<div class="TabContent"></div>').children(".TabContent"),m=i.labelPadding,g=i.labelColor,b=Reflect.has(t,i.labelSide)?i.labelSide:"top",f=t[b],p=o.includes(i.labelColorSideReverse),u=parseInt(i.dividerSize);let w=parseInt(i.defaultTab);"top"===b?(d.after(c),c.after(s)):"bottom"===b&&(s.after(c),c.after(d)),!isNaN(u)&&u>0&&a.find(".TabDivider")[f.dividerSizeType](u);const h=(C=p?f.labelColorSideReverse:f.labelColorSide).substring(0,1).toUpperCase()+C.substring(1);var C;a.addClass(f.className),p&&a.addClass("reverse"),a.children(".Tab").each(function(){($(this).children(".TabLabelText").text().replace(/\s/g,"").length||$(this).children(".TabLabelText").children().length)&&($(this).children(".TabLabelText").appendTo(d),$(this).children(".TabContentText").appendTo(a.children(".TabContent"))),$(this).remove()}),(isNaN(w)||w<=0||w>d.children(".TabLabelText").length)&&(w=1),d.children(".TabLabelText").on("click",function(){const e=$(this);e.addClass("selected").siblings().removeClass("selected").css({"border-color":"transparent","background-color":"inherit"}),s.children(".TabContentText").eq(d.children(".TabLabelText").index(e)).addClass("selected").siblings().removeClass("selected").removeAttr("style"),getOwnPropertyNamesLength(n.label)>0&&e.css(n.label),setTimeout(()=>{r.triggerHandler("scroll")},1)}).eq(w-1).trigger("click"),m&&d.children(".TabLabelText").css("padding",m),["labelBorderColor","labelBackgroundColor","textPadding","textBorderColor","textBackgroundColor"].forEach(e=>{const t=/^label/.test(e)?"label":"text",o=(e=>e.substring(0,1).toLowerCase()+e.substring(1))(e.replace(t,""));n[t][o]=i[e]}),g?n.label[`border${h}Color`]=g:n.label.borderColor&&(n.label[`border${h}Color`]="green"),d.find(".selected").trigger("click"),getOwnPropertyNamesLength(n.text)>0&&s.css(n.text),"yes"===i.autoWidth&&a.addClass("AutoWidth"),"left"===i.float&&a.addClass("FloatLeft"),"right"===i.float&&a.addClass("FloatRight")})})}(),setInterval(()=>{$(document.querySelectorAll('img[src*="//img.moegirl.org/"]:not(.org-changed), img[src*="//commons.moegirl.org/"]:not(.org-changed)')).each((e,t)=>{try{const e=new mw.Uri(t.src);["img.moegirl.org","commons.moegirl.org"].includes(e.host)&&(e.host+=".cn",t.src=e),t.classList.add("org-changed")}catch{}})},200),mw.hook("wikipage.content").add(a=>{const l=$();a.find(s).each((e,o)=>{if("true"===o.isTemplateFixed)return;o.isTemplateFixed=!0;const a=Array.from(o.querySelectorAll(s));a.length>0&&(l.push(o),a.forEach(e=>{e.isTemplateFixed=!0,c.forEach(o=>{t||e.classList.remove(o.substring(1))})}),console.info("TemplateFix",o,a))}),o>=0&&o%2==0&&l.length>0&&((1===+mw.user.options.get("gadget-enable-nest-highlight",0)||t&&!e.includes("staff"))&&l.css("border","3px dashed red"),
t&&!e.includes("staff")&&1!==+mw.user.options.get("gadget-disable-nest-alert",0)&&oouiDialog.alert(`本页面含有嵌套使用(混用)以下标签或模板的内容(已用红色虚线边框标识),请检查源码并修改之:<ul><li>删除线:<code>${oouiDialog.sanitize("<s>")}</code>、<code>${oouiDialog.sanitize("<del>")}</code>;</li><li>黑幕:<code>{{黑幕}}</code>、<code>{{Block}}</code>、<code>{{Heimu}}</code>;</li><li>彩色幕:<code>{{彩色幕}}</code>;</li><li>胡话:<code>{{胡话}}</code>、<code>{{jk}}</code>,大小写不限。</li></ul>`,{title:"萌娘百科提醒您",size:"medium"}))}),["edit","submit"].includes(a)&&(async()=>{const e=document.getElementById("TencentCaptchaBtn");if(e&&!e.disabled){const t=e.innerText;e.innerText="正在加载验证码,请稍候……";const o=document.getElementById("wpCaptchaWord"),a=document.getElementById("wpCaptchaId");for(;"function"!=typeof window.TencentCaptcha;)await sleep(100);e.disabled||(new window.TencentCaptcha(e),e.innerText=t),document.getElementById("wpSave").addEventListener("click",t=>{e.disabled||o.value&&a.value||(oouiDialog.alert("请点击验证按钮,完成验证后再提交"),t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation())},{capture:!0})}})(),"history"===a&&(()=>{const e=$("#mw-history-compare, #mw-log-deleterevision-submit");e.find('[name="editchangetags"], [name="revisiondelete"]').on("click",()=>{e.attr("method","post"),setTimeout(()=>{e.removeAttr("method")},16)})})(),/[)]$/.test(location.pathname+location.search)){const e=location.hash;location.hash="%",location.hash=e}r.on("hashchange.hashchange",()=>{const e=decodeURIComponent(location.hash.replace(/^#/,""));if(e.length>0){const t=document.getElementById(e);if(t){const e=$(t),o=!0,a=e.closest(".mw-collapsible.mw-collapsed");a.length>0&&a.find(".mw-collapsible-toggle").first().triggerHandler("click");const l=e.closest(".TabContentText:not(.selected)");l.length>0&&l.closest(".Tabs").children(".TabLabel").children().eq(l.index()).trigger("click"),o&&setTimeout(()=>{$("html, body").scrollTop(e.offset().top-window.innerHeight/8)},50)}}}),r.triggerHandler("hashchange.hashchange"),setInterval(()=>{$(".mw-parser-output ul:not(.margin-left-set), .mw-parser-output ol:not(.margin-left-set), #mw-content-text > pre.prettyprint ul:not(.margin-left-set), #mw-content-text > pre.prettyprint ol:not(.margin-left-set)").each((e,t)=>{const o=$(t);if(/none.+none/i.test(o.css("list-style"))||o.is(".gallery"))o.parent().is("li")&&o.parent().parent().is("ul, ol")?o.css("margin-left","1.2em"):o.css("margin-left","0.2em");else if(o.is("ol")){const e=o.children("li"),t=o.attr("start");let a=/^\d+$/.test(t)?+t:0;e.each((e,t)=>{const o=$(t).attr("value");/^\d+$/.test(o)?a=Math.max(a,+o):a++}),o.attr("data-last-margin-left-max-length",a).css("margin-left",.5*`${a}`.length+1.2+"em")}else o.css("margin-left","1.2em");o.addClass("margin-left-set")})},200),["copy","keydown","scroll","mousemove"].forEach(e=>{document.addEventListener(e,()=>{$(".mailSymbol").replaceWith('<span title="Template:Mail@">@</span>')},{capture:!0,passive:!0})}),"GadgetUsage"===mw.config.get("wgCanonicalSpecialPageName")&&(()=>{const e=["默认","預設","默認"],t=[],o=document.querySelector(".mw-spcontent > table");for(const a of o.querySelectorAll("tr")){const[{innerText:o},{innerText:l},{innerText:i}]=a.children;e.includes(l.trim())&&e.includes(i.trim())&&(a.style.display="none",t.push(o))}if(t.length>0){const e=document.createElement("div"),a=document.createElement("table");a.classList.add("wikitable");const l=document.createElement("caption");l.innerText=wgULS("默认小工具","預設小工具"),a.append(l);const i=document.createElement("thead"),n=document.createElement("tr"),r=document.createElement("th");r.innerText="小工具",a.append(i),i.append(n),n.append(r);const d=document.createElement("tbody");a.append(d);for(const e of t){const t=document.createElement("tr"),o=document.createElement("td");o.innerText=e,d.append(t),t.append(o)}o.before(e),e.append(o);const c=document.createElement("caption");c.innerText=document.querySelector("#firstHeading").innerText,o.append(c),e.append(a),e.style.display="flex",e.style.flexWrap="wrap",e.style.alignContent="flex-start",e.style.justifyContent="space-evenly",e.style.alignItems="flex-start"}})();const C=mw.config.get("wgCurRevisionId")||-1,x=mw.config.get("wgRevisionId")||-1;if(!e.includes("autoconfirmed"))if(C>0&&x>0&&C!==x)watermark("历史版本,非最新内容<br/>不代表萌娘百科立场",300);else if([2,3].includes(o)){const e=mw.config.get("wgPageName"),t=(v=o,RegExp(`^(?:${Object.entries(mw.config.get("wgNamespaceIds")).filter(e=>e[1]===v).map(e=>e[0].toLowerCase()).join("|")}):`,"i")),a=$("#firstHeading, #section_0").first().text().replace(/ /g,"_").replace(t,"").trim();if("view"===mw.config.get("wgAction")&&mw.config.get("wgArticleId")>0&&a!==e.replace(/ /g,"_").replace(t,"").trim()){const o=await(new mw.Api).post({action:"query",prop:"info",inprop:"varianttitles",titles:e});0===Object.values(o.query.pages[mw.config.get("wgArticleId")].varianttitles).filter(e=>a===e.replace(/ /g,"_").replace(t,"").trim()).length&&watermark("用户页面,非正式条目<br/>不代表萌娘百科立场",300)}}var v;mw.hook("ve.activationComplete").add(()=>{mw.loader.load("ext.gadget.edit")}),r.triggerHandler("resize"),r.on("load",()=>{r.triggerHandler("resize")})})(); 

/* </pre> */