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));
};
图片分割的算法换了,我把图片分割合并的算法改了完美运行