Skip to content

Commit

Permalink
feat: separate css
Browse files Browse the repository at this point in the history
  • Loading branch information
liady committed Dec 5, 2022
1 parent 4d932b8 commit 959eeec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function downloadThread({ as = Format.PNG } = {}) {
const pixelRatio = window.devicePixelRatio;
const minRatio = as === Format.PDF ? 2 : 2.5;
window.devicePixelRatio = Math.max(pixelRatio, minRatio);
html2canvas(elements.thread).then(async function (canvas) {
html2canvas(elements.thread, {
letterRendering: true,
}).then(async function (canvas) {
elements.restoreLocation();
window.devicePixelRatio = pixelRatio;
const imgData = canvas.toDataURL("image/png");
Expand Down Expand Up @@ -144,6 +146,7 @@ class Elements {
this.scroller = Array.from(
document.querySelectorAll('[class*="react-scroll-to"]')
).filter((el) => el.classList.contains("h-full"))[0];
this.images = Array.from(document.querySelectorAll("img[srcset]"));
}
fixLocation() {
this.threadWrapper.style.overflow = "auto";
Expand All @@ -155,6 +158,11 @@ class Elements {
this.positionForm.style.display = "none";
this.scroller.classList.remove("h-full");
this.scroller.style.minHeight = "100vh";
this.images.forEach((img) => {
const srcset = img.getAttribute("srcset");
img.setAttribute("srcset_old", srcset);
img.setAttribute("srcset", "");
});
}
restoreLocation() {
this.threadWrapper.style.overflow = null;
Expand All @@ -166,6 +174,11 @@ class Elements {
this.positionForm.style.display = null;
this.scroller.classList.add("h-full");
this.scroller.style.minHeight = null;
this.images.forEach((img) => {
const srcset = img.getAttribute("srcset_old");
img.setAttribute("srcset", srcset);
img.setAttribute("srcset_old", "");
});
}
}

Expand Down Expand Up @@ -202,7 +215,9 @@ function getData() {
);
const data = {
main: document.querySelector("main").outerHTML,
css: `${globalCss} ${localCss}`,
// css: `${globalCss} /* GLOBAL-LOCAL */ ${localCss}`,
globalCss,
localCss,
};
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "ChatGPT Download",
"description": "Download a PNG or PDF of your chat with ChatGPT",
"version": "1.0.0",
"version": "1.1.1",
"author": "Liad Yosef",
"icons": {
"48": "icons/48.png"
Expand Down

0 comments on commit 959eeec

Please sign in to comment.