Skip to content

Instantly share code, notes, and snippets.

@AlexKott
Last active January 7, 2020 09:21
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexKott/ba43547cbc3f5171007de3eb434592fa to your computer and use it in GitHub Desktop.
Save AlexKott/ba43547cbc3f5171007de3eb434592fa to your computer and use it in GitHub Desktop.
Export links from Google Spaces
/*
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);
@blanvill
Copy link

blanvill commented Mar 9, 2017

Thanks! Great script!
This helped me:

USAGE:

  1. Place yourself on the space page you want to export (such as: https://spaces.google.com/space/XXXXXXXXXXXXXXX)
  2. Refresh the page (don't forget to do this)
  3. Paste the following script in the console run it
  4. Choose a location for the resulting file

Yours,
Christian.

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