Skip to content

Instantly share code, notes, and snippets.

@soruly
Last active May 1, 2026 12:59
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 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 = await fetch("https://game.our-rails.ekimemo.com/api/backgrounds/start_game", {
headers: { Referer: "https://game.our-rails.ekimemo.com/" },
}).then((e) => e.json());
await fs.writeFile(
path.join(static_versions, "start_game.json"),
JSON.stringify(imageList, null, 2),
);
for (const { name_en, url } of imageList.contents.filter(
(e) => e.end_at !== "9999-07-01 15:00:00",
)) {
const filePath = path.join(static_versions, path.basename(url));
await fs.mkdir(path.dirname(filePath), { recursive: true });
if (
await fs
.access(filePath)
.then(() => true)
.catch(() => false)
) {
console.log(`${filePath} already exists, skipping download.`);
continue;
}
console.log(`Downloading ${name_en}`);
const response = await fetch(url, {
headers: { Referer: "https://game.our-rails.ekimemo.com/" },
});
if (!response.ok) {
console.error(`Failed to download ${name_en}: ${response.statusText}`);
continue;
}
await fs.writeFile(filePath, 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