Files
my-webtoon/Bomtoon_JS/bomtoon_canvas.js
2025-05-11 18:58:43 +02:00

53 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

async function downloadCanvasImages() {
let seenCanvases = new Set(); // 存储已经下载过的 Canvas避免重复下载
let lastScrollTop = 0;
while (true) {
console.log("🔽 正在下载当前屏幕的所有 Canvas...");
// 获取所有 <canvas> 并下载
document.querySelectorAll("canvas").forEach((canvas, index) => {
if (!seenCanvases.has(canvas)) { // 确保不重复下载
seenCanvases.add(canvas);
let imgData = canvas.toDataURL("image/webp"); // 转为 Base64 webp
let a = document.createElement("a");
a.href = imgData;
a.download = `${String(seenCanvases.size).padStart(3, "0")}.webp`; // 命名 001, 002, ...
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
console.log(`✅ 下载: ${a.download}`);
}
});
// 记录滚动前的位置
lastScrollTop = window.scrollY;
// 向下滚动 1 屏
window.scrollBy(0, window.innerHeight);
await new Promise(resolve => setTimeout(resolve, 3000)); // 等待 3 秒加载新 Canvas
// 如果滚动到底,停止执行
if (window.scrollY === lastScrollTop) {
console.log("🎉 已滚动到底,所有 Canvas 下载完成!");
break;
}
}
const div = document.querySelector('div.printView > div:not(style)');
const div2 = Array.from(div.children).filter(el => el.tagName.toLowerCase() === 'div')[1];
const div2_1_1_1 = div2.querySelector('div:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(1)');
const count = Array.from(div2_1_1_1.children).filter(el => {
return el.tagName.toLowerCase() === 'div' &&
el.hasAttribute('width') &&
el.hasAttribute('height');
}).length;
console.log("div2.1.1.1 下的 <div> 数量为:", count);
console.log(document.title);
}
// 运行脚本
downloadCanvasImages();