Skip to content

Instantly share code, notes, and snippets.

@peccu
Last active April 18, 2023 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peccu/27c6d8833276077b8684b60394e5eeb8 to your computer and use it in GitHub Desktop.
Save peccu/27c6d8833276077b8684b60394e5eeb8 to your computer and use it in GitHub Desktop.
EpubPress bookmarklet
const onload = ()=>{
const EpubPress = window.EpubPress;
const ebook = new EpubPress({
title: document.title,
description: 'generated by EpubPress', // TODO Pick from meta tag
urls: [location.href]
});
alert('Please wait to start downloading');
ebook.publish().then(() =>{
ebook.download(); // Default epub
// or ebook.email('epubpress@gmail.com')
}).then(() => {
alert('Success!');
}).catch((error) => {
alert(`Error: ${error}`);
});
};
const onerror = ()=>{
const fallback = '';
const url = `${fallback}?title=${document.title}&url=${location.href}`;
window.open(url)
};
const s = document.createElement('script');
s.src = 'https://cdn.jsdelivr.net/npm/epub-press-js@0.5.3/build/index.min.js';
s.onload = onload;
s.onerror = onerror;
document.body.appendChild(s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment