Skip to content

Instantly share code, notes, and snippets.

@geor-kasapidi
Last active May 12, 2024 12:43
Show Gist options
  • Save geor-kasapidi/276c3258ad40c7888951a5cd6be68a25 to your computer and use it in GitHub Desktop.
Save geor-kasapidi/276c3258ad40c7888951a5cd6be68a25 to your computer and use it in GitHub Desktop.
mangalib script to download images and open next chapter
// ==UserScript==
// @name MangaLib - Auto Download and Navigate
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Automatically download content and navigate to the next page
// @author Geor Kasapidi
// @match https://mangalib.org/*
// @grant none
// ==/UserScript==
(async function() {
'use strict';
// Ensure the required variables are present
if (typeof window.__pg === 'undefined' || typeof window.__info === 'undefined') {
console.error('Required variables are not defined on this page.');
return;
}
await new Promise(r => setTimeout(r, 100));
// Iterate through the pages and download content
for (const page of window.__pg) {
try {
const blob = await fetch(window.__info.servers[window.__info.img.server] + window.__info.img.url + page.u)
.then(res => res.blob());
const blobUrl = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = blobUrl;
a.download = window.__info.current.number + '_' + page.p + '.' + page.u.split('.').pop();
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
await new Promise(r => setTimeout(r, 20));
} catch (error) {
console.error('Error downloading:', error);
}
}
// Navigate to the next page
if (window.__info.next && window.__info.next.url) {
await new Promise(r => setTimeout(r, 500));
window.location.href = window.__info.next.url;
} else {
console.error('Next page URL is not defined.');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment