Bilibili-Evolved/min/i18n.min.js
2019-03-19 22:01:07 +08:00

1 line
609 B
JavaScript

(()=>{return(e,t)=>{(async()=>{const{map:n}=await t.importAsync(`i18n.${e.i18nLanguage}`);const o=e=>{const t=[];const n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,false);let o=n.nextNode();while(o){t.push(o);o=n.nextNode()}return t};const r=e=>{const t=n.get(e.nodeValue.trim());if(t!==undefined){if(typeof t==="string"){e.nodeValue=t}else{const{text:n,selector:o}=t;if(e.parentElement.matches(o)){e.nodeValue=n}}}};o(document.body).forEach(r);Observer.childListSubtree("body",e=>{e.forEach(e=>[...e.addedNodes].forEach(e=>{if(e.nodeType===Node.TEXT_NODE){r(e)}else{o(e).forEach(r)}}))})})()}})();