mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 03:56:26 +02:00
Added setting for canvas cache.
This commit is contained in:
parent
f853071d19
commit
48dc965f7c
6 changed files with 41 additions and 1 deletions
|
@ -54,8 +54,16 @@
|
|||
};
|
||||
}
|
||||
|
||||
var canvasCache = Object.create(null);
|
||||
function getFakeCanvas(window, original, prefs){
|
||||
try {
|
||||
if (prefs("useCanvasCache")){
|
||||
var originalDataURL = original.toDataURL();
|
||||
var cached = canvasCache[originalDataURL];
|
||||
if (cached){
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
// original may not be a canvas -> we must not leak an error
|
||||
var context = getContext(window, original);
|
||||
var {imageData, source} = getImageData(window, context);
|
||||
|
@ -86,6 +94,9 @@
|
|||
var canvas = original.cloneNode(true);
|
||||
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
||||
context.putImageData(imageData, 0, 0);
|
||||
if (prefs("useCanvasCache")){
|
||||
canvasCache[originalDataURL] = canvas;
|
||||
}
|
||||
return canvas;
|
||||
}
|
||||
catch (e){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue