Skip to content

Instantly share code, notes, and snippets.

@0wwafa
Created February 26, 2025 02:24
Show Gist options
  • Save 0wwafa/f0bc5c09e47b93f94da6b76890e62e41 to your computer and use it in GitHub Desktop.
Save 0wwafa/f0bc5c09e47b93f94da6b76890e62e41 to your computer and use it in GitHub Desktop.
PRINT / EXPORT Grok to PDF

To print a GROK chat, paste this code in javascript console:

(function() {
    var a = document.querySelector("body > div > div").children[0].children[1].children[0];
    if (a) {
        const b = window.open("", "_blank", `width=${.85 * window.screen.width},height=${.85 * window.screen.height},left=${.075 * window.screen.width},top=${.045 * window.screen.height}`)
          , e = Array.from(document.styleSheets).map(c => {
            try {
                return Array.from(c.cssRules).map(d => d.cssText).join("\n")
            } catch (d) {
                return console.error("Error occurred while getting stylesheet rules", d),
                ""
            }
        }
        ).join("\n");
        b.document.write("<html><head><title>Grok_" + (new Date).getTime() + "</title>");
        b.document.write("<style>" + e + "</style>");
        b.document.write("</head><body>");
        b.document.write(a.innerHTML);
        b.document.write("</body></html>");
        setTimeout(b.print.bind(b), 3E3)
    } else
        console.error("Central part not found!")
}
)()

Alternatively, save a bookmark called "Print Grok" with the following code:

javascript:(function(){var a=document.querySelector("body > div > div").children[0].children[1].children[0];if(a){const b=window.open("","_blank",`width=${.85*window.screen.width},height=${.85*window.screen.height},left=${.075*window.screen.width},top=${.045*window.screen.height}`),e=Array.from(document.styleSheets).map(c=>{try{return Array.from(c.cssRules).map(d=>d.cssText).join("\n")}catch(d){return console.error("Error occurred while getting stylesheet rules",d),""}}).join("\n");b.document.write("<html><head><title>Grok_"+(new Date).getTime()+"</title>"),b.document.write("<style>"+e+"</style>"),b.document.write("</head><body>"),b.document.write(a.innerHTML),b.document.write("</body></html>"),setTimeout(b.print.bind(b),3E3)}else console.error("Central part not found!")})()

Enjoy.

Note: If you want also the thinking to be printed, click on the thinking box before executing the bookmarklet (or the function).

@jrmessias
Copy link

To print a GROK chat, paste this code in javascript console:

(function() {
    var a = document.querySelector("body > div.flex > div").children[0].children[1].children[0];
    if (a) {
        const b = window.open("", "_blank", `width=${.85 * window.screen.width},height=${.85 * window.screen.height},left=${.075 * window.screen.width},top=${.045 * window.screen.height}`)
          , e = Array.from(document.styleSheets).map(c => {
            try {
                return Array.from(c.cssRules).map(d => d.cssText).join("\n")
            } catch (d) {
                return console.error("Error occurred while getting stylesheet rules", d),
                ""
            }
        }
        ).join("\n");
        b.document.write("<html><head><title>Grok_" + (new Date).getTime() + "</title>");
        b.document.write("<style>" + e + "</style>");
        b.document.write("</head><body>");
        b.document.write(a.innerHTML);
        b.document.write("</body></html>");
        setTimeout(b.print.bind(b), 3E3)
    } else
        console.error("Central part not found!")
}
)()

Alternatively, save a bookmark called "Print Grok" with the following code:

javascript:(function(){var a=document.querySelector("body > div.flex > div").children[0].children[1].children[0];if(a){const b=window.open("","_blank",`width=${.85*window.screen.width},height=${.85*window.screen.height},left=${.075*window.screen.width},top=${.045*window.screen.height}`),e=Array.from(document.styleSheets).map(c=>{try{return Array.from(c.cssRules).map(d=>d.cssText).join("\n")}catch(d){return console.error("Error occurred while getting stylesheet rules",d),""}}).join("\n");b.document.write("<html><head><title>Grok_"+(new Date).getTime()+"</title>"),b.document.write("<style>"+e+"</style>"),b.document.write("</head><body>"),b.document.write(a.innerHTML),b.document.write("</body></html>"),setTimeout(b.print.bind(b),3E3)}else console.error("Central part not found!")})()

Enjoy.

Note:
If you want also the thinking to be printed, click on the thinking box before executing the bookmarklet (or the function).

@zsyhd
Copy link

zsyhd commented Mar 25, 2025

Hello Could you please write a version of this script for ChatGPT as well? I really need it. Thank you so much in advance!

@jrmessias
Copy link

jrmessias commented Mar 26, 2025

Hello Could you please write a version of this script for ChatGPT as well? I really need it. Thank you so much in advance!

try this:

javascript:(function(){var a=document.querySelector("body main .relative.h-full");if(a){const b=window.open("","_blank",`width=${.85*window.screen.width},height=${.85*window.screen.height},left=${.075*window.screen.width},top=${.045*window.screen.height}`),e=Array.from(document.styleSheets).map(c=>{try{return Array.from(c.cssRules).map(d=>d.cssText).join("\n")}catch(d){return console.error("Error occurred while getting stylesheet rules",d),""}}).join("\n");b.document.write("<html><head><title>Grok_"+(new Date).getTime()+"</title>"),b.document.write("<style>"+e+"</style>"),b.document.write("</head><body>"),b.document.write(a.innerHTML),b.document.write("</body></html>"),setTimeout(b.print.bind(b),3E3)}else console.error("Central part not found!")})()

@zsyhd
Copy link

zsyhd commented Mar 26, 2025

Hello Could you please write a version of this script for ChatGPT as well? I really need it. Thank you so much in advance!

try this:

javascript:(function(){var a=document.querySelector("body main .relative.h-full");if(a){const b=window.open("","_blank",`width=${.85*window.screen.width},height=${.85*window.screen.height},left=${.075*window.screen.width},top=${.045*window.screen.height}`),e=Array.from(document.styleSheets).map(c=>{try{return Array.from(c.cssRules).map(d=>d.cssText).join("\n")}catch(d){return console.error("Error occurred while getting stylesheet rules",d),""}}).join("\n");b.document.write("<html><head><title>Grok_"+(new Date).getTime()+"</title>"),b.document.write("<style>"+e+"</style>"),b.document.write("</head><body>"),b.document.write(a.innerHTML),b.document.write("</body></html>"),setTimeout(b.print.bind(b),3E3)}else console.error("Central part not found!")})()

This is good, but I want the style, font, and CSS to be preserved. I always have a lot of formulas, and copying them takes time. I want to easily export them and be able to read the PDF or Do you also have the code for google AI Studio?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment