Skip to content

Instantly share code, notes, and snippets.

@mikeconley
Last active April 26, 2024 21:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeconley/1b7d382194b2f46bc34b975c60a4e730 to your computer and use it in GitHub Desktop.
Save mikeconley/1b7d382194b2f46bc34b975c60a4e730 to your computer and use it in GitHub Desktop.
// STEPS:
// 1: Make sure only the images you want are in the document (i.e., make a document with only the most recent headlines)
// 2: Scroll down to the bottom of that document to ensure Google Docs has lazy loaded all of the images
// 3: Run this in the console:
// ```
// copy(JSON.stringify([...document.querySelectorAll(".kix-canvas-tile-content image")].map(i => i.href.baseVal)))
// ```
// 4: Paste them in here:
let urls = [];
// 5: Increment this number to match the next Nightly blog post number:
let articleNumber = 75;
// 5: Run this file with node js in a directory where you want to output the images
// 6: Drag and drop them all into Wordpress uploads
const https = require("https");
const fs = require("fs");
const Buffer = require("buffer").Buffer;
(async function () {
for (let i = 0; i < urls.length; i++) {
let url = urls[i];
try {
console.log("Getting " + url);
let res = await new Promise((r, rej) => https.get(url, r).on("error", rej));
let wstream = fs.createWriteStream(`headlines${articleNumber}_${i}.png`);
await new Promise((r, rej) => {
const buf = Buffer.alloc(0);
res.on("data", data => wstream.write(data));
res.on("end", () => r());
res.on("error", e => rej(e));
});
wstream.end();
} catch (e) {
console.log("error!");
console.error(e);
}
}
})();
@mikeconley
Copy link
Author

This was originally written by Doug Thayer - just giving credit where it's due.

@amychurchwell
Copy link

google docs have changed the way they handle images. .kix-canvas-tile-content image is the new selector for line 6.

copy(JSON.stringify([...document.querySelectorAll(".kix-canvas-tile-content image")].map(i => i.href.baseVal)))

@mikeconley
Copy link
Author

Thanks, updated!

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