HHcomic Autoload

Autoload all images on one page when reading manga on hhcomic.com

目前為 2014-08-01 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           HHcomic Autoload
// @description    Autoload all images on one page when reading manga on hhcomic.com
// @include        http://paga.hhcomic.net/*/*
// @include        http://paga.vs20.com/*/*
// @version 0.0.1.20140801143719
// @namespace https://greasyfork.org/users/2233
// ==/UserScript==

var wnd = window
var doc = wnd.document
var loc = location
var href = loc.href

var load_imgs = function()
{
    doc.body.innerHTML = ''
    var d = doc.createDocumentFragment()
    for(var i=0, len=imgs.length; i<len; i++)
    {
        var img = new Image()
        img.id = i
        img.onerror = function(){ this.onerror = null; this.style.display = 'none' }
        img.src = imgs[i]
        img.style.cssText = 'display: block; margin-left: auto; margin-right: auto'
        img.width = wnd.innerWidth * 0.70
        d.appendChild(doc.createTextNode('p. '+i))
        d.appendChild(doc.createElement('BR'))
        d.appendChild(img)
        d.appendChild(doc.createElement('BR'))
    }
    doc.body.appendChild(d)
}

if((/^http:\/\/paga\.hhcomic\.net\//.test(href)) || (/^http:\/\/paga\.vs20\.com\//.test(href)))
{
    if(href.indexOf('#')==-1) { loc.href = loc.href + '#' }
    var imgs = []
    var wnd = unsafeWindow
    if(typeof wnd.arrPicLlstUrl != 'undefined') { imgs = wnd.arrPicLlstUrl } else { alert("Cannot find the image links."); throw 'exit' }
    var server = wnd.ServerList[/.*\bs=(\d+)/.exec(href)[1]-1]
    for(var i=imgs.length-1; i>=0; i--) { imgs[i] = server + imgs[i] }
    load_imgs()

    GM_xmlhttpRequest({
        method: 'GET',
        url: 'http://hhcomic.com/comic/' + /.*?\/(\d+\/).*/.exec(href)[1],
        synchronous: false,
        onload: function(response)
        {
            var html = response.responseText, m, p = /<li><a [^>]*?href=(http:\/\/[^ ]*)/g, vlnks = ['javascript:alert("This is the last volume.")']
            while(m=p.exec(html)){ if(m[1] != href) { vlnks.push(m[1]) } else { break } }
            vlnks.sort()
            var nextlink = vlnks[0]

            var nextlink_el = doc.createElement('A')
            nextlink_el.appendChild(doc.createTextNode('Next'))
            nextlink_el.href = nextlink
            doc.body.appendChild(nextlink_el)

            addEventListener("keydown", function(evt){ if(evt.keyCode == 32) { evt.preventDefault(); loc.href = doc.getElementsByTagName('A')[0].href } }, false)
        }
    })

    throw 'exit'
}