This commit is contained in:
2025-05-11 18:58:43 +02:00
parent d5a73f342e
commit f3f3045ebf
48 changed files with 686 additions and 243 deletions

View File

@@ -0,0 +1,53 @@
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();