-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
248 lines (237 loc) · 8.8 KB
/
index.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<body>
<h1>Clippy</h1>
<p>Use the controls below to change settings for your overlay.
Press "Copy Overlay URL" <b>after</b> you change any settings,
then paste into your browser source url.</p>
<p id="login" hidden></p>
<p id="pass" hidden></p>
<div id="flex">
<div>
<input id='newCommand' type="text">
<button onclick="addCommand()">Add Command</button>
<p>Click on a command to remove it</p>
<ul id="commands">
<li><button class="command" onclick="removeCommand(this)">!so</button></li>
<li><button class="command" onclick="removeCommand(this)">!shoutout</button></li>
</ul>
<br>
<input id="autoplay" type="checkbox">
<label for="autoplay">Auto-play clips from my channel</label>
<br>
<input id="autoso" type="checkbox">
<label for="autoso">Automatically send the first clippy command when getting raided</label>
<br>
<input id="firstOn" type="checkbox" onchange="enabled('first',this.checked)">
<label for="firstOn">Search the last </label>
<input id="first" type="number" min="1" max="100" step="1" value="20" disabled>
<label for="first"> clips</label>
<br>
<input id="noreplay" type="checkbox" checked>
<label for="noreplay">Don't use clips already played this session</label>
<br>
<input id="samegame" type="checkbox">
<label for="samegame">Find clips in my category</label>
<br>
<input id="lastgame" type="checkbox">
<label for="lastgame">Find clips in the target's category</label>
<br>
<input id="durOn" type="checkbox" onchange="enabled('dur',this.checked)">
<label for="durOn">Max clip duration in seconds: </label>
<input id="dur" type="number" min="5" max="60" step="0.1" value="60" disabled>
<br>
<input id="views" type="checkbox">
<label for="views">Most Viewed</label>
<br>
<input id="cutOn" type="checkbox" onclick="enabled('cut',this.checked)">
<label for="cutOn">Clip cutoff in seconds: </label>
<input id="cut" type="number" min="5" max="60" step="0.1" value="60" disabled>
<br>
<button onclick="copyURL()">Copy Overlay URL</button>
</div>
<div>
<input type="checkbox" id="messageOn">
<label for="messageOn">Send a message in chat</label>
<br>
<textarea id="message">Check out $target at https://twitch.tv/$target</textarea>
<br>
<label for="headerText">Header:</label>
<input type="text" id="headerText" value="Check out $target">
<br>
<label>
Custom CSS URI:
<input type="text" value="twitch.css">
<button onclick="loadCSS(this)">Load CSS</button>
</label>
<br>
<label>
Custom CSS File:
<input type="file" accept="text/css" oninput="readCSS(this)">
</label>
<br>
<textarea id="customcss"></textarea>
<br>
</div>
</div>
</body>
<style>
div {
margin-right: 20px;
}
#flex {
display:flex;
}
textarea {
width: 360px;
height: 50px;
}
#customcss {
height: 360px;
white-space: pre;
}
* {
vertical-align: top;
}
</style>
<script>
const client_id='72wtxvzs6erokrj33lk105whmoo381';
const newCommandHTML='<li><button class="command" onclick="removeCommand(this)">!command</button></li>';
const overlayURLBase=window.location.origin+window.location.pathname+'overlay.html';
function enabled(element,state){
document.getElementById(element).disabled=!state;
}
async function getPass() {
if(window.location.search){
localStorage.setItem('search',window.location.search)
}
try {
const pass = new URLSearchParams(document.location.hash.replace('#', '?')).get('access_token')
if (!pass) {
throw 'missing access token'
}
const search=localStorage.getItem('search')
if(search){
localStorage.removeItem('search')
const params=new URLSearchParams(decodeURIComponent(search))
params.set('pass',pass)
window.location.href=overlayURLBase+'?'+params.toString()
}
return pass;
} catch (e) {
window.location.href = encodeURI(
'https://id.twitch.tv/oauth2/authorize'
+ '?response_type=token'
+ '&client_id='+client_id
+ '&scope=chat:read chat:edit moderation:read'
)+'&redirect_uri='+window.location.href.split('?')[0];
throw e;
}
}
async function getLogin(pass) {
const response=await fetch('https://api.twitch.tv/helix/users'
,{
headers:{
'Authorization':'Bearer '+pass
,'Client-Id':client_id
}
}
)
const json=await response.json()
return json['data'][0]['login'];
}
async function init(){
pass.value=await getPass();
login.value=await getLogin(pass.value);
config=JSON.parse(localStorage.getItem('clippy'))
for(const [id, value] of Object.entries(config)){
console.log(id,value)
const element=document.getElementById(id)
if(element==null){
continue
}
switch(element.tagName.toLowerCase()){
case 'input':
switch(element.type){
case 'checkbox':
element.checked=value
if(element.onchange){
element.onchange()
}
break
default:
element.value=value
}
break
case 'ul':
for(const button of element.querySelectorAll('button')){
removeCommand(button)
}
for(const command of value){
addCommand(command)
}
break
default:
element.innerHTML=value
}
}
}
async function removeCommand(element){
element.parentElement.remove()
}
async function addCommand(commandName=null){
if(commandName==null){
commandName=newCommand.value;
}
const commandHTML=newCommandHTML.replace('!command',commandName);
console.log(commandHTML)
commands.innerHTML+=commandHTML;
}
async function copyURL() {
let settings = {}
settings['customcss']=customcss.value.split(' ').filter((string)=>string!='').join(' ')
settings['client_id'] = client_id;
settings['login'] = document.getElementById('login').value;
settings['pass'] = document.getElementById('pass').value;
settings['commands'] = []
for (const button of document.getElementsByClassName('command')) {
settings['commands'].push(button.innerHTML);
}
for (const element of document.querySelectorAll('input,textarea')) {
switch (element.id) {
case '':
case 'newCommand':
case 'customcss':
continue;
}
switch (element.type) {
case 'file':
case 'url':
continue;
case 'checkbox':
settings[element.id] = element.checked;
break;
default:
settings[element.id] = element.value;
break;
}
}
const url = new URL(overlayURLBase);
url.search = new URLSearchParams(settings)
navigator.clipboard.writeText(url);
localStorage.setItem('clippy',JSON.stringify(settings))
}
async function readCSS(input){
const reader = new FileReader();
reader.addEventListener("load", function () {
customcss.value+='\n'+reader.result
}, false);
reader.readAsText(input.files[0]);
}
async function loadCSS(button){
let data=button.parentElement.querySelector('input').value
data=await fetch(data)
data=await data.text()
customcss.value+='\n'+data
}
init();
</script>