-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.js
68 lines (62 loc) · 1.88 KB
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// ==UserScript==
// @name Spotify Live Status
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author lonelil
// @match https://open.spotify.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=spotify.com
// @grant none
// ==/UserScript==
(function () {
"use strict";
let data = {};
let ws;
function connect() {
ws = new WebSocket("ws://localhost:8080");
ws.onopen = function () {
console.log("started");
setInterval(function () {
let currentLine = document.getElementsByClassName(
"arY01KDGhWNgzlAHlhpd"
)[0].innerText;
let currentSong = document.querySelector(
`[data-testid="context-item-link"]`
);
let currentSongArtist = document.querySelector(
`[data-testid="context-item-info-artist"]`
);
let currentSongArt = document.querySelector(
`[data-testid="cover-art-image"]`
).src;
let currentSongLength = document.querySelector(
`[data-testid="playback-duration"]`
).innerText;
let newData = {
line: currentLine,
song: currentSong.innerText,
songId: currentSong.href.split("album/")[1],
artistName: currentSongArtist.innerHTML,
artistId: currentSongArtist.href.split("artist/")[1],
art: currentSongArt,
length: currentSongLength,
};
if (JSON.stringify(data) !== JSON.stringify(newData)) {
data = newData;
console.log(data);
ws.send(JSON.stringify(data));
}
}, 500);
};
ws.onclose = function (e) {
console.log(
"Socket is closed. Reconnect will be attempted in 1 second.",
e.reason
);
setTimeout(function () {
connect();
}, 1000);
};
}
connect();
})();