NowSniper

Now Playing Data

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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();}
    }

})();