From 6a5f0709ff99f4db9b28c1b6bb74cbbf666964f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Sat, 30 Aug 2025 11:11:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=94=9A=E8=93=9D?= =?UTF-8?q?=E6=A1=A3=E6=A1=88=E8=A7=92=E8=89=B2=E5=9B=BE=E7=89=87=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- download-ba-character-img.js | 235 +++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 download-ba-character-img.js diff --git a/download-ba-character-img.js b/download-ba-character-img.js new file mode 100644 index 0000000..5e1aff1 --- /dev/null +++ b/download-ba-character-img.js @@ -0,0 +1,235 @@ +// +// 批量下载蔚蓝档案角色图 +// + +// URL: https://bluearchive.fandom.com/wiki/Category:Students +// 记得先滚动页面确保所有图片加载完成 + +// 已经下载的图片 +const isDownloaded = [ + "hoshino", + "shiroko", + "serika", + "nonomi", + "ayane", + "makoto", + "satsuki", + "chiaki", + "iroha", + "ibuki", + "hina", + "ako", + "iori", + "chinatsu", + "aru", + "mutsuki", + "kayoko", + "haruka", + "haruna", + "junko", + "izumi", + "akari", + "fuuka", + "juri", + "sena", + "kasumi", + "megu", + "kirara", + "rio", + "yuuka", + "noa", + "koyuki", + "chihiro", + "maki", + "hare", + "kotama", + "neru", + "karin", + "akane", + "asuna", + "toki", + "hibiki", + "utaha", + "kotori", + "sumire", + "rei", + "himari", + "eimi", + "alice", + "yuzu", + "midori", + "momoi", + "nagisa", + "seia", + "mika", + "kazusa", + "natsu", + "airi", + "yoshimi", + "suzumi", + "reisa", + "tsurugi", + "hasumi", + "mashiro", + "ichika", + "mine", + "hanae", + "serina", + "hifumi", + "azusa", + "koharu", + "hanako", + "ui", + "shimiko", + "sakurako", + "mari", + "hinata", + "niya", + "kaho", + "chise", + "tsubaki", + "mimori", + "kaede", + "nagusa", + "renge", + "kikyou", + "yukari", + "shizuko", + "pina", + "umika", + "michiru", + "izuna", + "tsukuyo", + "wakamo", + "kisaki", + "mina", + "shun", + "kokona", + "saya", + "rumi", + "reijo", + "cherino", + "tomoe", + "marina", + "minori", + "meru", + "momiji", + "nodoka", + "shigure", + "kanna", + "kirino", + "fubuki", + "miyako", + "saki", + "miyu", + "moe", + "saori", + "misaki", + "hiyori", + "atsuko", + "hikari", + "nozomi", + "aoba", + "miku", + "misaka-mikoto", + "shokuhou-misaki", + "saten-ruiko" +]; + +// 清洗链接 +function cleanImageUrl(url) { + // 使用正则表达式匹配并提取需要的部分 + const cleanedUrl = url.replace(/(\/scale-to-width-down\/\d+\?.*)$/, ''); + return cleanedUrl; +} + +// 生成图片名称 +function generateImageName(url) { + // 提取文件名部分 + const fileNameMatch = url.match(/\/([^\/]+)\.png/); + if (fileNameMatch && fileNameMatch[1]) { + // 转换为小写并替换下划线为短横线 + return fileNameMatch[1].toLowerCase().replace("_icon", "").replace(/_/g, "-"); + } + return null; +} + +const images = Array.from(document.querySelectorAll(".wds-tab__content.wds-is-current table.article-table.sortable.jquery-tablesorter td:first-child img")).map((item) => [ + cleanImageUrl(item.src), + generateImageName(item.src) +]); + +const existingNames = []; + +// 有角色服装版本的图标,过滤掉即可 +const filteredImages = images.filter((item) => { + const [url, name] = item; + + // "hoshino" "hoshino-swimsuit" + if (!name || existingNames.includes(name)) { + return false; + } + + const firstName = name.split("-")[0]; + if (name.includes("-") && firstName && existingNames.includes(firstName)) { + return false; + } + + existingNames.push(name); + return true; +}); + +// https://static.wikia.nocookie.net/blue-archive/images/d/de/Hoshino_Icon.png/revision/latest/scale-to-width-down/60?cb=20221128153020 + +// 自动下载图片的函数 +function downloadImages(imageArray) { + let index = 0; + + const downloadImage = async () => { + if (index >= imageArray.length) { + console.log("所有图片下载完成!"); + return; + } + + const [url, filename] = imageArray[index]; + console.log(`正在下载第 ${index + 1} 张图片: ${filename}.png`); + + try { + // 使用 fetch 下载图片 + const response = await fetch(url, { + headers: { + "accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", + "accept-encoding": "gzip, deflate, br, zstd", + } + }); + if (!response.ok) { + throw new Error(`无法下载图片: ${url}`); + } + + // 将图片数据转换为 Blob + const blob = await response.blob(); + + // 创建一个隐藏的 元素用于下载 + const a = document.createElement("a"); + const objectUrl = URL.createObjectURL(blob); // 创建 Blob 的临时 URL + a.href = objectUrl; + a.download = `${filename.replace("resonator-", "")}.webp`; // 指定下载的文件名 + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + + // 释放 Blob 的临时 URL + URL.revokeObjectURL(objectUrl); + } catch (error) { + console.error(`下载图片失败: ${error.message}`); + } + + index++; + setTimeout(downloadImage, 2000); // 每隔 2 秒下载下一张图片 + }; + + downloadImage(); +} + +// 调用函数开始下载 +downloadImages(filteredImages);