Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // How to use:
- // 1) Go to a chapter page on Comikey.
- // 2) Open the console (generally if you open "inspect element"
- // the browser console will be another tab of that).
- // 3) Paste this entire file into the console, and hit enter
- // 4) Type run() into the console, and hit enter.
- // 5) Navigate to another page of the chapter using the left
- // and right arrow keys or the slider bar. You should see
- // an alert telling you which page to go to.
- // 6) Repeat (4) and (5) until you see an alert which says
- // "Downloaded all pages".
- // 7) Use 7zip or a similar program to combine all of the
- // downloaded page image files into one zip file, then
- // rename the zip file to have the file extension ".cbz"
- // Update 2021-12-19: Fixed script to work on chapters that
- // use img tags instead of canvas tags (this was previously
- // an issue with webtoon-style continuous vertical chapters)
- var make_filename = function(page_name){
- return page_name.match(/\d/g).join('').padStart(4, "0");
- }
- var img_to_canvas = function(img){
- var c = document.createElement("canvas");
- c.width = img.getAttribute("width");
- c.height = img.getAttribute("height");
- var context = c.getContext('2d');
- context.drawImage(img, 0, 0);
- if (!context.getImageData(0, 0, 1, 1).data[3]) {
- return null;
- }
- return c;
- }
- var download = function(page){
- page_name = page.getAttribute("aria-label");
- var link = document.createElement('a');
- link.download = make_filename(page_name) + ".png";
- if (page.nodeName == "IMG") {
- page = img_to_canvas(page);
- if (!page) {
- return false;
- }
- }
- link.href = page.toDataURL("image/png");
- link.click();
- return true;
- }
- var grab_first = function(iterable) {
- return iterable.values().next().value;
- }
- var is_ready_page = function(page) {
- if (page.nodeName == "CANVAS") {
- return (page.getAttribute("width") && page.getAttribute("height"));
- } else if (page.nodeName == "IMG") {
- return (page.getAttribute("src") && page.getAttribute("src").startsWith("blob:"));
- } else {
- return false;
- }
- }
- if (typeof my_pages === 'undefined' || my_pages === null) {
- var my_pages = new Set(document.querySelectorAll("img.page-img, canvas.page-img"));
- if (my_pages.size === 0) {
- alert("No pages found")
- }
- }
- var run = function(){
- if (my_pages.size === 0) {
- alert("You have already downloaded all pages");
- return;
- }
- new_pages = new Set(my_pages)
- for (page of my_pages) {
- if (is_ready_page(page)) {
- var rtn = download(page);
- if (rtn) {
- new_pages.delete(page);
- }
- }
- }
- my_pages = new_pages
- if (my_pages.size === 0) {
- alert("Downloaded all pages")
- } else {
- alert("Remaining pages: " + my_pages.size + " pages, including: " + grab_first(my_pages).getAttribute("aria-label"))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement