mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-09 13:15:00 +01:00
Added image-data hash.
This commit is contained in:
parent
96118e5690
commit
88b5e7668f
29
test/test.js
29
test/test.js
@ -2,19 +2,28 @@
|
|||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function show(container, {url, isPointInPath}){
|
function hashToString(hash){
|
||||||
|
var chunks = [];
|
||||||
|
(new Uint32Array(hash)).forEach(function(num){
|
||||||
|
chunks.push(num.toString(16));
|
||||||
|
});
|
||||||
|
return chunks.map(function(chunk){
|
||||||
|
return "0".repeat(8 - chunk.length) + chunk;
|
||||||
|
}).join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function show(container, {url, imageData, isPointInPath}){
|
||||||
var display = container.querySelector(".display");
|
var display = container.querySelector(".display");
|
||||||
display.src = url;
|
display.src = url;
|
||||||
display.title = url;
|
display.title = url;
|
||||||
var buffer = new TextEncoder("utf-8").encode(url);
|
var buffer = new TextEncoder("utf-8").encode(url);
|
||||||
crypto.subtle.digest("SHA-256", buffer).then(function(hash){
|
Promise.all([
|
||||||
var chunks = [];
|
crypto.subtle.digest("SHA-256", buffer),
|
||||||
(new Uint32Array(hash)).forEach(function(num){
|
crypto.subtle.digest("SHA-256", imageData.data)
|
||||||
chunks.push(num.toString(16));
|
]).then(function(hashes){
|
||||||
});
|
container.querySelector(".hash").textContent =
|
||||||
container.querySelector(".hash").textContent = chunks.map(function(chunk){
|
hashToString(hashes[0]) + " / " +
|
||||||
return "0".repeat(8 - chunk.length) + chunk;
|
hashToString(hashes[1]);
|
||||||
}).join("");
|
|
||||||
});
|
});
|
||||||
container.querySelector(".isPointInPath").textContent = isPointInPath;
|
container.querySelector(".isPointInPath").textContent = isPointInPath;
|
||||||
}
|
}
|
||||||
@ -86,6 +95,7 @@ function topTest(){
|
|||||||
var ctx = draw(canvas);
|
var ctx = draw(canvas);
|
||||||
return {
|
return {
|
||||||
url: canvas.toDataURL(),
|
url: canvas.toDataURL(),
|
||||||
|
imageData: ctx.getImageData(0, 0, canvas.width, canvas.height),
|
||||||
isPointInPath: getIsPointInPath(ctx)
|
isPointInPath: getIsPointInPath(ctx)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -110,6 +120,7 @@ function iframeTest(iframe){
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
url: iframe_canvas.toDataURL(),
|
url: iframe_canvas.toDataURL(),
|
||||||
|
imageData: iframe_ctx.getImageData(0, 0, iframe_canvas.width, iframe_canvas.height),
|
||||||
isPointInPath: getIsPointInPath(iframe_ctx)
|
isPointInPath: getIsPointInPath(iframe_ctx)
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user