Skip to content

Instantly share code, notes, and snippets.

@GiovanniMoretti
Forked from eimfach/bookmarklet.js
Last active April 10, 2019 22:16
Show Gist options
  • Save GiovanniMoretti/289c541c70fc57251ae41d34ee4a4d12 to your computer and use it in GitHub Desktop.
Save GiovanniMoretti/289c541c70fc57251ae41d34ee4a4d12 to your computer and use it in GitHub Desktop.
medium.com print bookmarklet
javascript:(function(){
var iframes = document.getElementsByTagName('iframe');
for(var i = 0; i < iframes.length; i++)
{iframes[i].width = "auto"; }
var content="@media print { img {max-width: 640px !important;} iframe { width: auto; display: block; } .section-inner.sectionLayout--insetColumn { max-width: 1024px !important; padding: padding: 0px 0px !important; } }";
var style = document.createElement('style');
style.appendChild(document.createTextNode(content));
document.getElementsByTagName('head')[0].appendChild(style);
alert("Print stylesheet tweaked - use 'File/Print Preview' to check");
})();
@GiovanniMoretti
Copy link
Author

GiovanniMoretti commented Apr 10, 2019

This is a bookmarklet to increase the width of what's printed for posts from Medium.com, otherwise there's a narrow colum of text in the middle of the page with huge amount of whitespace on the left and right. This becomes a real problem with posts that have lots of technical and source code.

I've tweaked Marcin's code (https://medium.com/@eimfach/i-wrote-a-bookmarklet-for-printing-articles-81c2e7a9e8a9) by adding

  • javascript: to the beginning, otherwise Firefox refuses to save the bookmark, and
  • added an alert, so when you click the bookmark, it's clear that something's happened.

To use this, create a new bookmark (e.g. printMedium) and replace the URL for the site with the above code.

Later, when reading an article on Medium.com that you'd like to print, click the 'printMedium' bookmark. Apart from the pop-up, the page layout on the screen won't change but the script adds to the CSS stylesheet so the printed version of the page has much wider margins. For me, the printed text is a little small, so I set the print scaling to about 120% .

Thanks to Marcin for doing the 'heavy lifting' :-)

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