Last active
December 11, 2021 19:53
-
-
Save grochowski/b0d4f5b847c53c3e7b8b7deb866a52e1 to your computer and use it in GitHub Desktop.
Export Medium Reading List to CSV
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
/** | |
* Export Medium Reading List to CSV | |
* Based on Imrat Jn article on Medium | |
* https://medium.com/@imrat/1-trick-inbox-zero-readinglist-86964bc55df3 | |
* added titles, links | |
* tested on Firefox 67 on Windows, should also work on Safari 11.1.2 | |
* | |
* Go to the reading list, scroll as far as you can (in order to load all the posts), | |
* Put this into your console | |
*/ | |
// Prepare output | |
var csv="title,link,datetime,readtime"; | |
// Get all posts | |
var posts=document.querySelectorAll('.streamItem'); | |
// Add line with post data to csv | |
posts.forEach(function(i,j) { | |
var title = i.querySelector('h3').firstChild.nodeValue; | |
var linkHref = i.querySelector('a.link').attributes.href.value; | |
var dateTimeItem = i.querySelector('time[datetime]'); | |
// Remove comma from Locale format so its compitable with Google Sheets format | |
var postTime = new Date(dateTimeItem.attributes.datetime.value).toLocaleString().replace(',',''); | |
// Get the readingTime through time parent node | |
var readingTime=dateTimeItem.parentNode.querySelector('.readingTime').title.replace(' min read',''); | |
// Add line | |
csv += "\n\""+title+"\",\""+linkHref+"\","+postTime+","+readingTime; | |
}); | |
// Function to download data to a file | |
// Source: https://stackoverflow.com/a/30832210 | |
function download(data, filename, type) { | |
var file = new Blob([data], {type: type}); | |
if (window.navigator.msSaveOrOpenBlob) // IE10+ | |
window.navigator.msSaveOrOpenBlob(file, filename); | |
else { // Others | |
var a = document.createElement("a"), | |
url = URL.createObjectURL(file); | |
a.href = url; | |
a.download = filename; | |
document.body.appendChild(a); | |
a.click(); | |
setTimeout(function() { | |
document.body.removeChild(a); | |
window.URL.revokeObjectURL(url); | |
}, 0); | |
} | |
} | |
// Download the data.csv file to default location | |
download(csv,"data.csv","text/csv") |
@ajmeese7 Thanks for letting me know! Changed to js to make it look right :)
Used it once for cleaning and never looked back, I'm glad it's useful (and still working, as I assume!)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you change the file extension to
.js
it will create syntax highlighting that make the code much easier to look at :)I know you created this a long time ago, but Google is still sending people to your Gist as one of the top results