@mfcc64/ytms 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -0
- package/script.mjs +476 -0
package/package.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mfcc64/ytms",
|
|
3
|
+
"version": "7.2.0",
|
|
4
|
+
"description": "YouTube Musical Spectrum",
|
|
5
|
+
"main": "script.mjs",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "Muhammad Faiz",
|
|
10
|
+
"license": "LGPL-3.0-or-later"
|
|
11
|
+
}
|
package/script.mjs
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import "../../showcqt-element@1.3.1/showcqt-element.mjs";
|
|
2
|
+
|
|
3
|
+
(async function(){
|
|
4
|
+
const current_script = import.meta.url;
|
|
5
|
+
const get_asset = (name) => String(new URL(`../ytms-assets@1.0.0/${name}`, current_script));
|
|
6
|
+
const axis_list = [
|
|
7
|
+
"",
|
|
8
|
+
get_asset("axis-hz-1920x32.png")
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const defaults = {
|
|
12
|
+
height: { def: 33, min: 20, max:100 },
|
|
13
|
+
bar: { def: 17, min: 1, max: 33 },
|
|
14
|
+
waterfall: { def: 33, min: 0, max: 70 },
|
|
15
|
+
brightness: { def: 17, min: 1, max: 70 },
|
|
16
|
+
bass: { def:-30, min:-50, max: 0 },
|
|
17
|
+
speed: { def: 2, min: 1, max: 12 },
|
|
18
|
+
mic: { def: 0, min: 0, max: 30 },
|
|
19
|
+
mic_pan: { def: 0, min:-10, max: 10 },
|
|
20
|
+
scale_x: { def:100, min: 30, max:100 },
|
|
21
|
+
scale_y: { def:100, min: 30, max:100 },
|
|
22
|
+
interval: { def: 1, min: 1, max: 4 },
|
|
23
|
+
codecs: { def: 1, min: 0, max: 2 },
|
|
24
|
+
transparent:{ def: 1, min: 0, max: 1 },
|
|
25
|
+
visible: { def: 1, min: 0, max: 1 },
|
|
26
|
+
axis: { def: 0, min: 0, max: axis_list.length - 1 }
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const opt_prefix = "__youtube_musical_spectrum_opt_";
|
|
30
|
+
function get_opt(name) {
|
|
31
|
+
var value = localStorage.getItem(opt_prefix + name);
|
|
32
|
+
if (!defaults[name])
|
|
33
|
+
return value;
|
|
34
|
+
if (!value)
|
|
35
|
+
return defaults[name].def;
|
|
36
|
+
value = Math.round(value);
|
|
37
|
+
return Math.max(defaults[name].min, Math.min(defaults[name].max, isNaN(value) ? defaults[name].def : value));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function set_opt(name, value) {
|
|
41
|
+
value = Math.round(value);
|
|
42
|
+
if (defaults[name])
|
|
43
|
+
value = Math.max(defaults[name].min, Math.min(defaults[name].max, isNaN(value) ? defaults[name].def : value));
|
|
44
|
+
try {
|
|
45
|
+
localStorage.setItem(opt_prefix + name, value);
|
|
46
|
+
} catch(e) {
|
|
47
|
+
console.warn(`Unable to store option ${name}.`, e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var child_menu = {};
|
|
52
|
+
|
|
53
|
+
function set_fixed_style(element, z_index) {
|
|
54
|
+
element.style.position = "fixed";
|
|
55
|
+
element.style.border = "none";
|
|
56
|
+
element.style.margin = "0px";
|
|
57
|
+
element.style.padding = "0px";
|
|
58
|
+
element.style.zIndex = z_index;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const icon_16 = get_asset("icon-16.png");
|
|
62
|
+
const af_links = document.createElement("div");
|
|
63
|
+
set_fixed_style(af_links, 10000001);
|
|
64
|
+
af_links.style.padding = "8px";
|
|
65
|
+
af_links.style.border = "thin solid white";
|
|
66
|
+
af_links.style.backgroundColor = "#000000DD";
|
|
67
|
+
af_links.style.color = "#FFFFFF";
|
|
68
|
+
af_links.style.fontSize = "10pt";
|
|
69
|
+
af_links.style.right = "8px";
|
|
70
|
+
af_links.style.bottom = "8px";
|
|
71
|
+
af_links.style.opacity = 1;
|
|
72
|
+
af_links.attachShadow({mode: "open"}).innerHTML =
|
|
73
|
+
`<style>
|
|
74
|
+
:host { opacity: 0; max-width: 700px; }
|
|
75
|
+
:host(:hover) { opacity: 1; }
|
|
76
|
+
img { vertical-align: middle; }
|
|
77
|
+
</style>
|
|
78
|
+
<div id="message">
|
|
79
|
+
<h3>YouTube Musical Spectrum</h3>
|
|
80
|
+
<ul>
|
|
81
|
+
<li>Click the <img alt="YTMS" src="${icon_16}"/> icon at the top left corner to open/close settings.</li>
|
|
82
|
+
<li>Press <b>Ctrl+Alt+H</b> to open/close settings and show/hide the <img alt="YTMS" src="${icon_16}"/> icon.</li>
|
|
83
|
+
<li>Press <b>Ctrl+Alt+G</b> as a shortcut to show/hide visualization.</li>
|
|
84
|
+
<li>If you want to change the axis, click it.</li>
|
|
85
|
+
<li>If you want to make your change persistent, click <b>Set as Default Settings</b> button.</li>
|
|
86
|
+
<li><b>New Features:</b> Hz-scale axis, microphone support, YT Music support, scale options to
|
|
87
|
+
reduce CPU usage.</li>
|
|
88
|
+
<li><a href="https://github.com/mfcc64/youtube-musical-spectrum#settings" target="_blank">Read more...</a></li>
|
|
89
|
+
</ul>
|
|
90
|
+
<p>
|
|
91
|
+
<button id="close_message" style="cursor: pointer;">Close</button>
|
|
92
|
+
(Click the <img alt="YTMS" src="${icon_16}"/> icon below to reopen again)
|
|
93
|
+
</p>
|
|
94
|
+
</div>
|
|
95
|
+
<div style="text-align: right;">
|
|
96
|
+
<img alt="YTMS" src="${icon_16}" style="cursor: pointer;" id="open_message"/>
|
|
97
|
+
Support me on
|
|
98
|
+
<a href="https://www.youtube.com/@mfcc64" target="_blank">YouTube</a>
|
|
99
|
+
<a href="https://www.patreon.com/mfcc64" target="_blank">Patreon</a>
|
|
100
|
+
<a href="https://github.com/mfcc64" target="_blank">GitHub</a>
|
|
101
|
+
<a href="https://paypal.me/mfcc64" target="_blank">PayPal</a>
|
|
102
|
+
<a href="https://saweria.co/mfcc64" target="_blank">Saweria</a>
|
|
103
|
+
</div>`;
|
|
104
|
+
setTimeout(() => af_links.style.opacity = "", 15000);
|
|
105
|
+
|
|
106
|
+
const message_version = 6;
|
|
107
|
+
af_links.shadowRoot.getElementById("message").style.display = get_opt("message_version") == message_version ? "none" : "block";
|
|
108
|
+
af_links.shadowRoot.getElementById("close_message").addEventListener("click", function() {
|
|
109
|
+
set_opt("message_version", message_version);
|
|
110
|
+
af_links.shadowRoot.getElementById("message").style.display = "none";
|
|
111
|
+
});
|
|
112
|
+
af_links.shadowRoot.getElementById("open_message").addEventListener("click", function() {
|
|
113
|
+
af_links.shadowRoot.getElementById("message").style.display = "block";
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const cqt = document.createElement("showcqt-element");
|
|
117
|
+
set_fixed_style(cqt, 9999999);
|
|
118
|
+
cqt.style.left = cqt.style.bottom = 0;
|
|
119
|
+
cqt.style.width = "100%";
|
|
120
|
+
let stop_count = 0;
|
|
121
|
+
const videos = document.getElementsByTagName("video");
|
|
122
|
+
let svideos = [];
|
|
123
|
+
cqt.render_callback = function() {
|
|
124
|
+
let need_refresh = (videos.length != svideos.length);
|
|
125
|
+
for (let k = 0; k < videos.length && !need_refresh; k++)
|
|
126
|
+
need_refresh = (videos[k] != svideos[k]);
|
|
127
|
+
if (need_refresh) {
|
|
128
|
+
this.dataset.inputs = "video";
|
|
129
|
+
svideos = Array.from(videos);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let state = 0;
|
|
133
|
+
for (let k = 0; k < svideos.length && state < 2; k++)
|
|
134
|
+
if (svideos[k].src && !svideos[k].ended)
|
|
135
|
+
state = svideos[k].paused ? 1 : 2;
|
|
136
|
+
|
|
137
|
+
(state == 1) ? this.render_pause() : this.render_play();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
function ytmusic_layout() {
|
|
141
|
+
const style = document.createElement("style");
|
|
142
|
+
style.textContent = `
|
|
143
|
+
ytmusic-player-bar { z-index: 12 !important; }
|
|
144
|
+
#main-panel { align-items: flex-start !important; }
|
|
145
|
+
#player { margin-top: 0 !important; }`;
|
|
146
|
+
document.head.appendChild(style);
|
|
147
|
+
af_links.style.zIndex = 11;
|
|
148
|
+
af_links.style.bottom = "calc(var(--ytmusic-player-bar-height, 0) + 8px)";
|
|
149
|
+
cqt.style.zIndex = 10;
|
|
150
|
+
|
|
151
|
+
function update_cqt_bottom() {
|
|
152
|
+
if (document.fullscreenElement) {
|
|
153
|
+
cqt.style.bottom = 0;
|
|
154
|
+
af_links.style.visibility = "hidden";
|
|
155
|
+
} else {
|
|
156
|
+
cqt.style.bottom = "var(--ytmusic-player-bar-height, 0)";
|
|
157
|
+
af_links.style.visibility = "visible";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
addEventListener("fullscreenchange", update_cqt_bottom);
|
|
162
|
+
update_cqt_bottom();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (document.location.hostname == "music.youtube.com")
|
|
166
|
+
ytmusic_layout();
|
|
167
|
+
|
|
168
|
+
child_menu.axis = { value: get_opt("axis") };
|
|
169
|
+
child_menu.axis.onchange = function() { cqt.dataset.axis = axis_list[child_menu.axis.value]; };
|
|
170
|
+
cqt.shadowRoot.getElementById("axis").addEventListener("click", function() {
|
|
171
|
+
child_menu.axis.value = (child_menu.axis.value + 1) % axis_list.length;
|
|
172
|
+
child_menu.axis.onchange();
|
|
173
|
+
});
|
|
174
|
+
child_menu.axis.onchange();
|
|
175
|
+
|
|
176
|
+
function create_menu() {
|
|
177
|
+
var menu = document.createElement("button");
|
|
178
|
+
set_fixed_style(menu, 10000002);
|
|
179
|
+
menu.style.left = "0px";
|
|
180
|
+
menu.style.top = "0px";
|
|
181
|
+
menu.style.backgroundColor = "transparent";
|
|
182
|
+
menu.style.cursor = "pointer";
|
|
183
|
+
menu.style.outline = "none";
|
|
184
|
+
menu.style.lineHeight = "0px";
|
|
185
|
+
menu.title = "YouTube Musical Spectrum";
|
|
186
|
+
var menu_img = document.createElement("img");
|
|
187
|
+
menu_img.src = get_asset("icon-24.png");
|
|
188
|
+
menu_img.alt = "Menu";
|
|
189
|
+
menu.appendChild(menu_img);
|
|
190
|
+
var menu_is_hidden = true;
|
|
191
|
+
var menu_div = document.createElement("div");
|
|
192
|
+
var menu_table = document.createElement("table");
|
|
193
|
+
set_fixed_style(menu_div, 10000001);
|
|
194
|
+
menu_div.style.left = "0px";
|
|
195
|
+
menu_div.style.top = "0px";
|
|
196
|
+
menu_div.style.padding = "8px";
|
|
197
|
+
menu_div.style.border = "thin solid white";
|
|
198
|
+
menu_div.style.color = "white";
|
|
199
|
+
menu_div.style.fontSize = "10pt";
|
|
200
|
+
menu_div.style.backgroundColor = "#000000DD";
|
|
201
|
+
menu_div.style.verticalAlign = "middle";
|
|
202
|
+
menu_div.style.maxHeight = "90%";
|
|
203
|
+
menu_div.style.overflow = "auto";
|
|
204
|
+
menu_div.style.scrollbarWidth = "none";
|
|
205
|
+
menu_div.style.visibility = "hidden";
|
|
206
|
+
menu_div.style.cursor = "default";
|
|
207
|
+
|
|
208
|
+
var current_tr = null;
|
|
209
|
+
|
|
210
|
+
function get_menu_table_tr() {
|
|
211
|
+
if (current_tr)
|
|
212
|
+
return current_tr;
|
|
213
|
+
return document.createElement("tr");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function append_menu_table_tr(tr) {
|
|
217
|
+
if (current_tr) {
|
|
218
|
+
current_tr = null;
|
|
219
|
+
} else {
|
|
220
|
+
menu_table.appendChild(tr);
|
|
221
|
+
current_tr = tr;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function set_common_tr_style(tr) {
|
|
226
|
+
tr.style.height = "32px";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function set_common_left_td_style(td) {
|
|
230
|
+
td.style.paddingLeft = "48px";
|
|
231
|
+
td.style.width = "80px";
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function create_child_range_menu(title, name, callback) {
|
|
235
|
+
var tr = get_menu_table_tr();
|
|
236
|
+
set_common_tr_style(tr);
|
|
237
|
+
var td = document.createElement("td");
|
|
238
|
+
set_common_left_td_style(td);
|
|
239
|
+
td.textContent = title;
|
|
240
|
+
tr.appendChild(td);
|
|
241
|
+
td = document.createElement("td");
|
|
242
|
+
var child = child_menu[name] = document.createElement("input");
|
|
243
|
+
var child_text = document.createElement("td");
|
|
244
|
+
child.style.cursor = "pointer";
|
|
245
|
+
child.type = "range";
|
|
246
|
+
child.min = defaults[name].min;
|
|
247
|
+
child.max = defaults[name].max;
|
|
248
|
+
child.step = 1;
|
|
249
|
+
child.value = get_opt(name);
|
|
250
|
+
child.oninput = function() {
|
|
251
|
+
child_text.textContent = this.value;
|
|
252
|
+
};
|
|
253
|
+
child.onchange = function() {
|
|
254
|
+
this.oninput();
|
|
255
|
+
if (callback)
|
|
256
|
+
callback(child);
|
|
257
|
+
};
|
|
258
|
+
td.appendChild(child);
|
|
259
|
+
tr.appendChild(td);
|
|
260
|
+
tr.appendChild(child_text);
|
|
261
|
+
child_text.style.textAlign = "right";
|
|
262
|
+
child_text.style.width = "32px";
|
|
263
|
+
child.onchange();
|
|
264
|
+
append_menu_table_tr(tr);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const mic = { };
|
|
268
|
+
mic.pan = cqt.audio_context.createStereoPanner();
|
|
269
|
+
mic.gain = cqt.audio_context.createGain();
|
|
270
|
+
mic.pan.connect(cqt.audio_input);
|
|
271
|
+
mic.gain.connect(mic.pan);
|
|
272
|
+
|
|
273
|
+
create_child_range_menu("Height", "height", (child) => cqt.style.height = child.value + "%");
|
|
274
|
+
create_child_range_menu("Bar", "bar", (child) => cqt.dataset.bar = child.value);
|
|
275
|
+
create_child_range_menu("Waterfall", "waterfall", (child) => cqt.dataset.waterfall = child.value);
|
|
276
|
+
create_child_range_menu("Brightness", "brightness", (child) => cqt.dataset.brightness = child.value);
|
|
277
|
+
create_child_range_menu("Bass", "bass", (child) => cqt.dataset.bass = child.value);
|
|
278
|
+
create_child_range_menu("Speed", "speed", (child) => cqt.dataset.speed = child.value);
|
|
279
|
+
create_child_range_menu("Mic", "mic", async (child) => {
|
|
280
|
+
mic.gain.gain.value = child.value * child.value / 100;
|
|
281
|
+
if (!mic.promise) {
|
|
282
|
+
if (child.value == 0)
|
|
283
|
+
return;
|
|
284
|
+
const media_params = {
|
|
285
|
+
audio: {
|
|
286
|
+
echoCancellation: false,
|
|
287
|
+
autoGainControl: false,
|
|
288
|
+
noiseSuppression: false,
|
|
289
|
+
latency: 0,
|
|
290
|
+
channelCount: 2,
|
|
291
|
+
sampleRate: cqt.audio_context.sampleRate
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
mic.promise = navigator.mediaDevices.getUserMedia(media_params);
|
|
295
|
+
mic.stream = await mic.promise;
|
|
296
|
+
mic.source = cqt.audio_context.createMediaStreamSource(mic.stream);
|
|
297
|
+
mic.source.connect(mic.gain);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (mic.source && child.value == 0) {
|
|
301
|
+
mic.source.disconnect(mic.gain);
|
|
302
|
+
for (const track of mic.stream.getTracks())
|
|
303
|
+
track.stop();
|
|
304
|
+
mic.source = mic.stream = mic.promise = null;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
create_child_range_menu("Mic Pan", "mic_pan", (child) => mic.pan.pan.value = child.value / 10);
|
|
308
|
+
create_child_range_menu("Scale X", "scale_x", (child) => cqt.dataset.scaleX = child.value);
|
|
309
|
+
create_child_range_menu("Scale Y", "scale_y", (child) => cqt.dataset.scaleY = child.value);
|
|
310
|
+
create_child_range_menu("Interval", "interval", (child) => cqt.dataset.interval = child.value);
|
|
311
|
+
|
|
312
|
+
function create_child_select_codecs() {
|
|
313
|
+
var tr = get_menu_table_tr();
|
|
314
|
+
set_common_tr_style(tr);
|
|
315
|
+
var td = document.createElement("td");
|
|
316
|
+
set_common_left_td_style(td);
|
|
317
|
+
td.textContent = "Codecs";
|
|
318
|
+
tr.appendChild(td);
|
|
319
|
+
td = document.createElement("td");
|
|
320
|
+
td.colSpan = 2;
|
|
321
|
+
var child = child_menu["codecs"] = document.createElement("select");
|
|
322
|
+
child.style.cursor = "pointer";
|
|
323
|
+
var select_opt = [ "All", "Block AV1", "Only H.264" ];
|
|
324
|
+
for (var k = 0; k < select_opt.length; k++) {
|
|
325
|
+
var opt = document.createElement("option");
|
|
326
|
+
opt.textContent = select_opt[k];
|
|
327
|
+
opt.value = k;
|
|
328
|
+
child.appendChild(opt);
|
|
329
|
+
}
|
|
330
|
+
child.value = get_opt("codecs");
|
|
331
|
+
td.appendChild(child);
|
|
332
|
+
tr.appendChild(td);
|
|
333
|
+
append_menu_table_tr(tr);
|
|
334
|
+
child.onchange = function() {};
|
|
335
|
+
const old_func = MediaSource.isTypeSupported;
|
|
336
|
+
MediaSource.isTypeSupported = function (mime_type) {
|
|
337
|
+
let rejected = [ "av01" ];
|
|
338
|
+
switch (child.value) {
|
|
339
|
+
case "0": rejected = []; break;
|
|
340
|
+
case "1": rejected = [ "av01" ]; break;
|
|
341
|
+
case "2": rejected = [ "av01", "vp09", "vp9", "vp08", "vp8" ]; break;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
for (const type of rejected) {
|
|
345
|
+
if (String(mime_type).indexOf(type) >= 0)
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return old_func.call(this, mime_type);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
create_child_select_codecs();
|
|
353
|
+
|
|
354
|
+
current_tr = null;
|
|
355
|
+
|
|
356
|
+
function create_child_checkbox_menu(title, name, callback) {
|
|
357
|
+
var tr = get_menu_table_tr();
|
|
358
|
+
set_common_tr_style(tr);
|
|
359
|
+
var td = document.createElement("td");
|
|
360
|
+
set_common_left_td_style(td);
|
|
361
|
+
td.textContent = title;
|
|
362
|
+
tr.appendChild(td);
|
|
363
|
+
td = document.createElement("td");
|
|
364
|
+
td.colSpan = 2;
|
|
365
|
+
var child = child_menu[name] = document.createElement("input");
|
|
366
|
+
child.style.cursor = "pointer";
|
|
367
|
+
child.type = "checkbox";
|
|
368
|
+
child.checked = get_opt(name) * 1;
|
|
369
|
+
child.onchange = function() {
|
|
370
|
+
if (callback)
|
|
371
|
+
callback(child);
|
|
372
|
+
};
|
|
373
|
+
child.onchange();
|
|
374
|
+
td.appendChild(child);
|
|
375
|
+
tr.appendChild(td);
|
|
376
|
+
append_menu_table_tr(tr);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
create_child_checkbox_menu("Transparent", "transparent", (child) => cqt.dataset.opacity = child.checked ? "transparent" : "opaque");
|
|
380
|
+
|
|
381
|
+
create_child_checkbox_menu("Visible", "visible", (child) => af_links.style.display = cqt.style.display = child.checked ? "block" : "none");
|
|
382
|
+
|
|
383
|
+
current_tr = null;
|
|
384
|
+
|
|
385
|
+
function create_child_button_menu(title, callback) {
|
|
386
|
+
var tr = get_menu_table_tr();
|
|
387
|
+
//set_common_tr_style(tr);
|
|
388
|
+
var td = document.createElement("td");
|
|
389
|
+
set_common_left_td_style(td);
|
|
390
|
+
td.colSpan = 3;
|
|
391
|
+
var child = document.createElement("input");
|
|
392
|
+
child.type = "button";
|
|
393
|
+
child.value = title;
|
|
394
|
+
child.style.cursor = "pointer";
|
|
395
|
+
child.style.fontFamily = "inherit";
|
|
396
|
+
child.style.fontSize = "inherit";
|
|
397
|
+
child.onclick = function() {
|
|
398
|
+
if (callback)
|
|
399
|
+
callback(child);
|
|
400
|
+
};
|
|
401
|
+
td.appendChild(child);
|
|
402
|
+
tr.appendChild(td);
|
|
403
|
+
append_menu_table_tr(tr);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
create_child_button_menu("Reset Settings", function() {
|
|
407
|
+
for (const name in child_menu) {
|
|
408
|
+
if (child_menu[name].type == "checkbox")
|
|
409
|
+
child_menu[name].checked = get_opt(name) * 1;
|
|
410
|
+
else
|
|
411
|
+
child_menu[name].value = get_opt(name);
|
|
412
|
+
child_menu[name].onchange();
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
create_child_button_menu("Set as Default Settings", function(child) {
|
|
417
|
+
child.value = "Saving...";
|
|
418
|
+
for (const name in child_menu) {
|
|
419
|
+
if (child_menu[name].type == "checkbox")
|
|
420
|
+
set_opt(name, child_menu[name].checked)
|
|
421
|
+
else
|
|
422
|
+
set_opt(name, child_menu[name].value);
|
|
423
|
+
}
|
|
424
|
+
setTimeout(function(){ child.value = "Set as Default Settings"; }, 300);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
create_child_button_menu("Reset Default Settings", function(child) {
|
|
428
|
+
child.value = "Resetting...";
|
|
429
|
+
for (const name in defaults)
|
|
430
|
+
set_opt(name, defaults[name].value);
|
|
431
|
+
setTimeout(function(){ child.value = "Reset Default Settings"; }, 300);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
menu_div.appendChild(menu_table);
|
|
435
|
+
menu.onclick = function() {
|
|
436
|
+
menu_is_hidden = !menu_is_hidden;
|
|
437
|
+
if (menu_is_hidden)
|
|
438
|
+
menu_div.style.visibility = "hidden";
|
|
439
|
+
else
|
|
440
|
+
menu_div.style.visibility = "visible";
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
var hide_menu = !!(get_opt("hide_menu") * 1);
|
|
444
|
+
menu.style.visibility = hide_menu ? "hidden" : "visible";
|
|
445
|
+
document.body.insertBefore(menu_div, document.body.firstChild);
|
|
446
|
+
document.body.insertBefore(menu, document.body.firstChild);
|
|
447
|
+
document.addEventListener("keydown", function(key) {
|
|
448
|
+
if (key.ctrlKey && key.altKey && !key.shiftKey && !key.metaKey && !key.repeat) {
|
|
449
|
+
switch (key.code) {
|
|
450
|
+
case "KeyH":
|
|
451
|
+
hide_menu = !hide_menu;
|
|
452
|
+
if (hide_menu) {
|
|
453
|
+
menu_is_hidden = true;
|
|
454
|
+
menu.style.visibility = "hidden";
|
|
455
|
+
menu_div.style.visibility = "hidden";
|
|
456
|
+
} else {
|
|
457
|
+
menu_is_hidden = false;
|
|
458
|
+
menu.style.visibility = "visible";
|
|
459
|
+
menu_div.style.visibility = "visible";
|
|
460
|
+
menu.focus();
|
|
461
|
+
}
|
|
462
|
+
set_opt("hide_menu", hide_menu * 1);
|
|
463
|
+
break;
|
|
464
|
+
case "KeyG":
|
|
465
|
+
child_menu.visible.checked = !child_menu.visible.checked;
|
|
466
|
+
child_menu.visible.onchange();
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
create_menu();
|
|
474
|
+
document.body.appendChild(cqt);
|
|
475
|
+
document.body.appendChild(af_links);
|
|
476
|
+
})().catch(e => console.error(e));
|