mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
(()=>{return(t,e)=>{const o=/@(\d+)[Ww]_(\d+)[Hh]/;const n=t.imageResolutionScale==="auto"?window.devicePixelRatio:parseFloat(t.imageResolutionScale);const r=["#certify-img1","#certify-img2"];const i=(t,e)=>{const o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null,false);let n=o.nextNode();while(n){e(n);n=o.nextNode()}};async function a(t){const e=(e,i)=>{const a=e(t);if(a===null){return}if(r.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);i(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()=>{i(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"){i(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}}}})(); |