@mfcc64/ytms 13.0.0 → 15.0.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 +1 -1
- package/script.mjs +112 -5
package/package.json
CHANGED
package/script.mjs
CHANGED
|
@@ -44,6 +44,9 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
|
|
|
44
44
|
mid_color: { def:0xdcdcdc, min:0, max:0xffffff },
|
|
45
45
|
interval: { def: 1, min: 1, max: 4 },
|
|
46
46
|
bar_scale: { def: 0, min: 0, max: 4 },
|
|
47
|
+
line_mode: { def: 0, min: 0, max: 2 },
|
|
48
|
+
line_width: { def: 1, min: 1, max: 3 },
|
|
49
|
+
line_color: { def:0xffffff, min:0, max:0xffffff },
|
|
47
50
|
transparent:{ def: 1, min: 0, max: 1 },
|
|
48
51
|
visible: { def: document.location.hostname != "www.youtube.com" ? 1 : 0,
|
|
49
52
|
min: 0, max: 1 },
|
|
@@ -117,8 +120,8 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
|
|
|
117
120
|
e("li", "Press ", e("b", "Ctrl+Alt+H"), " to open/close settings and show/hide the ", e("img", {alt: "YTMS"}, {src: icon_16}), " icon."),
|
|
118
121
|
e("li", "If you want to change the axis, click it."),
|
|
119
122
|
e("li", "If you want to make your change persistent, click ", e("b", "Set as Default Settings"), " button."),
|
|
120
|
-
e("li", e("b", "New Features:"), "
|
|
121
|
-
"
|
|
123
|
+
e("li", e("b", "New Features:"), " Custom color, custom range," +
|
|
124
|
+
" peak color, bar scale, presets, line visualizer."),
|
|
122
125
|
e("li", e("a", {href: "https://github.com/mfcc64/youtube-musical-spectrum#settings"}, {target: "_blank"}, "Read more..."))
|
|
123
126
|
),
|
|
124
127
|
e("p",
|
|
@@ -149,7 +152,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
|
|
|
149
152
|
af_links.style.display = !af_links_timeout || (child_menu.visible?.checked ?? true) ? "block" : "none";
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
const message_version =
|
|
155
|
+
const message_version = 11;
|
|
153
156
|
af_links.shadowRoot.getElementById("message").style.display = get_opt("message_version") == message_version ? "none" : "block";
|
|
154
157
|
af_links.shadowRoot.getElementById("close_message").addEventListener("click", function() {
|
|
155
158
|
set_opt("message_version", message_version);
|
|
@@ -388,7 +391,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
|
|
|
388
391
|
|
|
389
392
|
function bar_scale_sqrt(color) {
|
|
390
393
|
for (let k = 3; k < color.length; k += 4)
|
|
391
|
-
color[k] = Math.sqrt(color[k]);
|
|
394
|
+
color[k] = 0.5 * Math.sqrt(color[k]);
|
|
392
395
|
}
|
|
393
396
|
|
|
394
397
|
function bar_scale_db(color, range) {
|
|
@@ -505,12 +508,115 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
|
|
|
505
508
|
}
|
|
506
509
|
}
|
|
507
510
|
|
|
511
|
+
function create_child_select_line_mode(title, name) {
|
|
512
|
+
var tr = get_menu_table_tr();
|
|
513
|
+
set_common_tr_style(tr);
|
|
514
|
+
var td = document.createElement("td");
|
|
515
|
+
set_common_left_td_style(td);
|
|
516
|
+
td.textContent = title;
|
|
517
|
+
tr.appendChild(td);
|
|
518
|
+
td = document.createElement("td");
|
|
519
|
+
td.colSpan = 3;
|
|
520
|
+
var child = child_menu[name] = document.createElement("select");
|
|
521
|
+
child.style.cursor = "pointer";
|
|
522
|
+
child.style.width = "100%";
|
|
523
|
+
var select_opt = [ "Off", "Static", "Mid Color", "Average", "Spectrum" ];
|
|
524
|
+
for (var k = 0; k < select_opt.length; k++) {
|
|
525
|
+
var opt = document.createElement("option");
|
|
526
|
+
opt.textContent = select_opt[k];
|
|
527
|
+
opt.value = k;
|
|
528
|
+
child.appendChild(opt);
|
|
529
|
+
}
|
|
530
|
+
child.value = get_opt("line_mode");
|
|
531
|
+
td.appendChild(child);
|
|
532
|
+
tr.appendChild(td);
|
|
533
|
+
child.onchange = () => {};
|
|
534
|
+
}
|
|
535
|
+
create_child_select_line_mode("Line Mode", "line_mode");
|
|
536
|
+
create_child_range_menu("Line Width", "line_width");
|
|
537
|
+
create_child_color_menu("Line Color", "line_color");
|
|
538
|
+
|
|
539
|
+
const line_visualizer = new class {
|
|
540
|
+
color = null;
|
|
541
|
+
is_set = false;
|
|
542
|
+
c4 = new Uint32Array(1);
|
|
543
|
+
c = new Uint8ClampedArray(this.c4.buffer);
|
|
544
|
+
|
|
545
|
+
get_color(color) {
|
|
546
|
+
if (child_menu.line_mode.value == "0")
|
|
547
|
+
return;
|
|
548
|
+
|
|
549
|
+
if (this.color?.length != color.length)
|
|
550
|
+
this.color = new Float32Array(color.length);
|
|
551
|
+
|
|
552
|
+
if (this.is_set)
|
|
553
|
+
return;
|
|
554
|
+
|
|
555
|
+
this.color.set(color);
|
|
556
|
+
this.is_set = true;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
render(p) {
|
|
560
|
+
if (child_menu.line_mode.value == "0")
|
|
561
|
+
return;
|
|
562
|
+
|
|
563
|
+
const ctx = p.canvas_ctx, w = p.canvas.width;
|
|
564
|
+
|
|
565
|
+
this.color = this.color ?? new Float32Array(4 * w);
|
|
566
|
+
this.is_set || this.color.fill(0);
|
|
567
|
+
|
|
568
|
+
switch (child_menu.line_mode.value) {
|
|
569
|
+
case "1": {
|
|
570
|
+
ctx.strokeStyle = child_menu.line_color.value;
|
|
571
|
+
} break;
|
|
572
|
+
case "2": {
|
|
573
|
+
ctx.strokeStyle = child_menu.mid_color.value;
|
|
574
|
+
} break;
|
|
575
|
+
case "3": {
|
|
576
|
+
const c_sum = [ 0, 0, 0 ];
|
|
577
|
+
for (let k = 0; k < w; k++)
|
|
578
|
+
for (let m = 0; m < 3; m++)
|
|
579
|
+
c_sum[m] += Math.max(0, this.color[4*k + m]) ** 2;
|
|
580
|
+
for (let m = 0; m < 3; m++)
|
|
581
|
+
this.c[2-m] = Math.sqrt(c_sum[m] / w) * 255.5;
|
|
582
|
+
ctx.strokeStyle = "#" + this.c4[0].toString(16).padStart(6, "0");
|
|
583
|
+
} break;
|
|
584
|
+
case "4": {
|
|
585
|
+
const gradient = ctx.createLinearGradient(0, 0, w, 0);
|
|
586
|
+
for (let k = 0; k < w; k++) {
|
|
587
|
+
for (let m = 0; m < 3; m++)
|
|
588
|
+
this.c[2-m] = this.color[4*k + m] * 255.5;
|
|
589
|
+
gradient.addColorStop((k+0.5) / w, "#" + this.c4[0].toString(16).padStart(6, "0"));
|
|
590
|
+
}
|
|
591
|
+
ctx.strokeStyle = gradient;
|
|
592
|
+
} break;
|
|
593
|
+
default:
|
|
594
|
+
console.warn("Invalid line mode");
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
ctx.lineWidth = child_menu.line_width.value;
|
|
599
|
+
const translate = h => p.bar_h * (1 - h);
|
|
600
|
+
|
|
601
|
+
ctx.beginPath();
|
|
602
|
+
ctx.moveTo(-1, translate(this.color[3]));
|
|
603
|
+
for (let x = 0; x < w; x++)
|
|
604
|
+
ctx.lineTo(x + 0.5, translate(this.color[4*x + 3]));
|
|
605
|
+
ctx.lineTo(w + 1, translate(this.color[4*w - 1]));
|
|
606
|
+
ctx.stroke();
|
|
607
|
+
this.is_set = false;
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
|
|
508
611
|
cqt.actual_render_callback = function(color) {
|
|
509
612
|
transform_color(color);
|
|
510
|
-
detect_peak(color);
|
|
511
613
|
bar_scale_func?.(color);
|
|
614
|
+
line_visualizer.get_color(color);
|
|
615
|
+
detect_peak(color);
|
|
512
616
|
}
|
|
513
617
|
|
|
618
|
+
cqt.post_render_callback = p => line_visualizer.render(p);
|
|
619
|
+
|
|
514
620
|
function create_child_checkbox_menu(title, name, callback) {
|
|
515
621
|
var tr = get_menu_table_tr();
|
|
516
622
|
set_common_tr_style(tr);
|
|
@@ -714,4 +820,5 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
|
|
|
714
820
|
create_menu();
|
|
715
821
|
document.body.appendChild(cqt);
|
|
716
822
|
document.body.appendChild(af_links);
|
|
823
|
+
dispatchEvent(new CustomEvent("youtube-musical-spectrum-is-available"));
|
|
717
824
|
})().catch(e => console.error(e));
|