MediaWiki:Gadget-displayname-show.js
外观
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/**
* -------------------------------------------------------------------------
* !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
* -------------------------------------------------------------------------
*/
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/displayname-show/Gadget-displayname-show.js|user=[[U:AnnAngela]]|co-authors=|longId=7964b953d5f534f93b78320135bd3ddc6e2ab1b0|shortId=7964b953|summary=feat: 添加用户组检查以隐藏已注销用户昵称}}';
/* <pre> */
"use strict";$(()=>{const o={autoHide:!0,tag:"Gadget-displayname-show-notification",visibleTimeout:!1},notify=(n,e="success")=>mw.notify(n,{type:e,...o}),createCopyButton=(o,n,e)=>{const t=document.createElement("span");return t.textContent=o,t.style.marginLeft="2px",t.style.cursor="pointer",t.style.fontSize="0.9em",t.title=`复制${e}: ${n}`,t.addEventListener("click",async o=>{o.preventDefault(),o.stopPropagation(),await(async(o,n)=>{try{if(!navigator.clipboard?.writeText)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(o),notify(`${n} "${o}" 已复制到剪贴板!`)}catch(e){if(console.error(`复制${n}失败:`,e),(o=>{const n=document.createElement("textarea");n.value=o,n.setAttribute("readonly",""),n.style.position="absolute",n.style.left="-9999px",document.body.append(n),n.select();try{return document.execCommand("copy")}finally{n.remove()}})(o))return void notify(`${n} "${o}" 已复制到剪贴板!`);notify(`复制失败,请手动选择文字: ${o}`,"error")}})(n,e)}),t},buildDisplayText=(o,n)=>[o,n].filter(Boolean).join(" | "),{wgAction:n,wgCanonicalNamespace:e,wgCanonicalSpecialPageName:t,wgUserGroups:a}=mw.config.get(["wgAction","wgCanonicalNamespace","wgCanonicalSpecialPageName","wgUserGroups"]);if("history"!==n&&"Special"!==e)return;"Contributions"===t&&document.querySelector(".mw-contributions-user-tools a")?.classList.add("mw-userlink");const i=1===+mw.user.options.get("gadget-displayname-copy",0),c=document.querySelectorAll(".mw-userlink");for(const o of c){let{userName:e=o.textContent}=o.dataset;const{userNick:c=""}=o.dataset;"已注销#0000"!==c||a.includes("suppress")||(e="");const s=buildDisplayText(e,c);if(!s)continue;const r=[...o.childNodes].filter(o=>o.nodeType!==Node.TEXT_NODE&&o.textContent!==s);if(o.textContent=s,o.append(...r),!i||"Contributions"!==t&&"history"!==n)continue;const u=[];e&&u.push(createCopyButton("👤",e,"用户名")),c&&u.push(createCopyButton("🏷️",c,"昵称")),u.length>0&&o.after(...u)}});
/* </pre> */