SoundCloud - Auto redirect to current playing

Automaticly redirects to current playing song.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         SoundCloud - Auto redirect to current playing
// @namespace    armagan.rest
// @version      1.1
// @description  Automaticly redirects to current playing song.
// @author       Kıraç Armağan Önal
// @match        https://soundcloud.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getGetBadgesElement() {return document.querySelector(".playbackSoundBadge__actions")};
    function getAutoRedirectCheckbox() {return document.querySelector(".auto-redirect-button")};
    function isPlaying() {return Boolean(document.querySelector(".playControls__play.playing"))};
    function getNowplayingElement() {return document.querySelector(".playbackSoundBadge__titleLink")};
    function getNowplayingLink() {return (getNowplayingElement() || {}).href || ""};
    let isAutoRedirectActive = false;
    let lastNowPlayingLink = getNowplayingLink();

    setInterval(()=>{
        // Eğer sayfa ayarlar sayfası falansa umursamasın diye.
        if (!getGetBadgesElement()) return;

        if (!getAutoRedirectCheckbox()) {
            let checkBoxElement = document.createElement("input");
            checkBoxElement.type = "checkbox";
            checkBoxElement.checked = isAutoRedirectActive;
            checkBoxElement.title = "Auto redirect to current playing page";
            checkBoxElement.style.marginTop = "5px";
            checkBoxElement.style.marginLeft = "6px";
            checkBoxElement.classList.add("auto-redirect-button");
            checkBoxElement.addEventListener("change",()=>{
                isAutoRedirectActive = checkBoxElement.checked;
            });
            getGetBadgesElement().appendChild(checkBoxElement);
        }

        if (isPlaying() && isAutoRedirectActive && lastNowPlayingLink != getNowplayingLink()) {
            getNowplayingElement().click();
            lastNowPlayingLink = getNowplayingLink();
        }
    },1000)
})();