Veeno / Stop Automatic Recommendations on Soundcloud

// ==UserScript==
// @name        Stop Automatic Recommendations on Soundcloud
// @namespace   soundcloud-no-autoplay
// @author      Veeno
// @contributor Kai Kuehner
// @contributor Technowise
// @contributor Andreas J. Schwarz
// @description Stops the automatic playing of recommended tracks on Soundcloud.
// @include     http://www.soundcloud.com/*
// @include     https://www.soundcloud.com/*
// @include     http://soundcloud.com/*
// @include     https://soundcloud.com/*
// @grant       none
// @version     2.0
// ==/UserScript==

(function(){
    var playingRecommended = false,
        trackInfoContainer = "div.playbackSoundBadge",
        toTitlePath = ["children", 1, "children", 0, "title"],
        title = null,
        buttonElement = "button.playControl",
        recommendedString = "Playing from related tracks for ";

    function stepToTitle(step){ return title = title[step]; }

    function isRecommendedTrack(){
        title = trackInfoContainer;
        return (title && toTitlePath.every(stepToTitle) && typeof title === "string") ?
            title.startsWith(recommendedString) : null;
    }

    var trackInfoObserver = new MutationObserver(function(){
        var currentIsRecommended = isRecommendedTrack();
        if(typeof currentIsRecommended === "boolean"){
            if(!playingRecommended && currentIsRecommended) buttonElement.click();
            playingRecommended = currentIsRecommended;
        }
    });

    function start(){
        var _trackInfoContainer = document.querySelector(trackInfoContainer),
            _buttonElement = document.querySelector(buttonElement);
        
        if(!_trackInfoContainer || !_buttonElement){
            setTimeout(start, 20);
            return;
        }
        
        trackInfoContainer = _trackInfoContainer;
        buttonElement = _buttonElement;
        trackInfoObserver.observe(trackInfoContainer, {childList: true, subtree: true});
    }

    start();
})();