Skip to content

Instantly share code, notes, and snippets.

@curegit
Last active August 16, 2024 01:04
Show Gist options
  • Save curegit/2e2eebbec98d2f928ed1ca2ecc0f0f73 to your computer and use it in GitHub Desktop.
Save curegit/2e2eebbec98d2f928ed1ca2ecc0f0f73 to your computer and use it in GitHub Desktop.
LINE Theme をダウンロードするやつ
javascript: (async function () {
function validateThemeIdFormat(id) {
return /^[-a-z0-9]{6,}$/.test(id);
}
function buildThemeZipUri(id, version, platform) {
const subdir1 = id.substring(0, 2);
const subdir2 = id.substring(2, 4);
const subdir3 = id.substring(4, 6);
const baseuri = "https://stickershop.line-scdn.net/themeshop/v1/products";
return `${baseuri}/${subdir1}/${subdir2}/${subdir3}/${id}/${version}/${platform}/theme.zip`;
}
function downloadThemeZip(id, version, platform) {
const uri = buildThemeZipUri(id, version, platform);
const link = document.createElement("a");
console.table({ id, version, platform, uri });
link.href = uri;
link.download = `Theme-${id}-${version}-${platform}.zip`;
link.dispatchEvent(new MouseEvent("click"));
}
function getThemeIdFromUrl() {
const url = window.location.href;
const match = url.match(/\/themeshop\/product\/([-a-z0-9]{6,})\//);
return match ? match[1] : null;
}
const id = getThemeIdFromUrl();
if (!id || !validateThemeIdFormat(id)) {
alert("Invalid or missing package ID in URL");
return;
}
const ogImageMeta = document.querySelector('meta[property="og:image"]');
if (!ogImageMeta) {
alert("No og:image meta tag found");
return;
}
const ogImageUrl = ogImageMeta.getAttribute("content");
const versionMatch = ogImageUrl.match(/\/(\d+)\/WEBSTORE\//);
if (!versionMatch) {
alert("Version number not found in og:image URL");
return;
}
const version = versionMatch[1];
const platforms = ["ANDROID", "IOS"];
for (const platform of platforms) {
downloadThemeZip(id, version, platform);
await new Promise((r) => setTimeout(r, 1000));
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment