/
index.html
118 lines (111 loc) · 4.29 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
<!doctype html>
<meta charset="utf-8">
<title>MachRandGenerator</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.amber-yellow.min.css" />
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.10/clipboard.min.js"></script>
<style>
.mdl-textfield {
width: 90%;
}
#possible_input {
width: 90%;
}
#result {
width: 90%;
}
.generated {
white-space: nowrap;
}
.left-box {
width: 300px;
overflow: hidden;
margin: 10px;
}
#template {
display: none;
}
</style>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<div class="mdl-layout__header mdl-layout__header--waterfall">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">
MachRandGenerator
</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="http://kimihiro-n.appspot.com">Pistatium</a>
<a class="mdl-navigation__link" href="https://github.com/pistatium/mach_rand_generator">GitHub</a>
</nav>
</div>
</div>
<div class="mdl-layout__content">
<a name="top"></a>
<div class="mdl-typography--text-center">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input id="possible_input" type="text" class="mdl-textfield__input" name="possible" value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#$%&">
<label class="mdl-textfield__label" for="possible">Possible chars</label>
</div>
<ul class="mdl-list" id="result">
</ul>
</div>
</div>
<ul class="mdl-list" id="template">
<li class="mdl-list__item mdl-list__item--two-line">
<span class="left-box mdl-list__item-primary-content">
<span class="generated">twCBMcZ3$UrIuxm8UhV</span>
<span class="label mdl-list__item-sub-title">32 Chars</span>
</span>
<span class="mdl-list__item-secondary-action">
<button class="copy mdl-button mdl-js-button mdl-button--raised mdl-button--accent mdl-js-ripple-effect">COPY</button>
</span>
</li>
</ul>
</div>
<script>
$(function() {
var INTERVAL = 150;
var box_list = [6, 8, 10, 12, 16, 32, 64, 128];
var main = function() {
init();
set_random();
setInterval(set_random, INTERVAL);
};
var init = function() {
for (var i in box_list) {
var num = box_list[i];
var elem = $("#template").clone().show();
elem.find(".generated").attr("id", "generated" + num);
elem.find(".copy").attr("id", "copy" + num);
elem.find(".label").text(num + " Chars");
elem.find(".copy").attr("data-clipboard-text", "xxx");
$("#result").append($(elem));
};
new Clipboard(".copy");
};
var set_random = function() {
chars = generate();
var start = 0;
for (var i in box_list) {
var num = box_list[i];
var generated = chars.slice(start, start + num);
$("#generated" + num).text(generated);
$("#copy" + num).attr("data-clipboard-text", generated);
start += num;
};
};
var generate = function() {
var key = new Uint32Array(1000);
var r = window.crypto.getRandomValues(key);
return r.reduce(get_char, "");
};
var get_char = function(p, i) {
var possible = $("#possible_input").val();
return p + possible.charAt(i % possible.length);
};
main();
});
</script>