[Fixed] SoundCloud DL

Download SoundCloud tracks as mp3!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         [Fixed] SoundCloud DL
// @namespace    SCDL
// @version      1.7.5
// @description  Download SoundCloud tracks as mp3!
// @author       Kıraç Armağan Önal
// @match        https://soundcloud.com/*
// @match        https://soundcloud.com/*/*
// @match        https://soundcloud.com/*/*/*
// @match        https://soundcloud.com/*/*/*/*
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    "use strict";

    var OPTIONS = {
        /* true or false */
        autodownload: false,
        autoplay: false
    }

    /* don't change */
    var isLoaded = false;


    function createElementByHTML(html) {
    var divElm = document.createElement("div");
    divElm.innerHTML = html;
    return divElm.firstElementChild;
    };

    function loadSCDL(event) {
        if (isLoaded) return;
        isLoaded = true;
     setInterval(function(){
     if (!document.querySelector("#scdl-download-btn")) {
         var button_list = document.querySelector(".sc-button-group.sc-button-group-medium");
         if (button_list) button_list.appendChild(createElementByHTML(`<a id="scdl-download-btn" title="Download with SCDL!" href="javascript:openSCDL()"> <button class=" sc-button" alt="Download with SCDL">⬇ Download ⬇</button></a>`));
         unsafeWindow.openSCDL = function (){
           var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
             var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;

             var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
             var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

             var left = ((width / 2) - (1000 / 2)) + dualScreenLeft;
             var top = ((height / 2) - (1000 / 2)) + dualScreenTop;
             var newWindow = window.open(`https://soundcloud-dl.glitch.me/?autoplay=${OPTIONS.autoplay}&autodownload=${OPTIONS.autodownload}&url=${window.location.href}`, "SCDLWindow", 'width=1000, height=1000, top=' + top + ', left=' + left);

             if (window.focus) {
                 newWindow.focus();
             }
         }
     }
     },5000)
     }
    unsafeWindow.loadSCDL = loadSCDL;
    if (document.readyState == "loading") {
      document.addEventListener("DOMContentLoaded", (e)=>{loadSCDL(e)})
      document.addEventListener("DomContentLoaded", (e)=>{loadSCDL(e)})
    } else {
      loadSCDL();
    }

})();