Last active
January 7, 2020 09:21
-
-
Save AlexKott/ba43547cbc3f5171007de3eb434592fa to your computer and use it in GitHub Desktop.
Export links from Google Spaces
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
/* | |
Inspired by https://gist.github.com/daniele-rapagnani/2e7372210726b28aec8f0d2d1d149ffb | |
This script selects all links on a Google Spaces page with url, title and date. | |
Reload the page for every space and scroll down to the end (until it says | |
"The end is just a new beginning."). | |
Open the browser's console (right click -> inspect -> "Console") and paste these lines. | |
It then logs it to a HTML string which you can copy and save as "spaces-exports.html". | |
When changing to another service (e.g. Dropmark, Pocket ...) you can use the html file | |
to import all links from Spaces. | |
*/ | |
const linkArray = Array.from(document.querySelectorAll('.c1tmJe')); | |
const exportArray = linkArray.map(link => { | |
const linkObj = {}; | |
const videoElem = link.querySelector('.NMDTWd.CCxxof'); | |
if (videoElem) { | |
let videoUrl = videoElem.getAttribute('jsdata'); | |
const cutStart = videoUrl.indexOf('http'); | |
const cutEnd = videoUrl.lastIndexOf(';'); | |
videoUrl = videoUrl.substring(cutStart, cutEnd); | |
linkObj.url = videoUrl; | |
linkObj.title = link.querySelector('.ZD1Dee').innerText; | |
} else { | |
linkObj.url = link.querySelector('.b3n6fb').href; | |
linkObj.title = link.querySelector('.q9hwKf').innerText; | |
} | |
const dateString = link.querySelector('.StDPhd').innerText; | |
if (dateString.length < 5) { // '35m', '1h', .... | |
linkObj.date = new Date(); | |
} else { | |
linkObj.date = new Date(dateString); | |
} | |
return linkObj; | |
}); | |
// build HTML | |
let html = '<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Google Spaces Export File</title></head><body><ul>'; | |
exportArray.forEach(exp => { | |
html += `<li><a href="${exp.url}" time_added="${exp.date.getTime()}">${exp.title}</a></li>`; | |
}); | |
html += '</ul></body></html>'; | |
console.log(html); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Great script!
This helped me:
USAGE:
Yours,
Christian.