MyHentaiComics Downloader

Rapidly Downloads all the pages of a specific comic

От 21.02.2016. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         MyHentaiComics Downloader
// @namespace    ElectricHum/H/
// @version      0.1
// @description  Rapidly Downloads all the pages of a specific comic
// @author       ElectricHum
// @match        http://myhentaicomics.com/index.php/*
// @exclude      http://myhentaicomics.com/index.php/*/*
// @grant        none
// @require      http://code.jquery.com/jquery-1.12.0.min.js
// @compatible   chrome Must allow multiple downloads
// ==/UserScript==

var myDL = window.myDL = {};

/*When debug is set to one, more useful text for debugging will appear*/
myDL.debug = 0;

myDL.getPagesNumber = function()
{
    //Returns the amount of pages the comic has
    return parseInt($("#g-content .g-info").text().split(" of ")[1]);
};

myDL.getFirst = function()
{
    //Returns the starting page
    var thumbnailsrc = $(".g-thumbnail:first").attr("src").split("/");
    thumbnailsrc = thumbnailsrc[thumbnailsrc.length - 1];
    thumbnailsrc = thumbnailsrc.split("/")[0].split(".");
    var start = parseInt(thumbnailsrc[0]);
    if (this.debug)
        console.log("[DEBUG]: Start = " + start);
    return start;
};

myDL.getFormat = function()
{
    //Returns the extension of the pictures
    var thumbnailsrc = $(".g-thumbnail:first").attr("src").split("/");
    thumbnailsrc = thumbnailsrc[thumbnailsrc.length - 1];
    thumbnailsrc = thumbnailsrc.split("/");
    var format = thumbnailsrc[thumbnailsrc.length -1].split(".")[1];
    if (this.debug)
        console.log("[DEBUG]: Extension="+format);
    return format;
};

myDL.getTitle = function()
{
    //Returns the Title of the comic
    var title = $("#g-header .g-active").text().trim();
    if (this.debug)
        console.log("[DEBUG]: Title="+title);
    return title;
};

myDL.downloadImg = function(url)
{
    // Downloads image from url
    if (this.debug)
        console.log("Downloaded: " + url);
    $("body").append('<a class="myDL_tmp" style="display:none;" download href="' + url + '">Temp</a>');
    var anchor = document.getElementsByClassName("myDL_tmp")[0];
    anchor.click();
    anchor.remove();
};

myDL.DownloadAllImgs = function()
{
    var first = this.getFirst();
    var last = first + this.getPagesNumber();
    var baseUrl = "http://myhentaicomics.com/var/resizes/" + encodeURIComponent(this.getTitle()) + "/";
    for(i = first; i < last; i++)
    {
        if (this.debug)
            console.log("Downloaded "+ i);
        //Adds the starting 0's the site uses as a file structure before the number and extension
        var dlUrl = baseUrl;
        if(i < 10)
            dlUrl += "00";
        else if(i < 100)
            dlUrl += "0";
        dlUrl += String(i) + "." + this.getFormat();
        this.downloadImg(dlUrl);
    }
};

myDL.init = function()
{
    //Creates a button to initialise the downloading
    $("#g-header").after('<div id="myDL_box"></div>');
    $("#myDL_box").append('<button onclick="myDL.DownloadAllImgs()">Download all</button>');
    $("#myDL_box").append('<span style="float:right;" onclick="myDL.debug=1">Debug</span>');
};

$("document").ready(function () {
    //When the page loads, the magic happens
    myDL.init();
});