Last active
May 16, 2017 14:48
-
-
Save QQBoxy/a43457eb19b53c2089aafdf4f8726c3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateZip() { | |
$(".MangaPage img").each(function() { | |
var img = $(this); | |
var str = img.parent().prev().children("span").text(); | |
while (str.length < 3) str = '0' + str; | |
var filename = "Page " + str + ".png"; | |
var src = img.attr("src"); | |
if (src.indexOf("base64") > -1) { | |
var base64 = src.replace("data:image/png;base64,", ""); | |
var i = base64.indexOf(","); | |
if (i !== -1) { | |
base64 = base64.substring(index + 1, base64.length); | |
} | |
cache.zip.file(filename, base64, { | |
base64: true, | |
createFolders: true | |
}); | |
console.log(filename + " Added to Zip from Base64 Image"); | |
cache.downloadFiles++; | |
} else { | |
try { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: src, | |
overrideMimeType: 'text/plain; charset=x-user-defined', | |
onload: function(e) { | |
var base64 = customBase64Encode(e.responseText); | |
cache.zip.file(filename, base64, { | |
base64: true, | |
createFolders: true | |
}); | |
console.log(filename + " Added to Zip as Base64 Image"); | |
cache.downloadFiles++; | |
} | |
}); | |
} catch (e) { | |
console.log(e); | |
} | |
} | |
}); | |
var check = function() { | |
if (cache.downloadFiles < cache.Data.quant) { | |
setTimeout(check, 3000); | |
console.log("Waiting for Files to Download " + cache.downloadFiles + " of " + cache.Data.quant); | |
} else { | |
var blobLink = document.getElementById('blob'); | |
try { | |
blobLink.download = $(".ViewerTitle:first a").text().replace("(Return to Chapter List)", "").trim() + ".zip"; | |
cache.zip.generateAsync({ | |
type: "blob" | |
}).then(function(content) { | |
blobLink.href = window.URL.createObjectURL(content); | |
console.log("Download Ready"); | |
$("#blob")[0].click(); | |
}); | |
} catch (e) { | |
console.log(e); | |
blobLink.innerHTML += " (not supported on this browser)"; | |
} | |
} | |
}; | |
check(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment