Skip to content

Instantly share code, notes, and snippets.

@soruly
Created July 1, 2025 15:25
Show Gist options
  • Save soruly/afbddd77c5c1bb71c0988f5d564287a9 to your computer and use it in GitHub Desktop.
Save soruly/afbddd77c5c1bb71c0988f5d564287a9 to your computer and use it in GitHub Desktop.
Download 駅メモ background images
#!/usr/bin/env node
import fs from "node:fs/promises";
import path from "node:path";
const html = await fetch("https://game.our-rails.ekimemo.com/top/").then((e) => e.text());
const static_versions = html.match(/<meta name="app:static_versions:image" content="([^"]+)"/)[1];
const static_origin = html.match(/<meta name="app:provider:static_origin" content="([^"]+)"/)[1];
const appJS = html.match(/<script src="([^"]+\/app.js)"><\/script>/)[1];
await fs.mkdir(path.join(static_versions), { recursive: true });
let jsText = "";
if (
await fs
.access(path.join(static_versions, "app.js"))
.then(() => true)
.catch(() => false)
) {
jsText = await fs.readFile(path.join(static_versions, "app.js"), "utf-8");
} else {
jsText = await fetch(appJS, {
headers: { Referer: "https://game.our-rails.ekimemo.com/" },
}).then((e) => e.text());
await fs.writeFile(path.join(static_versions, "app.js"), jsText);
}
const imageList = JSON.parse(jsText.match(/'pwa':({[^}]+})/)[1].replace(/'/g, '"'));
for (const [name, url] of Object.entries(imageList)) {
const fileName = path.join(static_versions, name);
await fs.mkdir(path.dirname(fileName), { recursive: true });
if (
await fs
.access(fileName)
.then(() => true)
.catch(() => false)
) {
console.log(`${fileName} already exists, skipping download.`);
continue;
}
console.log(`Downloading ${name}`);
const response = await fetch(`${static_origin}/v=${static_versions}${url}`, {
headers: { Referer: "https://game.our-rails.ekimemo.com/" },
});
if (!response.ok) {
console.error(`Failed to download ${name}: ${response.statusText}`);
continue;
}
await fs.writeFile(fileName, Buffer.from(await response.arrayBuffer()));
await new Promise((resolve) => setTimeout(resolve, 1000 + Math.random() * 1000));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment