236 lines
4.5 KiB
JavaScript
236 lines
4.5 KiB
JavaScript
//
|
|
// 批量下载蔚蓝档案角色图
|
|
//
|
|
|
|
// 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();
|
|
|
|
// 创建一个隐藏的 <a> 元素用于下载
|
|
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);
|