Last active
April 15, 2020 20:23
-
-
Save plurch/97d4a77c319c4b7ad3f2490e905c913a to your computer and use it in GitHub Desktop.
Readability Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function() { | |
function loadScript(url) { | |
const script = document.createElement("script"); | |
script.src = url; | |
document.head.appendChild(script); | |
return new Promise(function(resolve, reject) { | |
script.onload = resolve; | |
}); | |
} | |
await loadScript('https://cdn.jsdelivr.net/gh/mozilla/readability/Readability.js'); | |
const article = new Readability(document).parse(); | |
document.write(` | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>${article.title}</title> | |
<style> | |
body { | |
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol; | |
max-width: 800px; | |
margin: 0 auto; | |
font-size: 20px; | |
font-weight: 300; | |
line-height: 30px; | |
color: #24292e; | |
padding-left: 10px; | |
padding-right: 10px; | |
} | |
img { | |
max-width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<h2>${article.title}</h2> | |
<h3>${article.byline}</h3> | |
${article.content} | |
</body> | |
</html> | |
`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment