-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdemo.html
More file actions
274 lines (250 loc) · 8.15 KB
/
demo.html
File metadata and controls
274 lines (250 loc) · 8.15 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html>
<html>
<head>
<title>Demo of String_random.js</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="keywords" content="JavaScript,Library,RegExp,Regular Expression,Random String"/>
<meta name="description" content="String_random.js is a library for generating random string from a regular experession."/>
<meta property="og:email" content="cho45@lowreal.net" />
<meta property="fb:admins" content="cho45" />
<meta name="twitter:site" content="cho45"/>
<meta name="twitter:creator" content="cho45"/>
<style>
body {
padding: 32px 0;
background: #f8f8fa;
color: #23242a;
font-family: 'Fira Mono', 'Menlo', 'Consolas', 'Monaco', monospace;
}
.container {
max-width: 900px;
margin: 0 auto;
background: #fff;
border-radius: 10px;
box-shadow: 0 4px 24px rgba(0,0,0,0.08);
padding: 32px 32px 24px 32px;
}
h1 {
font-size: 2.2em;
font-weight: bold;
letter-spacing: 0.02em;
color: #ffb86c;
margin-bottom: 0.5em;
}
.lead {
color: #666;
font-size: 1.1em;
margin-bottom: 2em;
}
form {
margin-bottom: 2em;
}
input[name="regexp"] {
font-family: inherit;
font-size: 1.2em;
background: #f8f8fa;
color: #23242a;
border: 1.5px solid #bbb;
border-radius: 6px;
padding: 12px 16px;
margin-bottom: 12px;
transition: border 0.2s;
width: 100%;
box-sizing: border-box;
}
input[name="regexp"]:focus {
border-color: #ffb86c;
outline: none;
}
input[type="submit"], .btn-primary {
background: #ffb86c;
color: #23242a;
border: none;
font-weight: bold;
transition: background 0.2s;
font-size: 1.3em;
padding: 16px 40px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.07);
margin-bottom: 10px;
}
input[type="submit"]:hover, .btn-primary:hover {
background: #ffa94d;
}
#examples {
margin-top: 10px;
font-size: 0.98em;
color: #0077b6;
}
#examples a {
color: #0077b6;
text-decoration: underline dotted;
margin: 0 2px;
cursor: pointer;
transition: color 0.2s;
}
#examples a:hover {
color: #ffb86c;
}
.jumbotron {
background: #f8f8fa;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.04);
padding: 40px 20px 20px 20px;
}
.jumbotron p {
font-size: 1.1em;
background: #fffbe6;
border-left: 4px solid #ffb86c;
padding: 8px 16px;
margin-bottom: 18px;
border-radius: 4px;
word-break: break-all;
color: #23242a;
font-family: inherit;
}
.twitter-share-button {
margin-left: 10px;
background: #1da1f2;
color: #fff !important;
border-radius: 4px;
padding: 2px 10px;
font-size: 0.95em;
text-decoration: none;
transition: background 0.2s;
border: none;
display: inline-block;
}
.twitter-share-button:hover {
background: #0d8ddb;
}
@media (max-width: 900px) {
.container {
max-width: 100vw;
padding: 12px 2vw 12px 2vw;
}
.jumbotron {
padding: 24px 4vw 12px 4vw;
}
}
</style>
</head>
<body>
<div class="container">
<div style="text-align: center">
<h1>Demo of String_random.js</h1>
<p class="lead"><a href="https://github.com/cho45/String_random.js">String_random.js</a> is a library for generating random string from a regular experession.</p>
</div>
<form style="text-align: center; padding: 30px 0" class="">
<div class="form-group">
<input type="text" name="regexp" placeholder="RegExp" class="form-control input-lg" required/>
</div>
<input type="submit" value="Generate" class="btn btn-primary btn-lg"/>
<div id="examples">
Examples:
<a href="javascript:void()" data-regexp="\d+">Numbers</a>,
<a href="javascript:void()" data-regexp="((James|Michael|Emily|Jessica|Daniel|Sarah|John|Ashley|David|Jennifer) ){1,2}(Smith|Johnson|Williams|Brown|Jones|Davis|Miller|Wilson|Moore|Taylor)">Names</a>,
<a href="javascript:void()" data-regexp="#[0-9a-f]{6}">Hex Color</a>,
<a href="javascript:void()" data-regexp="[1-9][0-9] [+-] [1-9][0-9] = ">Math Drill</a>,
<a href="javascript:void()" data-regexp="(🟩|⬛|🟨){5}">Wordle</a>,
<a href="javascript:void()" data-regexp="([a-z])([a-z])([a-z])([a-z])([a-z])\4\3\2\1">Palindrome</a>,
<a href="javascript:void()" data-regexp="([CDEFGAB][♯♭]?[Mm] ){3}">Chord</a>,
<a href="javascript:void()" data-regexp="(A ninja|Beyoncé|My teacher) met (a dragon|an alien|Santa Claus) (in a spaceship|at the zoo|on the toilet) (started a dance battle|made spaghetti|robbed a bank) (they became famous|the Earth exploded|they turned into frogs)">Consequences</a>,
<br>
<a href="javascript:void()" data-regexp="(佐藤|鈴木|高橋|田中|伊藤|渡辺|山本|中村|小林|加藤)(ハルト|ツムギ|ミナト|エマ|リク|サナ|ハルキ|コハル|ヒナタ|メイ)">名前</a>,
<a href="javascript:void()" data-regexp="セミの鳴き声です: ( (ミー?ン)+|(ツクツク|ホーシ)+|(ジー?)+)">セミの鳴き声</a>,
<a href="javascript:void()" data-regexp="([あいうえお]{5}) ああ\1 \1">川柳</a>,
<a href="javascript:void()" data-regexp="([ぁ-ん])([ぁ-ん])([ぁ-ん])([ぁ-ん])\3\2\1">回文</a>,
<a href="javascript:void()" data-regexp="((アグリー|ゼロベース|シナジー|イシュー|アジェンダ|アサイン|バリュー|ナレッジ|ASAP)[はにがでを]){5}\1">意識高め</a>,
<a href="javascript:void()" data-regexp="(ルイズ!)+((ルイズ!?)+|(ぅ*う*わぁ+あ+ん!+)|あ+[あ…ぁ]+|[うぅ]+)+">ルイズ</a>,
</div>
</form>
<div style="position: relative">
<div class="jumbotron" id="output" style="padding-top: 90px">
</div>
<!-- div style="position: absolute; top: 30px; left: 60px" id="twitter-button">
</div -->
</div>
</div>
<script type="module">
import { String_random } from './lib/String_random.js';
function seededRandom(seed) {
let x = seed >>> 0;
return function me() {
// Xorshift32アルゴリズム
x ^= x << 13;
x ^= x >>> 17;
x ^= x << 5;
me.seed = x;
return (x >>> 0) / 0x100000000;
};
}
function generate (re, seed) {
var input = document.querySelector('input[name=regexp]');
var output = document.getElementById('output');
output.innerHTML = '';
if (!re) {
re = input.value;
if (!re) return;
}
if (typeof seed === "undefined") seed = new Date().getMilliseconds();
input.value = re.source || re;
const params = new URLSearchParams();
params.set('seed', seed);
params.set('regexp', input.value);
location.hash = '#' + params.toString();
document.title = input.value;
console.log('seed:', seed);
const random = seededRandom(seed);
for (let i = 0; i < 10; i++) {
const generated = String_random(re, { random });
const p = document.createElement('p');
p.textContent = generated;
const params = new URLSearchParams();
params.set('url', location.href);
params.set('text', `${generated} #string_random_js`);
const url = `https://twitter.com/intent/tweet?${params.toString()}`;
const a = document.createElement('a');
a.href = url;
a.target = '_blank';
a.className = 'btn btn-sm btn-info twitter-share-button';
a.textContent = 'Tweet';
p.appendChild(a);
output.appendChild(p);
}
}
document.getElementById('examples').addEventListener('click', function (e) {
if (e.target.tagName === 'A') {
e.preventDefault();
e.stopPropagation();
const regexp = e.target.getAttribute('data-regexp');
generate(regexp);
}
});
document.querySelector('form').addEventListener('submit', function (e) {
generate();
e.preventDefault();
});
window.onhashchange = function (a, b) {
const hash = location.hash.replace(/^#/, '');
if (hash.match(/regexp=/)) {
const params = new URLSearchParams(hash);
const seed = parseInt(params.get('seed'), 10);
if (params.has('regexp')) {
if (seed) {
generate(new RegExp(params.get('regexp')), seed);
} else {
generate(new RegExp(params.get('regexp')));
}
return;
}
} else {
// backward compatibility
generate(new RegExp(decodeURIComponent(hash)));
}
};
window.onhashchange();
</script>
</body>
</html>