-
Notifications
You must be signed in to change notification settings - Fork 0
/
recover.js
77 lines (69 loc) · 2.6 KB
/
recover.js
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
$(function () {
$("#recover").click(function () {
// 取得輸入框文字
var input = $("#input").val();
// console.log(input)
if (input == "") {
alert("輸入不得為空白!")
}
else {
var lines = input.split("\n")
// 一行一行
var output = ""
lines.forEach(function (line, index) {
// console.log(line, index);
// console.log("before:", line)
line = " " + line + " "
if (line != "") {
// 復原前綴詞
prefixes.forEach(function (word, index) {
if (line.includes(word)) {
line = line.replace(word, "")
}
});
// 復原www,不小心寫太複雜了
const regex = /[^A-Za-z][wW]{1,}[^A-Za-z]/g
const result = [...line.matchAll(regex)];
if (result.length != 0) {
var move = 0
result.forEach(function (item) {
var index = item.index - move;
line = line.slice(0, index + 1) + line.slice(index + item[0].length - 1, line.length);
move += item[0].length - 2
});
}
// 復原後綴詞01
postfixes1.forEach(function (word, index) {
if (line.includes(word)) {
line = line.replace(word, "")
}
});
// 復原後綴詞02
var list = line.split("(")
var last_elem = list[list.length - 1]
if (!last_elem.includes(")")) {
line = line.slice(0, line.length - last_elem.length - 1)
}
// 刪除前後多餘的空格
line = line.trim();
}
// console.log("after:", line)
output = output + line + "\n";
});
}
// 顯示在輸出框
// console.log(output);
output = output.slice(0, output.length - 1)
$("#output").val(output);
})
// 機率決定
function prob_bool(prob) {
return Math.random() < prob;
}
// 一鍵複製功能
$("#copy").click(function () {
$("#output").select();
document.execCommand('copy');
alert("已複製到剪貼簿!");
})
})