MediaWiki:Gadget-displayname-default.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-default/Gadget-displayname-default.js|user=[[U:星海子]]|co-authors=|longId=655eb970a1b63d3c5486790aefd7276283279acc|shortId=655eb970|summary=fix|body=<nowiki>Normalize text node values by replacing underscores with spaces before comparing to userName. This ensures DOM text like "John_Doe" will match a userName of "John Doe" and be replaced with the configured targetText (change in src/gadgets/displayname-default/Gadget-displayname-default.js).</nowiki>}}';
/* <pre> */
"use strict";(()=>{const o=document.querySelector(".mw-parser-output");if(!o)return;const replaceTextNodes=(o,e,s)=>{if(o.nodeType===Node.TEXT_NODE)o.nodeValue.trim().replace(/_/g," ")===e&&(o.nodeValue=s);else{const n=[...o.childNodes];for(const o of n)replaceTextNodes(o,e,s)}},e=o.querySelectorAll("a[data-user-nick]");for(const o of e){const{userName:e,userNick:s}=o.dataset;if(!e||!s)continue;if(o.closest(".moe-displayname-none"))continue;const n=!!o.closest(".moe-displayname-both")&&(1===+mw.user.options.get("gadget-displayname-both",0)||mw.config.get("wgUserGroups").includes("sysop"));replaceTextNodes(o,e,n?`${e} | ${s}`:s)}})();
/* </pre> */