@mfcc64/ytms 18.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 +22 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mfcc64/ytms",
3
- "version": "18.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));
@@ -167,23 +167,30 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
167
167
  af_links.shadowRoot.getElementById("message").style.display = "block";
168
168
  });
169
169
 
170
- const media_symbol = Symbol("media_symbol");
171
170
  let svideos = [];
172
171
  if (document.location.hostname == "soundcloud.com") {
173
- await new Promise((res, rej) => {
174
- const old = AudioContext.prototype.createMediaElementSource;
175
- AudioContext.prototype.createMediaElementSource = function(media) {
176
- const retval = old.call(this, media);
177
- ShowCQTElement.global_audio_context = this;
178
- svideos.push(media);
179
- media[media_symbol] = retval;
180
- 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");
181
178
  return retval;
182
- };
183
- });
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;
184
191
  }
185
192
 
186
- const cqt = new ShowCQTElement();
193
+ var cqt = new ShowCQTElement();
187
194
  set_fixed_style(cqt, 9999999);
188
195
  let stop_count = 0;
189
196
  const videos = document.getElementsByTagName("video");
@@ -255,7 +262,6 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
255
262
  function soundcloud_layout() {
256
263
  cqt.style.zIndex = 1000;
257
264
  af_links.style.zIndex = 1001;
258
- svideos[0][media_symbol].connect(cqt.audio_input);
259
265
  document.body.style.setProperty("--ytms-cqt-bottom", "var(--play-controls-height, 0px)");
260
266
  }
261
267
 
@@ -957,8 +963,8 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
957
963
  setTimeout(function(){ child.value = "Reset Default Settings"; }, 300);
958
964
  });
959
965
 
960
- menu_div.attachShadow({mode: "open"});
961
- menu_div.shadowRoot.appendChild(menu_table);
966
+ (document.location.hostname == "open.spotify.com" ? menu_div.attachShadow({mode: "open"}) : menu_div)
967
+ .appendChild(menu_table);
962
968
  menu.onclick = function() {
963
969
  menu_is_hidden = !menu_is_hidden;
964
970
  if (menu_is_hidden)