Skip to content

Instantly share code, notes, and snippets.

@sanjarcode
Last active April 9, 2023 20:44
Show Gist options
  • Save sanjarcode/6afba1b090e5b84336b273399efeab39 to your computer and use it in GitHub Desktop.
Save sanjarcode/6afba1b090e5b84336b273399efeab39 to your computer and use it in GitHub Desktop.
ChatGPT tips n tricks
/* Instructions
1. Setup print preferences: Press Ctrl + P on any website. Enable headers + footers, background graphics, and set margin to custom (set all to 0, except the top, set it to 0.5mm using the mouse)
2. Copy and paste this file into the console
*/
// copied from https://github.com/liady/ChatGPT-pdf
class Elements {
constructor() {
this.init();
}
init() {
// this.threadWrapper = document.querySelector(".cdfdFe");
this.spacer = document.querySelector(
".w-full.h-32.md\\:h-48.flex-shrink-0"
);
this.thread = document.querySelector(
"[class*='react-scroll-to-bottom']>[class*='react-scroll-to-bottom']>div"
);
this.positionForm = document.querySelector("form").parentNode;
// this.styledThread = document.querySelector("main");
// this.threadContent = document.querySelector(".gAnhyd");
this.scroller = Array.from(
document.querySelectorAll('[class*="react-scroll-to"]')
).filter((el) => el.classList.contains("h-full"))[0];
this.hiddens = Array.from(document.querySelectorAll(".overflow-hidden"));
this.images = Array.from(document.querySelectorAll("img[srcset]"));
}
fixLocation() {
this.hiddens.forEach((el) => {
el.classList.remove("overflow-hidden");
});
this.spacer.style.display = "none";
this.thread.style.maxWidth = "960px";
this.thread.style.marginInline = "auto";
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", "");
});
//Fix to the text shifting down when generating the canvas
document.body.style.lineHeight = "0.5";
}
restoreLocation() {
this.hiddens.forEach((el) => {
el.classList.add("overflow-hidden");
});
this.spacer.style.display = null;
this.thread.style.maxWidth = null;
this.thread.style.marginInline = null;
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", "");
});
document.body.style.lineHeight = null;
}
print() {
window.print();
}
}
const elements = new Elements();
elements.fixLocation();
elements.print();
elements.restoreLocation();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment