-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.html
68 lines (56 loc) · 2.27 KB
/
submit.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Submit canvas-diff</title>
<script src="canvas-diff.js"></script>
<script src="tests.js"></script>
<style type="text/css">
</style>
</head>
<body>
<input type="text" id="id"></input><input type="text" id="name"></input> <a href="javascript:submit()">submit</a>
<script type="text/javascript">
function e( str ) {
// for now, just escape out the single quotes. XSS would be the least of our worries if the server is running publicly
return str.replace( /'/g, "\\'" );
}
// string concatenation would obviously be a bad way to handle this if this was public-facing
var diffString = "";
for ( var i = 0; i < diffs.length; i++ ) {
var canvas = diffToCanvas( diffs[i] );
diffString += " " + e( diffs[i].id ) + ": '" + e( canvas.toDataURL() ) + "'" + ( i === diffs.length - 1 ? '' : ',' ) + "\n";
}
var idText = document.getElementById( 'id' );
if ( localStorage.canvasDiffId ) {
idText.value = localStorage.canvasDiffId;
}
idText.addEventListener( 'input', function() {
localStorage.canvasDiffId = idText.value;
} );
var nameText = document.getElementById( 'name' );
if ( localStorage.canvasDiffName ) {
nameText.value = localStorage.canvasDiffName;
}
nameText.addEventListener( 'input', function() {
localStorage.canvasDiffName = nameText.value;
} );
function submit() {
var output = "browsers.push( {\n" +
" id: '" + e( idText.value ) + "',\n" +
" name: '" + e( nameText.value ) + "',\n" +
" userAgent: '" + e( navigator.userAgent ) + "',\n" +
" appVersion: '" + e( navigator.appVersion ) + "',\n" +
" platform: '" + e( navigator.platform ) + "',\n" +
" snapshots: {\n" +
diffString +
" }\n" +
"} );\n";
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open( 'POST', 'http://192.168.0.2:8082/' + idText.value, true );
xmlhttp.setRequestHeader( 'Content-type', 'text/javascript' );
xmlhttp.send( output );
}
</script>
</body>
</html>