Skip to content

Instantly share code, notes, and snippets.

@stuartsaunders
Forked from jesstelford/01-shape-up-to-kindle.md
Created September 9, 2020 17:32
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 stuartsaunders/c675836089f1f594b01ca07feb0b1b78 to your computer and use it in GitHub Desktop.
Save stuartsaunders/c675836089f1f594b01ca07feb0b1b78 to your computer and use it in GitHub Desktop.
Read SHAPE UP by basecamp in a single page or on a Kindle

Read Shape Up by basecamp in a single page

Basecamp's new book Shape Up is now available online (https://basecamp.com/shapeup) to read page-by-page.

To read it all in a single page:

  1. Go to the first chapter: https://basecamp.com/shapeup/0.1-foreword
  2. In the URL bar, type javascript:
  3. Paste in this single line of JavaScript (so the URL bar looks like javascript:var style=do...)
var style=document.createElement('style');document.head.appendChild(style);style.sheet.insertRule('main {grid-template-areas: "header" "sidebar" "content" "footer" !important; grid-template-columns: auto !important;}');document.querySelector('main').setAttribute('data-new',!0);function loadNext(){const nextPageLink=document.querySelector('main[data-new] .intro__next a');const nextPage=nextPageLink&&nextPageLink.href;['main[data-new] .intro__book-title.button','main[data-new] .pagination','main[data-new] footer','main[data-new] .warning','main[data-new] template','main[data-new] nav','a.pop','main[data-new] .intro__sections','main[data-new] .intro__next'].forEach(selector=>{const els=document.querySelectorAll(selector);els.forEach(el=>el.parentElement.removeChild(el))});document.querySelector('main[data-new]').removeAttribute('data-new');if(nextPageLink){console.log('loading '+nextPage);fetch(nextPage.replace(/\/$/,'')).then(res=>res.text()).then(res=>document.body.insertAdjacentHTML('beforeend',res.replace(/^[\s\S]+<main/m,'<main data-new').replace(/<\/main>[\s\S]+/m,'</main>'))).then(loadNext)}else{alert('done.')}};loadNext()
  1. Hit enter & wait for it to say "done."
  2. Enjoy the entire book in a single page.

NOTE: The unminified source is below

Reading on your Kindle

After converting to a single page, use Amazon's Send To Kindle browser extension to send a complete copy of the book to your kindle for reading later: https://www.amazon.com/gp/sendtokindle

var style = document.createElement('style');
document.head.appendChild(style);
style.sheet.insertRule('main {grid-template-areas: "header" "sidebar" "content" "footer" !important; grid-template-columns: auto !important;}');
document.querySelector('main').setAttribute('data-new', true);
function loadNext() {
const nextPageLink = document.querySelector('main[data-new] .intro__next a');
const nextPage = nextPageLink && nextPageLink.href;
['main[data-new] .intro__book-title.button', 'main[data-new] .pagination', 'main[data-new] footer', 'main[data-new] .warning', 'main[data-new] template', 'main[data-new] nav', 'a.pop', 'main[data-new] .intro__sections', 'main[data-new] .intro__next'].forEach(selector => { const els = document.querySelectorAll(selector); els.forEach(el => el.parentElement.removeChild(el))});
document.querySelector('main[data-new]').removeAttribute('data-new');
if (nextPageLink) {
console.log('loading ' + nextPage);
fetch(nextPage.replace(/\/$/, '')).then(res => res.text()).then(res => document.body.insertAdjacentHTML('beforeend', res.replace(/^[\s\S]+<main/m, '<main data-new').replace(/<\/main>[\s\S]+/m, '</main>'))).then(loadNext);
} else {
alert('done.');
}
}
loadNext();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment