-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
92 lines (71 loc) · 2.19 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no,initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Thanos' snap</title>
<style>
.container {
max-width: 650px;
width: 100%;
margin: 0 auto;
}
textarea{
margin: 0;
padding: 0;
width: 100%;
resize: vertical;
}
</style>
</head>
<body>
<div class="container">
<p>Thanos' snap, to remove 50% words from your English article.</p>
<p>1. Input your English article into the textarea down blow.</p>
<p>2. Click the `random remove` button.</p>
<p>Have fun.</p>
<div class="group">
<textarea name="article" id="article" cols="30" rows="10"></textarea>
</div>
<button id="trigger">random remove</button>
<div id="resultText"></div>
</div>
<script>
var trigger = document.getElementById('trigger')
trigger.addEventListener('click', doit, false)
var text = document.getElementById('article')
function doit() {
var _t = text.value
if (!_t) return
// 1. split all words
var wordArr = splitWords(_t)
console.log(wordArr)
var result = []
// 2. randow word
wordArr.forEach(function (item, index) {
var _w = random(item)
result.push(_w)
})
// 3. render article
render(result)
}
var letterReg = /^[A-Za-z]+$/
var emptyReg = /\s/
function splitWords(text) {
var _wa = text.split(emptyReg)
return _wa
}
function random(text) {
if (!text) return text
if (Math.random() > 0.5) return text
else return '_'.repeat(text.length)
}
function render(wordArr) {
var _r = document.getElementById('resultText')
_r.innerHTML = ''
_r.innerHTML = wordArr.join(' ')
}
</script>
</body>
</html>