-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.tis
175 lines (147 loc) · 4.31 KB
/
script.tis
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
//view.connectToInspector && view.connectToInspector(rootElement, inspectorIpAddress);
const history = [];
const storageLimit = 10;
const maxCharsThatCanBeCopied = 500;
var lastCopiedText = "";
var canShowPopup = true;
var shouldShowPopup = true;
var audioEnabled = true;
var clipboardEnabled = true;
var currentSound = false;
function playSound(sound) {
if (!audioEnabled) return;
if (currentSound != false) return;
currentSound = view.audio(self.url(sound));
currentSound.play();
view.root.timer(500ms, function() {
currentSound = false;
});
}
function updateStorageText() {
const length = $$(li).length > 0 ? $$(li).length / 2 : 0;
$(.storage-limit).html = String.$(Storage Limit: <b>{length} / {storageLimit}</b>);
$(img).style#visibility = length ? "none" : "visible";
shouldShowPopup = true;
}
function showStorageExceededPopup(text) {
if (!canShowPopup) return;
if (!shouldShowPopup) return;
canShowPopup = false;
shouldShowPopup = false;
const popup = $(div.popup);
popup.text = text;
playSound("error.mp3");
popup.style.set { bottom: 0 };
view.root.timer(2000ms, function() {
popup.style.set { opacity: 0 };
view.root.timer(750ms, function() {
popup.style.set {
transition: "none",
bottom: dip(-49),
opacity: 1
};
popup.style.set {
transition: "bottom cubic-out 0.5s, opacity linear 0.5s;"
};
canShowPopup = true;
});
});
}
$(a.pseudo-button.settings) << event click {
$(div.settings).style.set {
transition: "bottom linear 100ms",
bottom: 0
};
$(div.filter).style#visibility = "visible";
$(div.filter).style.set { opacity: 0.5 };
};
function hideSettings() {
$(div.settings).style.set {
transition: "bottom linear 50ms",
bottom: dip(-224);
};
$(div.filter).style.set { opacity: 0 };
view.root.timer(200ms, function() {
$(div.filter).style#visibility = "none";
});
}
$(a.pseudo-button.close) << event click {
hideSettings();
};
$(div.filter) << event click {
hideSettings();
};
view.root.timer(500ms, function() {
if (!clipboardEnabled) return true;
const contents = view.clipboard(#get, #text);
if (contents == null) return true;
const string = contents.trim();
if (lastCopiedText == string) return true;
if (string == "") return true;
const length = self.$$(li.item)?.length;
if (history.indexOf(string) == -1 && length == storageLimit) {
showStorageExceededPopup("Your storage limit is exceeded!");
return true;
}
if (string.length > maxCharsThatCanBeCopied) {
showStorageExceededPopup(String.$(Cannot copy text of characters more than {maxCharsThatCanBeCopied}));
return true;
}
if (history.indexOf(string) == -1) {
$(ul).$append(<li .item><span class="clipboard-content">{contents}</span></li>);
$(ul).$append(<li .trashcan><span .trashcan-button .material-icons>delete</span></li>);
history.push(contents);
lastCopiedText = string;
updateStorageText();
playSound("success.mp3");
}
return true;
});
$(.clear) << event click {
for (var li in $$(li)) {
li.remove();
}
history.length = 0;
updateStorageText();
playSound("trash.mp3");
}
event click $(.trashcan-button) (evt, span) {
const li = span.parent;
const items = li.parent.$$(> li);
const prevItem = items[li.index - 1];
const prevItemText = prevItem.$(span).text;
const textIndex = history.indexOf(prevItemText);
history.remove(textIndex);
prevItem.remove();
updateStorageText();
li.remove();
}
event click $(li.item) {
lastCopiedText = this.text;
view.clipboard(#put, this.text);
const textIndex = history.indexOf(this.text);
const items = $$(li);
const selfIndex = items.indexOf(this);
const nextItem = items[selfIndex + 1];
nextItem.remove();
$(ul).$prepend(<li .trashcan><span .trashcan-button .material-icons>delete</span></li>);
$(ul).$prepend(<li .item><span class="clipboard-content">{this.text}</span></li>);
playSound("success.mp3");
this.remove();
}
$(toggle(audio)) << event change {
audioEnabled = this.value;
}
$(toggle(clipboard)) << event change {
clipboardEnabled = this.value;
}
$(a#sciter) << event click {
const href = this.attributes["href"];
Sciter.launch(href);
return true;
};
$(a#clipper) << event click {
const href = this.attributes["href"];
Sciter.launch(href);
return true;
};