Skip to content

Commit

Permalink
feat: fix broken native code
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinpan committed Mar 4, 2021
1 parent cd6b689 commit da36bf8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scripts/super-image-reptile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// @author yujinpan
// @include http*://**
// @require https://cdn.bootcss.com/jszip/3.2.2/jszip.min.js
// @run-at document-start
// ==/UserScript==

/**
Expand Down Expand Up @@ -45,6 +46,9 @@
const blobUrls = new Set();
let timeId;

// 开启高级模式
advance();

// 初始化
init();

Expand Down Expand Up @@ -358,7 +362,7 @@
* @param {HTMLCanvasElement} canvas canvas 元素
*/
function getCanvasImage(canvas) {
return canvas.toDataURL();
return canvas.toDataURL_();
}

/**
Expand Down Expand Up @@ -513,4 +517,21 @@
function warnMessage(...params) {
console.warn('[自动获取图片]:', ...params);
}

function advance() {
// `toDataURL` was broke
HTMLCanvasElement.prototype.toDataURL_ = HTMLCanvasElement.prototype.toDataURL;

// remove tainted source
const canvasContextPrototype = CanvasRenderingContext2D.prototype;
canvasContextPrototype.drawImage_ = CanvasRenderingContext2D.prototype.drawImage;
canvasContextPrototype.drawImage = function () {
const src = arguments[0].src;
if (src.startsWith('http') && location.origin !== src.slice(0, src.indexOf('/', 8)) && src.crossOrigin === undefined) {
console.log('%c 【自动获取图片】站点正在加载无法下载的图片,请自行访问该链接下载:', 'color: orange;', src);
return;
}
this.drawImage_.apply(this, arguments);
};
}
})();

0 comments on commit da36bf8

Please sign in to comment.