@mfcc64/ytms 12.1.2 → 14.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/script.mjs +127 -46
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mfcc64/ytms",
3
- "version": "12.1.2",
3
+ "version": "14.0.0",
4
4
  "description": "YouTube Musical Spectrum",
5
5
  "main": "script.mjs",
6
6
  "scripts": {
package/script.mjs CHANGED
@@ -43,7 +43,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
43
43
  right_color:{ def:0x00b9dc, min:0, max:0xffffff },
44
44
  mid_color: { def:0xdcdcdc, min:0, max:0xffffff },
45
45
  interval: { def: 1, min: 1, max: 4 },
46
- codecs: { def: 1, min: 0, max: 2 },
46
+ bar_scale: { def: 0, min: 0, max: 4 },
47
47
  transparent:{ def: 1, min: 0, max: 1 },
48
48
  visible: { def: document.location.hostname != "www.youtube.com" ? 1 : 0,
49
49
  min: 0, max: 1 },
@@ -118,7 +118,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
118
118
  e("li", "If you want to change the axis, click it."),
119
119
  e("li", "If you want to make your change persistent, click ", e("b", "Set as Default Settings"), " button."),
120
120
  e("li", e("b", "New Features:"), " Hz-scale axis, microphone support, YT Music support, scale options to " +
121
- "reduce CPU usage, custom color, custom range, peak color."),
121
+ "reduce CPU usage, custom color, custom range, peak color, bar scale, presets."),
122
122
  e("li", e("a", {href: "https://github.com/mfcc64/youtube-musical-spectrum#settings"}, {target: "_blank"}, "Read more..."))
123
123
  ),
124
124
  e("p",
@@ -149,7 +149,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
149
149
  af_links.style.display = !af_links_timeout || (child_menu.visible?.checked ?? true) ? "block" : "none";
150
150
  }
151
151
 
152
- const message_version = 9;
152
+ const message_version = 10;
153
153
  af_links.shadowRoot.getElementById("message").style.display = get_opt("message_version") == message_version ? "none" : "block";
154
154
  af_links.shadowRoot.getElementById("close_message").addEventListener("click", function() {
155
155
  set_opt("message_version", message_version);
@@ -351,7 +351,52 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
351
351
  create_child_range_menu("Interval", "interval", (child) => cqt.dataset.interval = child.value);
352
352
  create_child_range_menu("Scale X", "scale_x", (child) => cqt.dataset.scaleX = child.value);
353
353
  create_child_range_menu("Scale Y", "scale_y", (child) => cqt.dataset.scaleY = child.value);
354
- create_child_select_codecs();
354
+
355
+ let bar_scale_func = null;
356
+ function create_child_select_bar_scale(title, name) {
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 = 3;
365
+ var child = child_menu[name] = document.createElement("select");
366
+ child.style.cursor = "pointer";
367
+ child.style.width = "100%";
368
+ var select_opt = [ "Linear", "Sqrt", "Log (40 dB)", "Log (60 dB)", "Log (80 dB)" ];
369
+ for (var k = 0; k < select_opt.length; k++) {
370
+ var opt = document.createElement("option");
371
+ opt.textContent = select_opt[k];
372
+ opt.value = k;
373
+ child.appendChild(opt);
374
+ }
375
+ child.value = get_opt("bar_scale");
376
+ td.appendChild(child);
377
+ tr.appendChild(td);
378
+ child.onchange = function() {
379
+ switch (child.value) {
380
+ case "1": bar_scale_func = bar_scale_sqrt; break;
381
+ case "2": bar_scale_func = c => bar_scale_db(c, 2); break;
382
+ case "3": bar_scale_func = c => bar_scale_db(c, 3); break;
383
+ case "4": bar_scale_func = c => bar_scale_db(c, 4); break;
384
+ default: bar_scale_func = null;
385
+ }
386
+ };
387
+ child.onchange();
388
+
389
+ function bar_scale_sqrt(color) {
390
+ for (let k = 3; k < color.length; k += 4)
391
+ color[k] = Math.sqrt(color[k]);
392
+ }
393
+
394
+ function bar_scale_db(color, range) {
395
+ for (let k = 3; k < color.length; k += 4)
396
+ color[k] = Math.max(0, (Math.log10(color[k]) + range) / range);
397
+ }
398
+ }
399
+ create_child_select_bar_scale("Bar Scale", "bar_scale");
355
400
 
356
401
  function update_range(child) {
357
402
  if (!child_menu.base_note || !child_menu.semitones)
@@ -463,48 +508,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
463
508
  cqt.actual_render_callback = function(color) {
464
509
  transform_color(color);
465
510
  detect_peak(color);
466
- }
467
-
468
- function create_child_select_codecs() {
469
- var tr = get_menu_table_tr();
470
- set_common_tr_style(tr);
471
- var td = document.createElement("td");
472
- set_common_left_td_style(td);
473
- td.textContent = "Codecs";
474
- tr.appendChild(td);
475
- td = document.createElement("td");
476
- td.colSpan = 2;
477
- var child = child_menu["codecs"] = document.createElement("select");
478
- child.style.cursor = "pointer";
479
- child.style.width = "100%";
480
- var select_opt = [ "All", "Block AV1", "Only H.264" ];
481
- for (var k = 0; k < select_opt.length; k++) {
482
- var opt = document.createElement("option");
483
- opt.textContent = select_opt[k];
484
- opt.value = k;
485
- child.appendChild(opt);
486
- }
487
- child.value = get_opt("codecs");
488
- td.appendChild(child);
489
- tr.appendChild(td);
490
- tr.appendChild(document.createElement("td"));
491
- child.onchange = function() {};
492
- const old_func = MediaSource.isTypeSupported;
493
- MediaSource.isTypeSupported = function (mime_type) {
494
- let rejected = [ "av01" ];
495
- switch (child.value) {
496
- case "0": rejected = []; break;
497
- case "1": rejected = [ "av01" ]; break;
498
- case "2": rejected = [ "av01", "vp09", "vp9", "vp08", "vp8" ]; break;
499
- }
500
-
501
- for (const type of rejected) {
502
- if (String(mime_type).indexOf(type) >= 0)
503
- return false;
504
- }
505
-
506
- return old_func.call(this, mime_type);
507
- }
511
+ bar_scale_func?.(color);
508
512
  }
509
513
 
510
514
  function create_child_checkbox_menu(title, name, callback) {
@@ -535,6 +539,82 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
535
539
  update_af_links();
536
540
  });
537
541
 
542
+ function create_child_select_presets() {
543
+ var tr = get_menu_table_tr();
544
+ set_common_tr_style(tr);
545
+ var td = document.createElement("td");
546
+ set_common_left_td_style(td);
547
+ td.textContent = "Presets";
548
+ tr.appendChild(td);
549
+ td = document.createElement("td");
550
+ td.colSpan = 3;
551
+ var child = document.createElement("select");
552
+ child.style.cursor = "pointer";
553
+ child.style.width = "100%";
554
+
555
+ const presets = {
556
+ none: { text: "-- Choose Preset --" },
557
+ color_default: { text: "Color: Default", command: set_color_default },
558
+ color_deep_blue: { text: "Color: Deep Blue", command: set_color_deep_blue },
559
+ color_mono_fire: { text: "Color: Mono Fire", command: set_color_mono_fire },
560
+ color_juicy_lemon: { text: "Color: Juicy Lemon", command: set_color_juicy_lemon },
561
+ color_rain_forest: { text: "Color: Rain Forest", command: set_color_rain_forest },
562
+ scale_960: { text: "Scale: 960", command: () => set_scale_preset(960) },
563
+ scale_1280: { text: "Scale: 1280", command: () => set_scale_preset(1280) }
564
+ };
565
+
566
+ for (const name of Object.keys(presets)) {
567
+ var opt = document.createElement("option");
568
+ opt.textContent = presets[name].text;
569
+ opt.value = name;
570
+ child.appendChild(opt);
571
+ }
572
+
573
+ child.onchange = function() {
574
+ presets[child.value]?.command?.();
575
+ child.value = "none";
576
+ };
577
+
578
+ td.appendChild(child);
579
+ tr.appendChild(td);
580
+
581
+ function set_color_preset(...args) {
582
+ child_menu.left_color.value = number2color(args[0]), child_menu.left_color.onchange();
583
+ child_menu.mid_color.value = number2color(args[1]), child_menu.mid_color.onchange();
584
+ child_menu.right_color.value = number2color(args[2]), child_menu.right_color.onchange();
585
+ child_menu.peak_color.value = number2color(args[3]), child_menu.peak_color.onchange();
586
+ child_menu.brightness.value = args[4], child_menu.brightness.onchange();
587
+ }
588
+
589
+ function set_color_default() {
590
+ set_color_preset(defaults.left_color.def, defaults.mid_color.def, defaults.right_color.def,
591
+ defaults.peak_color.def, defaults.brightness.def);
592
+ }
593
+
594
+ function set_color_deep_blue() {
595
+ set_color_preset(0x6400b9, 0x6464dc, 0x0064b9, 0x0000ff, 50);
596
+ }
597
+
598
+ function set_color_mono_fire() {
599
+ set_color_preset(0xb94a25, 0xdc582c, 0xb94a25, 0xff0000, 70);
600
+ }
601
+
602
+ function set_color_juicy_lemon() {
603
+ set_color_preset(0xff004a, 0xffff58, 0x00ff4a, 0xffffff, 33);
604
+ }
605
+
606
+ function set_color_rain_forest() {
607
+ set_color_preset(0x64b900, 0x64dc64, 0x00b964, 0x00ff00, 33);
608
+ }
609
+
610
+ function set_scale_preset(target) {
611
+ const scale = Math.max(30, Math.min(100, Math.round(target / window.innerWidth * 100)));
612
+ child_menu.scale_x.value = scale, child_menu.scale_x.onchange();
613
+ child_menu.scale_y.value = scale, child_menu.scale_y.onchange();
614
+ }
615
+ }
616
+ create_child_select_presets();
617
+
538
618
  current_tr = null;
539
619
  set_common_tr_style(get_menu_table_tr());
540
620
  current_tr = null;
@@ -634,4 +714,5 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
634
714
  create_menu();
635
715
  document.body.appendChild(cqt);
636
716
  document.body.appendChild(af_links);
717
+ dispatchEvent(new CustomEvent("youtube-musical-spectrum-is-available"));
637
718
  })().catch(e => console.error(e));