From 89ca3d5d0734e29a68645b36e7bcdb0c189a46a8 Mon Sep 17 00:00:00 2001 From: the1812 Date: Thu, 6 May 2021 13:54:08 +0800 Subject: [PATCH] Fix image width (fix #1583) --- min/dark.user.css | 2 +- min/image-resolution.min.js | 2 +- src/utils/image-resolution.ts | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/min/dark.user.css b/min/dark.user.css index 1b128021e..44f9f3026 100644 --- a/min/dark.user.css +++ b/min/dark.user.css @@ -3,7 +3,7 @@ @namespace Bilibili-Evolved @homepageURL https://github.com/the1812/Bilibili-Evolved @updateURL https://cdn.jsdelivr.net/gh/the1812/Bilibili-Evolved@preview/min/dark.user.css -@version 1014.25.0 +@version 1024.90.0 @license MIT @author Grant Howard (https://github.com/the1812), Coulomb-G (https://github.com/Coulomb-G) ==/UserStyle== */ diff --git a/min/image-resolution.min.js b/min/image-resolution.min.js index a16bf3e7f..d1145ad40 100644 --- a/min/image-resolution.min.js +++ b/min/image-resolution.min.js @@ -1 +1 @@ -(()=>(t,e)=>{const n=/@(\d+)[Ww]_(\d+)[Hh]/;const o=t.imageResolutionScale==="auto"?window.devicePixelRatio:parseFloat(t.imageResolutionScale);const i=["#certify-img1","#certify-img2"];const r=(t,e)=>{const n=document.createNodeIterator(t,NodeFilter.SHOW_ELEMENT,null);let o=n.nextNode();while(o){if(o instanceof HTMLElement){e(o)}o=n.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(n);if(!s){return}let[,c,l]=s;let u=parseInt(t.getAttribute("data-resolution-width")||"0");if(parseInt(c)>=u&&u!==0){return}if(t.getAttribute("width")===null&&t.getAttribute("height")===null){t.setAttribute("width",c)}c=Math.round(o*parseInt(c)).toString();l=Math.round(o*parseInt(l)).toString();t.setAttribute("data-resolution-width",c);r(t,a.replace(n,`@${c}w_${l}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(`\n.favInfo-box .favInfo-cover img {\n width: 100% !important;\n object-position: left !important;\n}\n.bili-avatar-img {\n width: 100% !important;\n}\n`,"image-resolution-fix");return{export:{imageResolution:a}}})(); \ No newline at end of file +(()=>(t,e)=>{const n=/@(\d+)[Ww]_(\d+)[Hh]/;const i=t.imageResolutionScale==="auto"?window.devicePixelRatio:parseFloat(t.imageResolutionScale);const o=["#certify-img1","#certify-img2"];const r=(t,e)=>{const n=document.createNodeIterator(t,NodeFilter.SHOW_ELEMENT,null);let i=n.nextNode();while(i){if(i instanceof HTMLElement){e(i)}i=n.nextNode()}};async function a(t){const e=(e,r)=>{const a=e(t);if(a===null){return}if(o.some((e=>t.matches(e)))){return}const s=a.match(n);if(!s){return}let[,l,c]=s;let d=parseInt(t.getAttribute("data-resolution-width")||"0");if(parseInt(l)>=d&&d!==0){return}if(t.getAttribute("width")===null&&t.getAttribute("height")===null){t.setAttribute("width",l)}l=Math.round(i*parseInt(l)).toString();c=Math.round(i*parseInt(c)).toString();t.setAttribute("data-resolution-width",l);r(t,a.replace(n,`@${l}w_${c}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(`\n.favInfo-box .favInfo-cover img {\n width: 100% !important;\n object-position: left !important;\n}\n.bili-avatar-img {\n width: 100% !important;\n}\n.bb-comment .sailing .sailing-img,\n.comment-bilibili-fold .sailing .sailing-img {\n width: 288px;\n}\n`,"image-resolution-fix");return{export:{imageResolution:a}}})(); \ No newline at end of file diff --git a/src/utils/image-resolution.ts b/src/utils/image-resolution.ts index 59f291372..d81eae288 100644 --- a/src/utils/image-resolution.ts +++ b/src/utils/image-resolution.ts @@ -69,6 +69,10 @@ resources.applyStyleFromText(` .bili-avatar-img { width: 100% !important; } +.bb-comment .sailing .sailing-img, +.comment-bilibili-fold .sailing .sailing-img { + width: 288px; +} `, 'image-resolution-fix') export default { export: { imageResolution }