Skip to content

Instantly share code, notes, and snippets.

@SleepingInsomniac
Created April 11, 2023 15:54
Show Gist options
  • Select an option

  • Save SleepingInsomniac/db218962cef2080c69df85ad2e27693c to your computer and use it in GitHub Desktop.

Select an option

Save SleepingInsomniac/db218962cef2080c69df85ad2e27693c to your computer and use it in GitHub Desktop.
Safari bookmark script to download a chatGPT chat
javascript:(function() {
var chatgptContent = document.querySelector('main > div > div > div').innerHTML;
var pageTitle = document.title.replace(/[^a-zA-Z0-9\s]/g, "").replace(/\s+/g, "_");
var styles = '';
for (var i = 0; i < document.styleSheets.length; i++) {
var styleSheet = document.styleSheets[i];
try {
if (styleSheet.cssRules) {
for (var j = 0; j < styleSheet.cssRules.length; j++) {
styles += styleSheet.cssRules[j].cssText;
}
}
} catch (e) {
console.log('Error: Unable to load CSS rules from ' + styleSheet.href);
}
}
var htmlContent = '<html><head><title>' + pageTitle + '</title><style>' + styles + '</style></head><body>' + chatgptContent + '</body></html>';
var blob = new Blob([htmlContent], {type: 'text/html;charset=utf-8'});
var link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = pageTitle + '.html';
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment