// ==UserScript== // @name soundcloud disable autoplay station // @version 1.2 // @description Opens the Soundcloud Next Up menu on load and turns off the Autoplay Station, then continually disables it // @author bhackel // @match https://soundcloud.com/* // @grant none // @run-at document-start // @noframes // @namespace https://greasyfork.org/en/users/324178-bhackel // @downloadURL none // ==/UserScript== (function() { 'use strict'; /* First, the script needs to open the Next Up Queue. This is to load the Autoplay Station button in the page. Once it is loaded, the script can then disable it. If the Next Up menu is never loaded, then the Autoplay Station cannot be disabled. */ function openQueue() { // opens the Next Up Queue to load the Autoplay button var queueTrigger = document.getElementsByClassName("playbackSoundBadge__queueCircle").item(0); if (queueTrigger) { // check if next up button is loaded, then open it and call to close it queueTrigger.click(); closeQueue(queueTrigger); } else { // perform another check after delay setTimeout(openQueue, 500); } } function closeQueue(queueTrigger) { // closes the Next Up queue once the Autoplay button has loaded var buttonDiv = document.getElementsByClassName("queueFallback__toggle").item(0); if (buttonDiv) { // check if the button has loaded, then close the queue and call the loop queueTrigger.click(); // Add focus back to the play/pause button document.getElementsByClassName("playButton").item(0).focus(); // call the loop since the button has loaded disableButtonLoop(); } else { // perform another check after delay setTimeout(function() { closeQueue(queueTrigger); }, 500); } } /* In order to keep the Autoplay Station off, it needs to be continually disabled. In SoundCloud, if a user clicks on a song outside of the currently playing playlist, it re-enables autoplay. This function chekcs whether the autoplay station is enabled, and if it is, then it disables it. Then, it calls itself again after two seconds. */ function disableButtonLoop() { // repeatedly tries to turn off the Autoplay button var buttonDiv = document.getElementsByClassName("queueFallback__toggle").item(0); if (buttonDiv) { // make sure it exists to not error var button = buttonDiv.children.item(0); if (button.className === "toggle sc-toggle sc-toggle-active") { // it has this classname when Autoplay is enabled button.click(); // Add focus back to the play/pause button document.getElementsByClassName("playControl").item(0).focus(); } } setTimeout(disableButtonLoop, 2000); } // Start the script openQueue(); })();