// ==UserScript==
// @name Manhuagui - Recover Blocked Manga
// @namespace https://www.manhuagui.com/
// @version 0.2
// @description Recover blocked manga on www.manhuagui.com | 添加对 checkAdult 按钮的检测;localStorage的key添加ID用以区分不同的漫画作品
// @author DD1969
// @match https://www.manhuagui.com/comic/*/
// @match https://www.manhuagui.com/comic/*/*.html
// @require https://unpkg.com/axios@0.27.2/dist/axios.min.js
// @require https://unpkg.com/vanilla-lazyload@17.8.2/dist/lazyload.min.js
// @icon https://www.google.com/s2/favicons?sz=64&domain=manhuagui.com
// @grant none
// @downloadURL none
// ==/UserScript==
(async function(axios, LazyLoad) {
'use strict';
try {
// check if current comic/chapter is blocked
const isBlocked = await axios.get(window.location.href).then(res => res.data.match(/erroraudit_show/) !== null && res.data.match(/checkAdult/) === null);
if (!isBlocked) {
console.log('No need to recover.');
return;s
}
window.location.href.includes('.html') ? loadImages() : loadCatalog();
} catch (error) {
console.log(error);
}
async function loadCatalog() {
// setup container
const container = await getContainer();
container.classList.add('chapter-list');
container.innerHTML = '
';
const list = document.getElementById('recover-list');
// get comic id and latest chapter id
const latestChapterURL = document.querySelector('.detail-list .status a.blue').href;
const latestChapterData = await getChapterData(latestChapterURL);
const comicID = latestChapterData.bid;
let currentTargetID = latestChapterData.cid;
// store all collected chapter data
let chapterData = [];
// if there is data stored in localStorage before, get them and process
const storedChapterDataString = window.localStorage.getItem(`recovered-chapter-data-${comicID}`);
if (storedChapterDataString) {
const storedChapterData = JSON.parse(storedChapterDataString);
chapterData = [].concat(storedChapterData);
chapterData.forEach(data => {
const listItem = getListItem(data.url, data.title, data.pageAmount);
list.appendChild(listItem);
});
currentTargetID = chapterData[chapterData.length - 1].prevID;
}
// get chapter data with interval
const timer = setInterval(async () => {
if (currentTargetID === 0) {
clearInterval(timer);
console.log('All chapters are recovered.');
} else {
const currentChapterURL = `https://www.manhuagui.com/comic/${comicID}/${currentTargetID}.html`;
const { cname, len, prevId } = await getChapterData(currentChapterURL);
const listItem = getListItem(currentChapterURL, cname, len);
list.appendChild(listItem);
// update localStorage
chapterData.push({
url: currentChapterURL,
title: cname,
pageAmount: len,
prevID: prevId
});
window.localStorage.setItem(`recovered-chapter-data-${comicID}`, JSON.stringify(chapterData));
currentTargetID = prevId;
}
}, 10 * 1000); // 10 seconds per chapter
}
async function loadImages() {
// generate image urls
const imageURLs = await getChapterData(window.location.href).then(({ files, path, sl }) => {
const origin = 'https://us.hamreus.com';
return files.map(fileName => `${origin}${path}${fileName}?e=${sl.e}&m=${sl.m}`)
});
// load images
const container = await getContainer();
container.innerHTML = `${imageURLs.reduce((acc, cur) => {
return acc + `
`;
}, '')}`;
// setup image lazyload
new LazyLoad({ threshold: 900 });
}
// wait for the div element whose id is 'erroraudit_show' appear
async function getContainer() {
const container = await new Promise(resolve => {
const timer = setInterval(() => {
const errorAudit = document.getElementById('erroraudit_show');
if (errorAudit) {
clearInterval(timer);
resolve(errorAudit);
}
}, 100);
});
container.classList.remove('warning-bar');
container.id = 'recover-container';
return container;
}
// generate list item
function getListItem(href, title, pageAmount) {
const li = document.createElement('li');
li.innerHTML = `
${title}
${pageAmount}p
`;
return li;
}
// get episode data from