-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloze_machine.html
66 lines (65 loc) · 1.75 KB
/
cloze_machine.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page Title</title>
<style>
div{
text-align:center;
width: 100%;
}
textarea {
min-width: 98%;
max-width: 98%;
width: 98%;
}
p {
text-align: right;
margin-right: 2%;
}
input{
width: 5%;
}
</style>
</head>
<body>
<div><textarea id="textbox"></textarea></div>
<p>x: <input id="x" type="text">y: <input id="y" type="text"><button onclick="g()">GO</button><button onclick="h()">RE</button></p>
</body>
<script>
var ch = '';
var txtBox = document.getElementById('textbox');
txtBox.style.height = (window.screen.height/2) + 'px';
/*txtBox.addEventListener('mouseup',(event)=>{
const keyName = event.button;
if(keyName===0){
console.log('lft mouse');
var selObj = window.getSelection();
console.log('text: '+ selObj.toString());
}
});*/
function h(){
txtBox.value = (txtBox.value!== ch?ch:txtBox.value);
}
function g(){
ch = txtBox.value;
if(txtBox.value.length>0){
var str = f(txtBox.value);
if(str){
txtBox.value = str;
}
}else{
alert('nothing');
}
}
function f(s){
let x = document.getElementById('x').value?document.getElementById('x').value:1;
let y = document.getElementById('y').value?document.getElementById('y').value:(x+1);
let p = 0;
let r = s.replace(/([\u4E00-\u9FA5])|([a-zA-Z]+)/gu,function(t){
return `{{c${(((p++)%2==0)?x:y)}::${t}}}`;
})
return r;
}
</script>
</html>