-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtchat.js
More file actions
94 lines (84 loc) · 2.07 KB
/
tchat.js
File metadata and controls
94 lines (84 loc) · 2.07 KB
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
'use strict';
addEventListener ('load', init);
function init ()
{
const form = document.forms.tchat;
form.addEventListener ('input', input);
form.addEventListener ('submit', clip);
input ();
}
async function clip (event)
{
const form = document.forms.tchat;
event.preventDefault ();
form.elements.copy.disabled = true;
try
{
await navigator.clipboard.writeText (form.elements.url.textContent);
setTimeout (() => { form.elements.copy.disabled = false }, 1000);
}
catch (e)
{
console.error (e);
form.elements.copy.value = 'Failed to access clipboard';
}
}
function input ()
{
const form = document.forms.tchat;
const joins = form.elements.join.value.trim ();
let p = '';
for (const j of joins.split (/\W+/))
p += '&join=' + encodeURIComponent (j);
if (form.elements.time.value > 0)
p += '&time=' + form.elements.time.value;
if (form.elements.scale.value > 1)
p += '&scale=' + form.elements.scale.value;
if (form.elements.static.checked)
p += '&static';
const test = document.getElementById ('test');
for (const opt of [
'colon',
'first',
'wrap',
'bold',
])
{
const checked = form.elements[opt].checked;
if (opt == 'first' ? !checked : checked)
{
p += `&style=${opt}`;
test.classList.add (opt);
}
else
test.classList.remove (opt);
}
if (form.elements.bots.checked)
{
p += `&no=bots`;
test.classList.add ('bots');
}
else
test.classList.remove ('bots');
if (form.elements.bans.checked)
p += '&bans';
if (form.elements.chatters.checked)
p += '&chatters';
if (form.elements.rm.checked)
p += '&rm';
if (form.elements.noPronouns.checked)
p += '&no=pronouns';
if (form.elements.noBttv.checked)
p += '&no=bttv';
if (form.elements.noFfz.checked)
p += '&no=ffz';
if (form.elements.no7tv.checked)
p += '&no=7tv';
if (!joins)
return;
const url = new URL ('tchat/?' + p.slice (1), location);
const a = document.createElement ('a');
a.href = url;
a.textContent = url;
form.elements.url.replaceChildren (a);
}