// ==UserScript==
// @name ChatGPT to PDF by PDFCrowd
// @namespace http://tampermonkey.net/
// @version 1.28
// @description Turn your chats into neatly formatted PDF.
// @author PDFCrowd (https://pdfcrowd.com/)
// @match https://chatgpt.com/*
// @match https://chat.com/*
// @icon64 https://github.com/pdfcrowd/save-chatgpt-as-pdf/raw/master/icons/icon64.png
// @run-at document-end
// @grant GM_xmlhttpRequest
// @connect api.pdfcrowd.com
// @license MIT
// @downloadURL https://update.greasyfork.icu/scripts/484463/ChatGPT%20to%20PDF%20by%20PDFCrowd.user.js
// @updateURL https://update.greasyfork.icu/scripts/484463/ChatGPT%20to%20PDF%20by%20PDFCrowd.meta.js
// ==/UserScript==
/* globals pdfcrowdChatGPT */
// do not modify or delete the following line, it serves as a placeholder for
// the common.js contents which is copied here by "make build-userscript-single-file"
//
// shared.js placeholder
'use strict';
const pdfcrowdShared = {};
pdfcrowdShared.defaultOptions = {
margins: '',
theme: '',
zoom: 100,
no_questions: false,
q_color: 'default',
q_color_picker: '#ecf9f2',
q_fg_color: 'default',
q_fg_color_picker: '#000',
title_mode: '',
margin_left: '0.4in',
margin_right: '0.4in',
margin_top: '0.4in',
margin_bottom: '0.4in',
page_break: '',
toc: '',
no_icons: false,
model_name: false
}
pdfcrowdShared.version = 'v1.28';
pdfcrowdShared.rateUsLink = '#';
pdfcrowdShared.hasOptions = true;
if (typeof GM_info !== 'undefined') {
pdfcrowdShared.rateUsLink = 'https://greasyfork.org/en/scripts/484463-save-chatgpt-as-pdf/feedback#post-discussion';
pdfcrowdShared.hasOptions = false;
} else if (navigator.userAgent.includes('Edg/')) {
pdfcrowdShared.rateUsLink = 'https://microsoftedge.microsoft.com/addons/detail/save-chatgpt-as-pdf/fjlfcopnobjbkjiclieaopipchijelmj';
} else if (navigator.userAgent.includes("Chrome")) {
pdfcrowdShared.rateUsLink = 'https://chromewebstore.google.com/detail/save-chatgpt-as-pdf/ccjfggejcoobknjolglgmfhoeneafhhm/reviews';
} else if (navigator.userAgent.includes("Firefox")) {
pdfcrowdShared.rateUsLink = 'https://addons.mozilla.org/en-US/firefox/addon/save-chatgpt-as-pdf/reviews/';
}
pdfcrowdShared.helpContent = `
Support
Feel free to contact us with any questions or for assistance. We're always happy to help!
Email us at
support@pdfcrowd.com or use our
contact form.
Note
All generated PDFs include a banner which cannot be removed.
Purchasing a PDFCrowd license does not remove the banner.
Tips
-
You can download a specific part of the chat by selecting it.
-
If images are missing in the PDF, reload the page and try downloading the PDF again.
-
Customize the PDF file via addon
options.
`;
pdfcrowdShared.getOptions = function(callback) {
if(typeof chrome === 'undefined') {
callback(pdfcrowdShared.defaultOptions);
} else {
try {
chrome.storage.sync.get('options', function(obj) {
let rv = {};
Object.assign(rv, pdfcrowdShared.defaultOptions);
if(obj.options) {
Object.assign(rv, obj.options);
}
callback(rv);
});
} catch(error) {
console.error(error);
callback(pdfcrowdShared.defaultOptions);
}
}
}
function init() {
let elem = document.getElementById('version');
if(elem) {
elem.innerHTML = pdfcrowdShared.version;
}
elem = document.getElementById('help');
if(elem) {
elem.innerHTML = pdfcrowdShared.helpContent;
}
}
document.addEventListener('DOMContentLoaded', init);
// common.js placeholder
const pdfcrowdChatGPT = {};
pdfcrowdChatGPT.pdfcrowdAPI = 'https://api.pdfcrowd.com/convert/24.04/';
pdfcrowdChatGPT.username = 'chat-gpt';
pdfcrowdChatGPT.apiKey = '29d211b1f6924c22b7a799b4e8fecb7e';
pdfcrowdChatGPT.init = function() {
if(document.querySelectorAll('.pdfcrowd-convert').length > 0) {
// avoid double init
return;
}
// remote images live at least 1 minute
const minImageDuration = 60000;
const buttonIconFill = (typeof GM_xmlhttpRequest !== 'undefined')
? '#A72C16' : '#EA4C3A';
const blockStyle = document.createElement('style');
blockStyle.textContent = `
.pdfcrowd-block {
position: fixed;
height: 36px;
top: 10px;
right: 180px;
}
@media (max-width: 767px) {
.pdfcrowd-lg {
display: none;
}
.pdfcrowd-sm {
display: block;
}
}
.pdfcrowd-lg {
display: block;
}
.pdfcrowd-sm {
display: none;
}
.pdfcrowd-btn-smaller .pdfcrowd-lg {
display: none;
}
.pdfcrowd-btn-smaller .pdfcrowd-sm {
display: block;
}
.pdfcrowd-btn-smallest .pdfcrowd-lg, .pdfcrowd-btn-smallest .pdfcrowd-sm {
display: none;
}
.pdfcrowd-btn-xs-small .pdfcrowd-lg, .pdfcrowd-btn-xs-small .pdfcrowd-sm {
display: none;
}
.pdfcrowd-btn-xs-small .btn-small {
background: none;
border: none;
}
.pdfcrowd-btn-xs-small svg {
margin: 0;
}
svg.pdfcrowd-btn-content {
width: 1rem;
height: 1rem;
}
#pdfcrowd-convert-main {
padding-right: 0;
}
#pdfcrowd-convert-main:disabled {
cursor: wait;
filter: none;
opacity: 1;
}
.pdfcrowd-dropdown-arrow::after {
display: inline-block;
width: 0;
height: 0;
vertical-align: .255em;
content: "";
border-top: .3em solid;
border-right: .3em solid transparent;
border-bottom: 0;
border-left: .3em solid transparent;
}
.pdfcrowd-fs-small {
font-size: .875rem;
}
#pdfcrowd-more {
cursor: pointer;
padding: .5rem;
border-top-right-radius: .5rem;
border-bottom-right-radius: .5rem;
}
#pdfcrowd-more:hover {
background-color: rgba(0,0,0,.1);
}
#pdfcrowd-extra-btns {
border: 1px solid rgba(0,0,0,.1);
background-color: #fff;
color: #000;
}
.pdfcrowd-extra-btn:hover {
background-color: rgba(0,0,0,.1);
}
.pdfcrowd-extra-btn {
width: 100%;
text-align: start;
display: block;
}
.pdfcrowd-hidden {
display: none;
}
#pdfcrowd-spinner {
position: absolute;
width: 100%;
height: 100%;
}
.pdfcrowd-spinner {
border: 4px solid #ccc;
border-radius: 50%;
border-top: 4px solid #ffc107;
width: 1.5rem;
height: 1.5rem;
-webkit-animation: spin 1.5s linear infinite;
animation: spin 1.5s linear infinite;
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.pdfcrowd-invisible {
visibility: hidden;
}
.pdfcrowd-overlay {
z-index: 10000;
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
color: #000;
}
.pdfcrowd-dialog {
background: #fff;
padding: 0;
margin: 0.5em;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
text-align: start;
}
.pdfcrowd-dialog a {
color: revert;
}
.pdfcrowd-dialog-body {
padding: 0 2em;
line-height: 2;
}
.pdfcrowd-dialog-footer {
text-align: center;
margin: .5em;
position: relative;
}
.pdfcrowd-dialog-header {
background-color: #eee;
font-size: 1.25em;
padding: .5em;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.pdfcrowd-help-content {
max-width: 660px;
}
.pdfcrowd-version {
position: absolute;
bottom: 0;
right: 0;
font-size: .65em;
color: #777;
}
.pdfcrowd-dialog ul {
list-style: disc;
margin: 0;
padding: 0 0 0 2em;
}
.pdfcrowd-close-x {
cursor: pointer;
float: right;
color: #777;
}
#pdfcrowd-help {
cursor: pointer;
}
.pdfcrowd-py-1 {
padding-bottom: 0.25rem;
padding-top: 0.25rem;
}
.pdfcrowd-px-2 {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.pdfcrowd-mr-1 {
margin-right: 0.25rem;
}
.pdfcrowd-mr-4 {
margin-right: 1rem;
}
.pdfcrowd-justify-center {
justify-content: center;
}
.pdfcrowd-items-center {
align-items: center;
}
.pdfcrowd-flex {
display: flex;
}
.pdfcrowd-text-left {
text-align: left;
}
.pdfcrowd-text-right {
text-align: right;
}
.pdfcrowd-h-9 {
height: 2.25rem;
}
#pdfcrowd-title {
margin-top: 1em !important;
margin-bottom: .5em !important;
padding: .5em !important;
border: revert !important;
visibility: revert !important;
display: revert !important;
color: revert !important;
background: revert !important;
width: 360px;
border-radius: 5px;
}
.pdfcrowd-category {
line-height: normal;
margin-top: 1em;
}
.pdfcrowd-category-title {
font-size: larger;
font-weight: bold;
}
`;
document.head.appendChild(blockStyle);
const pdfcrowdBlockHtml = `
' +
getModelName(model_el) +
'
';
}
}
const direction = document.documentElement.getAttribute(
'dir') || 'ltr';
data.text = `