Black HyRead

Download hyread ebook

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Black HyRead
// @namespace    Yr
// @version      1.0
// @description  Download hyread ebook
// @author       toudaimori
// @match        https://service.ebook.hyread.com.tw/ebookservice/epubreader/hyread/v3/reader.jsp
// @require  https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js
// @require  https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.js
// @require  https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js
// @grant    GM.xmlHttpRequest
// ==/UserScript==

var container = []

async function Download(event)
{
    event.stopPropagation()

    const realContainer = []
    for(let i = 0; i < container.length; ++i){
        console.log(i, container[i])
        realContainer.push(await getImageBase64(i, container[i]))
    }

    Compress('Download', realContainer)
}

function Compress(title, pics)
{
    return new Promise((resolve, reject) => {
        console.log(`Start Compress`)
        const zip = new JSZip()
        const folder = zip.folder(`${title}`);
        for(let i = 0; i < pics.length; ++i){
            folder.file(`${pics[i].index}.jpg`, pics[i].base64, {base64: true})
        }

        zip.generateAsync({type:"blob", streamFiles: true}, metadata => {
            console.log(`Compress Progress = ${metadata.percent} %`)
        })
        .then((content) => {
            // see FileSaver.js
            console.log(`All Done, Save to ${title}.zip`);
            resolve(saveAs(content, `${title}.zip`))
        });
    })
}

async function processSinglePage(){
    const pages = [...document.querySelectorAll('.hyr-hejview__content')].map(x => x.style['background-image'])
    pages.filter(x => x.match(/(blob.*)\"/)).map(x => container.push(x.match(/(blob.*)\"/)[1]))

    container = [...new Set(container)]
    document.title = `HyRead (${container.length})`
}

function getImageBase64(index, path)
{
    return new Promise((resolve, reject) => {
        const extension = path.substring(path.lastIndexOf('.') + 1)
        GM.xmlHttpRequest({
            method: "GET",
            url: path,
            overrideMimeType: 'text/plain; charset=x-user-defined',
            onload: response => {
                let binary = "";
                const responseText = response.responseText;
                const responseTextLen = responseText.length;
                for ( let i = 0; i < responseTextLen; i++ ) {
                    binary += String.fromCharCode(responseText.charCodeAt(i) & 255)
                }

                // Note there is no 'data:image/jpeg;base64,' Due to JSZip
                let src = btoa(binary)

                console.log(`Downloaded: ${index}.${extension}, src=${path}`)
                resolve({'index': index, 'base64': src, 'extension': extension })
            }
        })
    })
}

const btn = $(`<a id="yrBtn" style="position: absolute;top: 50px;left: 10px;">下載</a>`)

$('body').append(btn)

btn.on('click', event => {
    console.log('click')
    Download(event)
})

setInterval(processSinglePage, 500)