@mfcc64/ytms 17.0.0 → 18.1.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 +44 -36
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mfcc64/ytms",
3
- "version": "17.0.0",
3
+ "version": "18.1.0",
4
4
  "description": "YouTube Musical Spectrum",
5
5
  "main": "script.mjs",
6
6
  "scripts": {
package/script.mjs CHANGED
@@ -16,7 +16,7 @@
16
16
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
  */
18
18
 
19
- import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
19
+ import {ShowCQTElement, AutoResumeAudioContext} from "../../showcqt-element@2/showcqt-element.mjs";
20
20
 
21
21
  (async function(){
22
22
  const get_asset = (name) => String(new URL(`../ytms-assets@1.0.0/${name}`, import.meta.url));
@@ -34,23 +34,24 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
34
34
  speed: { def: 2, min: 1, max: 12 },
35
35
  mic: { def: 0, min: 0, max: 30 },
36
36
  mic_pan: { def: 0, min:-10, max: 10 },
37
+ interval: { def: 1, min: 1, max: 4 },
37
38
  scale_x: { def:100, min: 30, max:100 },
38
39
  scale_y: { def:100, min: 30, max:100 },
40
+ bar_scale: { def: 0, min: 0, max: 4 },
39
41
  base_note: { def: 16, min: 16, max:100 },
40
42
  semitones: { def:120, min: 36, max:120 },
41
- peak_color: { def:0xffffff, min:0, max:0xffffff },
43
+ scroll: { def: 0, min: 0, max: 1 },
42
44
  left_color: { def:0xdcb900, min:0, max:0xffffff },
43
- right_color:{ def:0x00b9dc, min:0, max:0xffffff },
44
45
  mid_color: { def:0xdcdcdc, min:0, max:0xffffff },
46
+ right_color:{ def:0x00b9dc, min:0, max:0xffffff },
45
47
  saturation: { def: 0, min: 0, max: 30 },
46
48
  hue: { def: 0, min:-18, max: 19 },
47
49
  hue_range: { def: 18, min:-36, max: 36 },
48
- interval: { def: 1, min: 1, max: 4 },
49
- bar_scale: { def: 0, min: 0, max: 4 },
50
50
  line_mode: { def: 0, min: 0, max: 4 },
51
51
  line_width: { def: 1, min: 1, max: 3 },
52
52
  line_color: { def:0xffffff, min:0, max:0xffffff },
53
- scroll: { def: 0, min: 0, max: 1 },
53
+ peak_range: { def: 72, min: 0, max:120 },
54
+ peak_color: { def:0xffffff, min:0, max:0xffffff },
54
55
  coord_color:{ def:0x000000, min:0, max:0xffffff },
55
56
  transparent:{ def: 1, min: 0, max: 1 },
56
57
  visible: { def: document.location.hostname != "www.youtube.com" ? 1 : 0,
@@ -126,7 +127,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
126
127
  e("li", "If you want to change the axis, click it."),
127
128
  e("li", "If you want to make your change persistent, click ", e("b", "Set as Default Settings"), " button."),
128
129
  e("li", e("b", "New Features:"), " Custom color, custom range," +
129
- " peak color, bar scale, line visualizer, hue rotation, more color presets, horizontal scroll, coordinate line."),
130
+ " peak color, bar scale, line visualizer, hue rotation, more color presets, horizontal scroll, coordinate line, peak range."),
130
131
  e("li", e("a", {href: "https://github.com/mfcc64/youtube-musical-spectrum#settings"}, {target: "_blank"}, "Read more..."))
131
132
  ),
132
133
  e("p",
@@ -156,7 +157,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
156
157
  af_links.style.display = !af_links_timeout || (child_menu.visible?.checked ?? true) ? "block" : "none";
157
158
  }
158
159
 
159
- const message_version = 13;
160
+ const message_version = 14;
160
161
  af_links.shadowRoot.getElementById("message").style.display = get_opt("message_version") == message_version ? "none" : "block";
161
162
  af_links.shadowRoot.getElementById("close_message").addEventListener("click", function() {
162
163
  set_opt("message_version", message_version);
@@ -166,23 +167,30 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
166
167
  af_links.shadowRoot.getElementById("message").style.display = "block";
167
168
  });
168
169
 
169
- const media_symbol = Symbol("media_symbol");
170
170
  let svideos = [];
171
171
  if (document.location.hostname == "soundcloud.com") {
172
- await new Promise((res, rej) => {
173
- const old = AudioContext.prototype.createMediaElementSource;
174
- AudioContext.prototype.createMediaElementSource = function(media) {
175
- const retval = old.call(this, media);
176
- ShowCQTElement.global_audio_context = this;
177
- svideos.push(media);
178
- media[media_symbol] = retval;
179
- res();
172
+ ShowCQTElement.global_audio_context = new AutoResumeAudioContext();
173
+ const old = AudioContext.prototype.createMediaElementSource;
174
+ AudioContext.prototype.createMediaElementSource = function(media) {
175
+ const retval = old.call(this, media);
176
+ if (this != ShowCQTElement.global_audio_context) {
177
+ console.warn("audio can't connect to showcqt-element");
180
178
  return retval;
181
- };
182
- });
179
+ }
180
+ retval.connect(cqt.audio_input);
181
+ svideos.push(media);
182
+ return retval;
183
+ };
184
+
185
+ window.AudioContext = function() {
186
+ return ShowCQTElement.global_audio_context;
187
+ };
188
+
189
+ Object.setPrototypeOf(window.AudioContext, AutoResumeAudioContext);
190
+ window.AudioContext.prototype = AutoResumeAudioContext.prototype;
183
191
  }
184
192
 
185
- const cqt = new ShowCQTElement();
193
+ var cqt = new ShowCQTElement();
186
194
  set_fixed_style(cqt, 9999999);
187
195
  let stop_count = 0;
188
196
  const videos = document.getElementsByTagName("video");
@@ -254,7 +262,6 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
254
262
  function soundcloud_layout() {
255
263
  cqt.style.zIndex = 1000;
256
264
  af_links.style.zIndex = 1001;
257
- svideos[0][media_symbol].connect(cqt.audio_input);
258
265
  document.body.style.setProperty("--ytms-cqt-bottom", "var(--play-controls-height, 0px)");
259
266
  }
260
267
 
@@ -614,19 +621,18 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
614
621
  child.onchange();
615
622
  }
616
623
 
617
- create_child_color_menu("Peak Color", "peak_color", child => color_int[3] = color2number(child.value));
624
+ create_child_select_menu("Scroll", "scroll", [ "Vertical", "Horizontal" ], update_cqt_layout);
618
625
 
619
626
  function detect_peak(color) {
620
627
  if (color_int[3] == 0xffffff)
621
628
  return;
622
629
 
623
- for (let k = 4; k < color.length - 4; k += 4) {
630
+ const range = child_menu.peak_range.value / 120 * color.length;
631
+ for (let k = 4; k + 2 < range && k < color.length - 4; k += 4) {
624
632
  if (color[k+3] <= color[k-1] || color[k+3] < color[k+7])
625
633
  continue;
626
634
 
627
- const alpha = (1 - (k+2) / color.length) ** 2 - 0.16;
628
- if (alpha <= 0)
629
- break;
635
+ const alpha = Math.cos(0.5 * Math.PI * (k+2) / range) ** 2;
630
636
 
631
637
  for (let m = 0; m < 3; m++)
632
638
  color[k+m] = Math.min(color[k+m], 1) * (1 - alpha + peak_color[m] * alpha);
@@ -794,14 +800,8 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
794
800
  tr.appendChild(td);
795
801
  }
796
802
 
797
- create_child_select_menu("Scroll", "scroll", [ "Vertical", "Horizontal" ], update_cqt_layout);
798
- create_child_checkbox_menu("Transparent", "transparent", (child) => cqt.dataset.opacity = child.checked ? "transparent" : "opaque");
799
- create_child_checkbox_menu("Visible", "visible", (child) => {
800
- cqt.style.display = child.checked ? "block" : "none";
801
- if (!child.checked)
802
- coord_line_h.style.display = coord_line_v.style.display = "none";
803
- update_af_links();
804
- });
803
+ create_child_range_menu("Peak Range", "peak_range");
804
+ create_child_color_menu("Peak Color", "peak_color", child => color_int[3] = color2number(child.value));
805
805
 
806
806
  function cqt_coord_line_leave(ev) {
807
807
  coord_line_h.style.display = coord_line_v.style.display = "none";
@@ -825,6 +825,14 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
825
825
  }
826
826
  });
827
827
 
828
+ create_child_checkbox_menu("Transparent", "transparent", (child) => cqt.dataset.opacity = child.checked ? "transparent" : "opaque");
829
+ create_child_checkbox_menu("Visible", "visible", (child) => {
830
+ cqt.style.display = child.checked ? "block" : "none";
831
+ if (!child.checked)
832
+ coord_line_h.style.display = coord_line_v.style.display = "none";
833
+ update_af_links();
834
+ });
835
+
828
836
  function create_child_select_presets() {
829
837
  const presets = [
830
838
  { title: "-- Choose Preset --" },
@@ -955,8 +963,8 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
955
963
  setTimeout(function(){ child.value = "Reset Default Settings"; }, 300);
956
964
  });
957
965
 
958
- menu_div.attachShadow({mode: "open"});
959
- menu_div.shadowRoot.appendChild(menu_table);
966
+ (document.location.hostname == "open.spotify.com" ? menu_div.attachShadow({mode: "open"}) : menu_div)
967
+ .appendChild(menu_table);
960
968
  menu.onclick = function() {
961
969
  menu_is_hidden = !menu_is_hidden;
962
970
  if (menu_is_hidden)