-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys.js
67 lines (55 loc) · 1.9 KB
/
sys.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
function checkPattern(e){
e.value = e.value.replace(/^[^A-Za-z]/g, '').replace(/[^\w\-]/g, '');
results();
}
function normalizeText(e){
return e.replace(/\\/g, "\\\\");
}
function ignoreEmptyString(str){
return str != '' ? str : null;
}
function results(){
var locale = document.getElementById("locale").value;
var auth = document.getElementById("auth").value;
var dm = document.getElementById("dm").value;
var cmd = ignoreEmptyString(document.getElementById("cmd").value.trim());
var value = ignoreEmptyString(document.getElementById("value").value.trim());
var title = ignoreEmptyString(document.getElementById("title").value.trim());
var description = ignoreEmptyString(document.getElementById("description").value.trim());
var code = ignoreEmptyString(editor.getValue().trim());
var result = document.getElementById("result");
document.getElementById("copy").innerHTML = "Copy to clipboard";
var failed = !(cmd && cmd.length > 1);
if (!failed)
{
result.value = "!gcmd " + locale + " " + auth + " " + dm + " " + cmd;
var len = result.value.length;
if (code && code.length > 3)
result.value += " script`" + code + "`";
if (value)
result.value += " value[[" + normalizeText(value) + "]]";
if (title)
result.value += " title[[" + normalizeText(title) + "]]";
if (result.value.length == len)
failed = true;
else
{
if (description)
result.value += " description[[" + normalizeText(description) + "]]";
}
}
if (failed)
result.value = "";
else
{
var size = (2000 - result.value.length);
document.getElementById("size").innerHTML = (size < 0 ? "<font color=\"#FC4646\">" : '') + size + " characters."
}
}
function copy(){
let result = document.getElementById("result");
if (result.value == "") return;
result.select();
document.execCommand("copy");
document.getElementById("copy").innerHTML = "Copied";
}