Swyter Tweaks for Spotify

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name          Swyter Tweaks for Spotify
// @description   Mutes the audio ads on play.spotify.com, while they are still being played, so *everyone* is happy.
// @homepage      https://swyterzone.appspot.com
// @namespace     https://greatest.deepsurf.us/users/4813
// @match         https://play.spotify.com/*
// @grant         none
// @run-at        document-end
// @version       2015.07.01
// @author        Swyter
// @icon          https://i.imgur.com/LHkCkka.png
// ==/UserScript==

if (window.parent !== window)
  throw 'stop execution';

function when_external_loaded()
{

  // Bruteforce our way to get the instance reference, nice spaguetti code, JS at its finest!
  // F*ck you Firefox, I'm elegant!— Said the angry programmer with the hair-raising voice of a stud.
  var _core = Spotify.Instances.get(
    (document.querySelector("object[id*='SPFBIn_']")||{id:"firefoxsux69"}).id.match(/.+\d+/)
  );

  if (typeof _core === 'undefined')
  {
    // Wait in cycles of 100 ms until the client finally loads
    setTimeout(arguments.callee, 100);
  }
  
  else
  {
    // Here's the real meat...
    console.log("Binding Swyter Tweaks for Spotify on the player's code.");

    _core.audioManager.bind('PLAYING', function(e)
    {
        var isAd = document.getElementById("app-player").contentDocument.getElementById("next").classList.contains('disabled');

        if (isAd)
        {
            console.log("We're loading an ad, skipping “"+ document.title.match(/^▶?\s?(.+) -/)[1] +"”");

            var timestamp = document.getElementById('app-player').contentDocument.getElementById('track-length').innerHTML.split(':');
                timestamp = timestamp[0]*60 + timestamp[1]*1;
                timestamp*= 1000;

            _core.audioManager.getActivePlayer().seek(
                _core.audioManager.getActivePlayer().getDuration() || timestamp
            );
        }
    });

  }
}

// Ugly as hell so it stays crossplatform, damn you Spotify engineers for a nicely done work! :-)
document.head.appendChild(
  inject_fn = document.createElement('script')
);

inject_fn.innerHTML = '(' + when_external_loaded.toString() + ')()';