Skip to content

Instantly share code, notes, and snippets.

@mitry
Last active February 8, 2025 15:34
Show Gist options
  • Select an option

  • Save mitry/59d5d6f12cb787e90175b2de97ff5eec to your computer and use it in GitHub Desktop.

Select an option

Save mitry/59d5d6f12cb787e90175b2de97ff5eec to your computer and use it in GitHub Desktop.
Bookmarklet: save webpage as clean Markdown file.
javascript:
!function(){
const
base64 = x => btoa(unescape(encodeURIComponent(x))),
onload = x => {
if (!Readability || !TurndownService) return;
const content = new Readability(document.cloneNode(true)).parse().content,
text = new TurndownService().turndown(content)
+ `\n\n[original]: ${document.location.href} "${document.title}"\n`,
link = document.createElement('a');
link.href = `data:text/markdown;base64,${base64(text)}`;
link.download = document.title.replace(/\s+/g,'-') + '.md';
document.body.appendChild(link).click();
},
require = x => document.head.append(Object.assign(document.createElement('script'),{src:x,onload:onload}));
require('//cdn.jsdelivr.net/npm/@mozilla/readability/Readability.min.js');
require('//cdn.jsdelivr.net/npm/turndown/dist/turndown.min.js');
}()
@mitry
Copy link
Author

mitry commented Feb 8, 2025

Minified version:

javascript:!function(){const ll=x=>{if(!Readability||!TurndownService)return;const e=new Readability(document.cloneNode(!0)).parse().content,t=(new TurndownService).turndown(e)+`\n\n[original]: ${document.location.href} "${document.title}"\n`,d=document.createElement("a");d.href=`data:text/markdown;base64,${btoa(unescape(encodeURIComponent(t)))}`,d.download=document.title.replace(/\s+/g,"-")+".md",document.body.appendChild(d).click()},req=x=>document.head.append(Object.assign(document.createElement("script"),{src:x,onload:ll}));req("//cdn.jsdelivr.net/npm/@mozilla/readability/Readability.min.js"),req("//cdn.jsdelivr.net/npm/turndown/dist/turndown.min.js")}()

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