Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18comic漫画下载 #9

Closed
ydc1992 opened this issue Mar 6, 2022 · 1 comment
Closed

18comic漫画下载 #9

ydc1992 opened this issue Mar 6, 2022 · 1 comment

Comments

@ydc1992
Copy link

ydc1992 commented Mar 6, 2022

图片分割的算法换了,我把图片分割合并的算法改了完美运行

 const download = async url => {
        const img = new Image;
        img.src = URL.createObjectURL((await new Promise((resolve, reject) => GM.xmlHttpRequest({
            url,
            method: 'GET',
            responseType: 'blob',
            onload: resolve,
            onerror: reject
        }))).response);
        await new Promise((resolve, reject) => (img.onload = resolve, img.onerror = reject));
        const canvas = document.createElement('canvas');
        const ctx = canvas.getContext('2d');
        const w = canvas.width = img.naturalWidth;
        const h = canvas.height = img.naturalHeight;
        // aid & scramble_id are both global variables
        if (!url.includes('.jpg') || aid < scramble_id) {
            ctx.drawImage(img, 0, 0);
        } else {
            var r = url.split("/")[6].split(".")[0];
            var s = get_num(aid, r);
            var l = parseInt(h % s);
            var o = w;
            for(var m=0;m<s;m++){
              var c = Math.floor(h / s);
              var g = c * m;
              var h1 = h - c * (m + 1) - l;
              0 == m ? c += l : g += l;
              ctx.drawImage(img, 0, h1, o, c, 0, g, o, c) 
            }
  
        }
        URL.revokeObjectURL(img.src);
        // TODO: Select image type? Change quality?
        return new Promise(resolve => canvas.toBlob(resolve, 'image/webp', 0.9));
    };
@eternalphane
Copy link
Owner

@ydc1992 这段时间没啥需求 所以一直没想起来改这块儿的代码 多谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants