NowSniper

Now Playing Data

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         NowSniper
// @namespace    NowSniper
// @version      1.0.1
// @description  Now Playing Data
// @author       Kıraç Armağan Önal
// @match        *://open.spotify.com/*
// @match        *://soundcloud.com/*
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict';

    var ws = new WebSocket("ws://127.0.0.1:9081");
    unsafeWindow.ws = ws;
    function wsSend(data){
        ws.send(JSON.stringify({data,hostname:window.location.hostname,date:Date.now()}));
    }
    function StartFunction(){

        setInterval(()=>{
            let hostname = window.location.hostname;
            if (hostname == "soundcloud.com") {
              let isPlaying = document.querySelector(".playControl").classList.contains("playing");
              let artwork = document.querySelector(".playbackSoundBadge span.sc-artwork").style.backgroundImage.slice(5,-2).replace("t50x50","t500x500");
              let title = document.querySelector(".playbackSoundBadge__titleLink").title;
              let artist = document.querySelector(".playbackSoundBadge__lightLink").title;
              let timePassed = document.querySelector(".playbackTimeline__timePassed span:nth-child(2)").textContent;
              let totalDuration = document.querySelector(".playbackTimeline__duration span:nth-child(2)").textContent;
              let albumLink = document.querySelector(".playbackSoundBadge__titleLink").href;
              wsSend({artwork,title,artist,isPlaying,timePassed,totalDuration,albumLink});

            } else if (hostname == "open.spotify.com") {
              let isPlaying = !!document.querySelector('.player-controls [data-testid="control-button-pause"]');
              let title = document.querySelector('[data-testid="nowplaying-track-link"]').textContent;
              let artist = [...new Set(Array.from(document.querySelectorAll('span[draggable] a[href*="artist"]')).map(i=>i.textContent))].join(", ");
              let artwork = document.querySelector('[data-testid="CoverSlotExpanded__container"] .cover-art-image').style.backgroundImage.slice(5,-2);
              let timePassed = document.querySelectorAll(".playback-bar .playback-bar__progress-time")[0].textContent;
              let totalDuration = document.querySelectorAll(".playback-bar .playback-bar__progress-time")[1].textContent;
              let albumLink = document.querySelector('[data-testid="nowplaying-track-link"]').href;
              wsSend({artwork,title,artist,isPlaying,timePassed,totalDuration,albumLink});
            }

        },1000);

    }

    if (ws.readyState == WebSocket.OPEN) {
       StartFunction();
    } else {
       ws.onopen = ()=>{StartFunction();}
    }

})();