Greasy Fork

Greasy Fork is available in English.

Stop Automatic Recommendations on Soundcloud

Stops the automatic playing of recommended tracks on Soundcloud.

目前为 2015-10-17 提交的版本。查看 最新版本

// ==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     1.7
// ==/UserScript==
//-------------------------------------------------------------------------------------------
var sc_cp = {
	"title": null,
	"checkInterval": null,
	
	"titleElement": "a.playbackSoundBadge__context",
	"attribute": "title",
	"recommendedString": "Playing from related tracks for ",
	"buttonElement": "button.playControl",
	
	"isRecommendedTrack": function() {
		sc_cp.title = document.querySelector(sc_cp.titleElement).getAttribute(sc_cp.attribute);
		return sc_cp.title != null && sc_cp.title.startsWith(sc_cp.recommendedString);
	},
	
	"checkA": function () {
		if(!sc_cp.isRecommendedTrack()) {
			clearInterval(sc_cp.checkInterval);
			sc_cp.checkInterval = setInterval(sc_cp.checkB, 100);
		}
	},
	
	"checkB": function () {
		if(sc_cp.isRecommendedTrack()) {
			document.querySelector(sc_cp.buttonElement).click();
			clearInterval(sc_cp.checkInterval);
			sc_cp.checkInterval = setInterval(sc_cp.checkA, 500);
		}
	}
};


if (!String.prototype.startsWith) {
	String.prototype.startsWith = function(searchString, position) {
		position = position || 0;
		return this.substring(position, position + searchString.length) == searchString;
	};
}


window.onload = function() {
	sc_cp.checkInterval = setInterval(sc_cp.checkA, 500);
};