Skip to content

Commit

Permalink
chore: improving handling of images with srcset
Browse files Browse the repository at this point in the history
  • Loading branch information
uggrock committed Jun 18, 2024
1 parent ca00186 commit 59f0eb6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ui/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,17 @@ function updatePreviewArea(htmlContent) {
// console.log("srcset: " + source.srcset);
source.setAttribute("srcset", "");
}

// Fix svg icons shown in full width
const allSVGs = previewHtmlEl.getElementsByTagName("svg");
for (const svg of allSVGs) {
svg.style.maxWidth = "100px"; // svg.getAttribute("naturalWidth");
}

const allImages = previewHtmlEl.getElementsByTagName("img");
for (const img of allImages) {
const imgSrc = img.getAttribute("src");
// img.setAttribute("width", img.getAttribute("naturalWidth"));
if (
imgSrc.startsWith("file:") ||
imgSrc.startsWith("http") ||
Expand All @@ -414,6 +422,12 @@ function updatePreviewArea(htmlContent) {
} else {
img.setAttribute("src", documentBaseUri.pathBase + "/" + imgSrc);
}
// remove unneeded img attributes
// todo use the biggest image in the srcset
img.removeAttribute("srcset");
img.removeAttribute("data-srcset");
img.removeAttribute("sizes");
img.removeAttribute("loading");
}
let styleEl = previewEl.contentDocument.createElement("style");
styleEl.type = "text/css";
Expand Down

0 comments on commit 59f0eb6

Please sign in to comment.