Swyter Tweaks for Spotify

Mutes the audio ads on play.spotify.com, while they are still being played, so *everyone* is happy.

  1. // ==UserScript==
  2. // @name Swyter Tweaks for Spotify
  3. // @description Mutes the audio ads on play.spotify.com, while they are still being played, so *everyone* is happy.
  4. // @homepage https://swyterzone.appspot.com
  5. // @namespace https://gf.qytechs.cn/users/4813
  6. // @match https://play.spotify.com/*
  7. // @grant none
  8. // @run-at document-end
  9. // @version 2015.07.01
  10. // @author Swyter
  11. // @icon https://i.imgur.com/LHkCkka.png
  12. // ==/UserScript==
  13.  
  14. if (window.parent !== window)
  15. throw 'stop execution';
  16.  
  17. function when_external_loaded()
  18. {
  19.  
  20. // Bruteforce our way to get the instance reference, nice spaguetti code, JS at its finest!
  21. // F*ck you Firefox, I'm elegant!— Said the angry programmer with the hair-raising voice of a stud.
  22. var _core = Spotify.Instances.get(
  23. (document.querySelector("object[id*='SPFBIn_']")||{id:"firefoxsux69"}).id.match(/.+\d+/)
  24. );
  25.  
  26. if (typeof _core === 'undefined')
  27. {
  28. // Wait in cycles of 100 ms until the client finally loads
  29. setTimeout(arguments.callee, 100);
  30. }
  31. else
  32. {
  33. // Here's the real meat...
  34. console.log("Binding Swyter Tweaks for Spotify on the player's code.");
  35.  
  36. _core.audioManager.bind('PLAYING', function(e)
  37. {
  38. var isAd = document.getElementById("app-player").contentDocument.getElementById("next").classList.contains('disabled');
  39.  
  40. if (isAd)
  41. {
  42. console.log("We're loading an ad, skipping “"+ document.title.match(/^▶?\s?(.+) -/)[1] +"”");
  43.  
  44. var timestamp = document.getElementById('app-player').contentDocument.getElementById('track-length').innerHTML.split(':');
  45. timestamp = timestamp[0]*60 + timestamp[1]*1;
  46. timestamp*= 1000;
  47.  
  48. _core.audioManager.getActivePlayer().seek(
  49. _core.audioManager.getActivePlayer().getDuration() || timestamp
  50. );
  51. }
  52. });
  53.  
  54. }
  55. }
  56.  
  57. // Ugly as hell so it stays crossplatform, damn you Spotify engineers for a nicely done work! :-)
  58. document.head.appendChild(
  59. inject_fn = document.createElement('script')
  60. );
  61.  
  62. inject_fn.innerHTML = '(' + when_external_loaded.toString() + ')()';

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址