Skip to content

Instantly share code, notes, and snippets.

@cayleyh
Last active April 27, 2019 22:10
Show Gist options
  • Save cayleyh/7aef5a7314225b031ea96368b6788b7f to your computer and use it in GitHub Desktop.
Save cayleyh/7aef5a7314225b031ea96368b6788b7f to your computer and use it in GitHub Desktop.
Simple bookmarklet to make Apple Docs, Wikipedia, etc. more readable
javascript:(function()%7Bvar%20css%20%3D%20'%23contents%2C%20%23bodyContent%2C%20.main.section%2C%20section%20%7Bmax-width%3A%2036em%3B%20margin%3A%201em%20auto%3B%20font-size%3A%20125%25%3B%7D%20p%20%7B%20line-height%3A%201.5em%3B%20%7D'%2Chead%20%3D%20document.head%20%7C%7C%20document.getElementsByTagName('head')%5B0%5D%2Cstyle%20%3D%20document.createElement('style')%3Bstyle.type%20%3D%20'text%2Fcss'%3Bif%20(style.styleSheet)%7Bstyle.styleSheet.cssText%20%3D%20css%3B%7D%20else%20%7Bstyle.appendChild(document.createTextNode(css))%3B%7Dhead.appendChild(style)%7D)()
@cayleyh
Copy link
Author

cayleyh commented Apr 12, 2016

Quick Readability Bookmarklet

Makes Wikipedia, Apple reference docs (eg. this), and some general web layouts easier to read by increasing font size & leading, and imposing a sane line width:

From This:
start

To This:
finish


Code:

// #contents - main container on Apple docs
// #bodyContent - main container on Wikipedia
// .main.section - Blogger
// section - covers generic cases :)
var css = '#contents, #bodyContent, .main.section, section {max-width: 36em; margin: 1em auto; font-size: 125%;} p { line-height: 1.5em; }',
    head = document.head || document.getElementsByTagName('head')[0],
    style = document.createElement('style');

style.type = 'text/css';
if (style.styleSheet){
  style.styleSheet.cssText = css;
} else {
  style.appendChild(document.createTextNode(css));
}
head.appendChild(style);

Code to insert stylesheet directly from http://stackoverflow.com/a/524721/4821759
Bookmarklet code generated with http://mrcoles.com/bookmarklet/

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