mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
1.4 KiB
JavaScript
1 line
1.4 KiB
JavaScript
(()=>(t,e)=>{const o=/@(\d+)[Ww]_(\d+)[Hh]/;const n=t.imageResolutionScale==="auto"?window.devicePixelRatio:parseFloat(t.imageResolutionScale);const i=["#certify-img1","#certify-img2"];const r=(t,e)=>{const o=document.createNodeIterator(t,NodeFilter.SHOW_ELEMENT,null);let n=o.nextNode();while(n){if(n instanceof HTMLElement){e(n)}n=o.nextNode()}};async function a(t){const e=(e,r)=>{const a=e(t);if(a===null){return}if(i.some((e=>t.matches(e)))){return}const s=a.match(o);if(!s){return}let[,c,u]=s;let l=parseInt(t.getAttribute("data-resolution-width")||"0");if(parseInt(c)>=l&&l!==0){return}if(t.getAttribute("width")===null&&t.getAttribute("height")===null){t.setAttribute("width",c)}c=Math.round(n*parseInt(c)).toString();u=Math.round(n*parseInt(u)).toString();t.setAttribute("data-resolution-width",c);r(t,a.replace(o,`@${c}w_${u}h`))};Observer.attributes(t,(()=>{e((t=>t.getAttribute("src")),((t,e)=>t.setAttribute("src",e)));e((t=>t.style.backgroundImage),((t,e)=>t.style.backgroundImage=e))}))}const s=async()=>{r(document.body,(t=>a(t)));Observer.childListSubtree(document.body,(t=>{for(const e of t){for(const t of e.addedNodes){if(t instanceof HTMLElement){a(t);if(t.nodeName.toUpperCase()!=="IMG"){r(t,(t=>a(t)))}}}}}))};s();e.applyStyleFromText(`.favInfo-box .favInfo-cover img {width: 100% !important object-position: left !important}`,"image-resolution-fix");return{export:{imageResolution:a}}})(); |