-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
217 lines (175 loc) · 8.88 KB
/
index.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Free yourself from the burden of your secrets. Share them out in the open.">
<meta property="og:title" content="An Open Secret">
<meta property="og:site_name" content="An Open Secret">
<meta property="og:url" content="https://shannonvturner.com/secret">
<meta property="og:type" content="website">
<meta property="fb:app_id" content="">
<meta property="og:description" content="Free yourself from the burden of your secrets. Share them out in the open.">
<meta property="og:image" content="https://shannonvturner.com/secret/secretimage.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="https://shannonvturner.com/secret">
<meta name="twitter:creator" content="@svthmc">
<meta name="twitter:title" content="An Open Secret">
<meta name="twitter:description" content="Free yourself from the burden of your secrets. Share them out in the open.">
<meta name="twitter:image:src" content="https://shannonvturner.com/secret/secretimage.png">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<title>An Open Secret</title>
<link rel="icon" href="https://shannonvturner.com/secret/favicon.ico">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-49936574-3', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div class="container-fluid">
<div class="col-lg-2 text-left">
<h2>Free yourself from the burden of your secrets</h2>
<hr>
<h4 class="hidden-xs hidden-sm">Start typing your secret now. As you do, an image will be created for you.</h4>
<h4 class="visible-xs visible-sm">Start typing your secret now. As you do, an image will be created for you below.</h4>
<input id="mobile-textbox" type="password" class="visible-xs visible-sm" style="width: 100%;">
<hr>
<h4 class="hidden-xs hidden-sm">When you're finished, right click and save your image.</h4>
<h4 class="visible-xs visible-sm">When you're finished, touch and hold to save your image.</a></h4>
<hr>
<h4>Your secret image is probably unique and undecipherable.</h4> <h4>But the world is a big place, and if someone has the exact same secret image as you, the two of you will know.</h4>
<hr>
<!-- Reset button -->
<button id="reset" class="btn btn-info center-block">Reset Image</button>
<hr>
</div> <!-- /.col-lg-2.text-center -->
<div class="col-lg-10">
<canvas id="secret" style="width: 100%; height: 100%;" class="hidden-xs hidden-sm"></canvas>
<img id="secret-img" style="width: 100%; height: 100%;" class="visible-xs visible-sm">
</div> <!-- /.col-lg-10 -->
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="js/sha256.js"></script>
<script>
var canvas = document.getElementById('secret');
var context = canvas.getContext('2d');
$("#secret-img").attr("src", canvas.toDataURL());
canvas.width = 1440;
canvas.height = 900;
// 16 rows
var rowHeight = parseInt(canvas.height / 16);
// Get 1% of a row's width, for calculating bar widths
var onePctWidth = parseInt(canvas.width / 100);
// in a word: ba78
// position 1: color of 1st bar and width of 3rd bar
// position 2: color of background and width of 1st bar
// position 3: color of 2nd bar and width of spacing between 1st and 2nd bars
// position 4: width of 2nd bar and color of 3rd bar
function drawSecret(hash) {
colors = [ '#E45', '#E64', '#EC6', '#6E4',
'#8DE', '#99E', '#B8E', '#C5C', // Rainbow
'#28B', '#7FD', '#2CC', '#000',
'#6BA', '#5AB', '#66A', '#647'
];
for (var i=0;i<=hash.length;i+=4) {
// Set background color
context.fillStyle = colors[parseInt("0x"+hash[i+1])];
// Create background (a full-width Rectangle of that color)
context.fillRect(0, i/4 * rowHeight, canvas.width, rowHeight);
// Set color of 1st bar
context.fillStyle = colors[parseInt("0x"+hash[i])];
// Create 1st bar
context.fillRect(parseInt("0x"+hash[i+1]) * onePctWidth, i/4 * rowHeight, parseInt("0x"+hash[i+1]) * onePctWidth, rowHeight);
// Set width of spacing beteen 1st and 2nd bars
var spacing = parseInt("0x"+hash[i+2]) * onePctWidth;
spacing += (parseInt("0x"+hash[i+1]) * onePctWidth * 4); // Position of 1st bar
// Set color of 2nd bar
context.fillStyle = colors[parseInt("0x"+hash[i+2])];
// Create 2nd bar
context.fillRect(spacing, i/4 * rowHeight, parseInt("0x"+hash[i+3]) * onePctWidth, rowHeight);
// Set color of 3rd bar
context.fillStyle = colors[parseInt("0x"+hash[i+3])];
// Determine position of 3rd bar
spacing = spacing + (parseInt("0x"+hash[i+3]) * onePctWidth * 4)
// Create 3rd bar
context.fillRect(spacing, i/4 * rowHeight, parseInt("0x"+hash[i]) * onePctWidth, rowHeight);
}
$("#secret-img").attr("src", canvas.toDataURL());
}
function clearSecret() {
context.clearRect(0, 0, canvas.width, canvas.height);
$("#mobile-textbox").val("")
message = "";
$("#secret-img").attr("src", canvas.toDataURL());
// Remove focus from the button so that if you press space it doesn't reset again
// There's not a better way to remove the focus than this
$("#reset").hide();
setTimeout(function() {
$("#reset").show();
}, 500);
}
$("#reset").click(function() {
clearSecret();
});
var message = "";
document.onkeypress = function (key) {
if (window.event) {
// Prevent spacebar from scrolling the page slightly
if (key.keyCode == 32 && key.target == document.body) {
message += ' ';
key.preventDefault();
}
message += String.fromCharCode(key.keyCode);
} else if (key.key) { // For compatibility with Firefox
if (key.key == ' ' || key.key == "'") {
// The quote key brings up a search box in Firefox
message += key.key;
key.preventDefault();
} else if (key.key == 'Enter') {
message += '\n';
} else if (key.key == 'ArrowLeft' || key.key == 'ArrowDown' || key.key == 'ArrowUp' || key.key == 'ArrowRight') {
// Do nothing
} else if (key.key == 'Backspace') {
message = message.slice(0, -1);
} else if (key.key == 'Tab') {
message += '\t';
} else {
message += key.key;
}
}
drawSecret(Sha256.hash(message));
};
// On Chrome, need to use document.onkeydown instead of onkeypress to handle Backspace and Tab
// But can't use .onkeydown for normal typing or letter case is not preserved
document.onkeydown = function(key) {
if (window.event && key.keyCode == 8 && key.target == document.body) {
message = message.slice(0, message.length-1);
key.preventDefault();
drawSecret(Sha256.hash(message));
} else if (key.keyCode == 9 && key.target == document.body) {
message += '\t';
key.preventDefault();
drawSecret(Sha256.hash(message));
}
}
// Certain mobile browsers don't capture document.onkeydown or document.onkeypress properly
// So we'll check for if the input textfield has changed instead (since the textfield only appears on mobile it's fine)
$("#mobile-textbox").change(function() {
message = $("#mobile-textbox").val();
drawSecret(Sha256.hash(message));
});
// function downloadCanvas(link, canvasId, filename) {
// link.href = document.getElementById(canvasId).toDataURL();
// link.download = filename;
// }
// document.getElementById('download-link').addEventListener('click', function() {
// downloadCanvas(this, 'secret', 'test.png');
// }, false);
</script>
</body>
</html>