Greasy Fork 还支持 简体中文。

Swyter Tweaks for Spotify

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

目前為 2014-08-28 提交的版本,檢視 最新版本

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