-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
141 lines (123 loc) · 5.81 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
h1 {
margin-bottom: 35px;
margin-top: 10px;
}
#canvasgenerated {
margin-top: 40px;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col"></div>
<div class="col-10">
<h1>Demonstration of Picasso Canvas</h1>
<form>
<div class="form-group row">
<label for="numshapes" class="col-sm-2 col-form-label">Number of rounds</label>
<div class="col-sm-2">
<input type="number" class="form-control" id="numshapes" value="5" min="1">
</div>
<label for="initialSeed" class="col-sm-2 col-form-label">Initial Seed</label>
<div class="col-sm-2">
<input type="number" class="form-control" id="initialSeed" value="42" min="1">
</div>
</div>
<div class="form-group row">
<label for="widtharea" class="col-sm-2 col-form-label">Canvas width</label>
<div class="col-sm-2">
<input type="number" class="form-control" id="widtharea" value="300" min="1">
</div>
<label for="heightarea" class="col-sm-2 col-form-label">Canvas height</label>
<div class="col-sm-2">
<input type="number" class="form-control" id="heightarea" value="300" min="1">
</div>
</div>
<div class="form-group row">
<label for="offsetParameter" class="col-sm-2 col-form-label">Offset</label>
<div class="col-sm-2">
<input type="number" class="form-control" id="offsetParameter"
value="2001000001" min="1" step="10000">
</div>
<label for="multiplier" class="col-sm-2 col-form-label">Multiplier</label>
<div class="col-sm-2">
<input type="number" class="form-control" id="multiplier"
value="15000" min="1" step="100">
</div>
</div>
<div class="form-group row">
<label for="fontSizeFactor" class="col-sm-2 col-form-label">Font size scale factor</label>
<div class="col-sm-2">
<input type="number" class="form-control" id="fontSizeFactor" step="0.1"
value="1.5" min="0.1">
</div>
<label for="maxShadowBlur" class="col-sm-2 col-form-label">Max shadow blur</label>
<div class="col-sm-2">
<input type="number" class="form-control" id="maxShadowBlur" step="1"
value="50" min="1">
</div>
</div>
<button id="canvasbtn" type="submit" class="btn btn-primary mb-2">Generate canvas</button>
</form>
<div style="text-align:center;" id="canvasgenerated"></div>
Hash:<div id="hash"></div>
</div>
<div class="col"></div>
Original Implementation from:
https://antoinevastel.com/browser%20fingerprinting/2019/03/21/picasso-canvas-fingerprinting.html
</div>
</div>
<script src="canvas.js"></script>
<script>
String.prototype.hashCode = function() {
var hash = 0, i, chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
document.getElementById('canvasbtn')
.addEventListener('click', (e) => {
e.preventDefault();
const params = {
area: {
width: document.getElementById('widtharea').value,
height: document.getElementById('heightarea').value,
},
offsetParameter: document.getElementById('offsetParameter').value,
fontSizeFactor: document.getElementById('fontSizeFactor').value,
multiplier: document.getElementById('multiplier').value,
maxShadowBlur: document.getElementById('maxShadowBlur').value,
};
const numShapes = document.getElementById('numshapes').value;
// const initialSeed = Math.floor(100*Math.random());
const initialSeed = document.getElementById('initialSeed').value;
console.log(initialSeed)
const start = performance.now();
window.canvasValue = picassoCanvas(
numShapes, initialSeed, params
);
const end = performance.now();
if (canvasValue.indexOf('base64') > -1) {
const img = document.createElement('img');
img.src = canvasValue;
document.getElementById('canvasgenerated').innerHTML = `<p>Canvas with ${numShapes} primitives computed in ${((end - start)/1000).toFixed(6)} seconds</p>`;
document.getElementById('canvasgenerated').appendChild(img);
} else {
document.getElementById('canvasgenerated').innerHTML = '<h2 class="alert alert-danger">An error occured</h2>';
}
document.getElementById("hash").innerHTML = canvasValue.hashCode();
});
</script>
</body>
</html>