grajapa日本写真网 自动下载工具

grajapa 写真网 免去繁琐操作 一键下载所有图片

< Opiniones de grajapa日本写真网 自动下载工具

Puntuación: Pasable; el script funciona, pero tiene carencias importantes

§
Publicado: 22/06/2025

以下是利用AI修改的版本,延緩下載時間讓圖片順序變得正常


// ==UserScript==
// @name grajapa日本写真网 自动下载工具(微軟修正版 v0.7)
// @namespace http://tampermonkey.net/
// @version 0.7
// @description 自動命名壓縮檔與資料夾,補零命名,修正圖片順序錯亂
// @author hg542006810 + Microsoft Copilot
// @match https://www.grajapa.shueisha.co.jp/viewerV3_8/
// @icon https://www.google.com/s2/favicons?domain=shueisha.co.jp
// @grant GM_addStyle
// @require http://code.jquery.com/jquery-1.11.0.min.js
// @require https://cdn.bootcdn.net/ajax/libs/jszip/3.6.0/jszip.js
// @license MIT
// ==/UserScript==

(function () {
'use strict';

GM_addStyle(
'#grajapa_download{position: absolute; z-index: 10000; top: 100px; right: 400px; background: red;color: white;}'
);

const button = document.createElement('button');
button.id = 'grajapa_download';
button.textContent = '微軟修正版下載';
document.body.appendChild(button);

async function waitForImagesReady() {
return new Promise((resolve) => {
const check = () => {
let allReady = true;
$('.fixed-book-frame iframe').each(function () {
const images = $(this).contents().find('image');
if (images.length === 0) {
allReady = false;
return;
}
images.each(function () {
const href = $(this).attr('xlink:href');
if (!href || href.trim() === '') {
allReady = false;
}
});
});
if (allReady) {
resolve();
} else {
setTimeout(check, 300);
}
};
check();
});
}

async function getImages(index, sum, allImages) {
$('.list-group-item')[index].click();
await waitForImagesReady();

$('.fixed-book-frame').each(function () {
$(this)
.find('iframe')
.each(function () {
$(this)
.contents()
.find('image')
.each(function () {
const link = $(this).attr('xlink:href');
if (link && !allImages.includes(link)) {
allImages.push(link);
}
});
});
});

if (index + 1 < sum) {
return await getImages(index + 1, sum, allImages);
} else {
return allImages;
}
}

button.onclick = async () => {
const itemCount = $('.list-group-item').length;
if (itemCount === 0) {
alert('沒有找到圖片!');
return;
}

const images = await getImages(0, itemCount, []);
if (images.length === 0) {
alert('沒有找到圖片!');
return;
}

// 嘗試從標題中取得寫真集名稱
let title = document.title.trim().replace(/[\\/:*?"<>|]/g, '_') || 'photo';

const zip = new JSZip();
const img = zip.folder(title); // ✅ 自動命名資料夾

const digits = String(images.length - 1).length;

for (let i = 0; i < images.length; i++) {
const item = images[i];
const paddedName = String(i).padStart(digits, '0');

if (item.startsWith('data:image/jpeg;base64,')) {
img.file(paddedName + '.jpeg', item.replace('data:image/jpeg;base64,', ''), { base64: true });
} else if (item.startsWith('data:image/jpg;base64,')) {
img.file(paddedName + '.jpg', item.replace('data:image/jpg;base64,', ''), { base64: true });
} else if (item.startsWith('data:image/png;base64,')) {
img.file(paddedName + '.png', item.replace('data:image/png;base64,', ''), { base64: true });
}
}

zip
.generateAsync({ type: 'blob' })
.then(function (content) {
const a = document.createElement('a');
a.href = URL.createObjectURL(content);
a.download = title + '.zip'; // ✅ 自動命名壓縮檔
a.click();
})
.catch(function (err) {
alert('發生錯誤!' + err);
});
};
})();

Publicar respuesta

Inicia sesión para responder.

长期地址
遇到问题?请前往 GitHub 提 Issues。