Skip to content

Instantly share code, notes, and snippets.

@soruly
Last active September 25, 2025 17:57
Show Gist options
  • Select an option

  • Save soruly/afbddd77c5c1bb71c0988f5d564287a9 to your computer and use it in GitHub Desktop.

Select an option

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";
import * as prettier from "prettier";
const html = await fetch("https://game.our-rails.ekimemo.com/top/").then((e) => e.text());
const static_versions = html.match(/<script.* src=".*\/v=([^/]+)\/.*app\.js">/)[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-prettier.js"))
.then(() => true)
.catch(() => false)
) {
jsText = await fs.readFile(path.join(static_versions, "app-prettier.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);
jsText = await prettier.format(jsText, { parser: "babel", trailingComma: "none" });
await fs.writeFile(path.join(static_versions, "app-prettier.js"), jsText);
}
const imageList = JSON.parse(jsText.match(/pwa:\s*({[^}]+})/)[1]);
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