-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspq_background.js
More file actions
26 lines (22 loc) · 834 Bytes
/
spq_background.js
File metadata and controls
26 lines (22 loc) · 834 Bytes
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
function bytesToJson(bytes) {
const intArr = new Uint8Array(bytes);
var unparsedString = "";
for (const i of intArr) {
unparsedString += String.fromCharCode(i);
}
const parsedJson = JSON.parse(unparsedString);
return parsedJson;
}
// Used to obtain device and connection IDs
chrome.webRequest.onBeforeRequest.addListener(function(details) {
if (details.url.endsWith("spclient.spotify.com/track-playback/v1/devices")) {
const data = bytesToJson(details.requestBody.raw[0].bytes);
const deviceId = data.device.device_id;
const connectionId = data.connection_id;
chrome.tabs.query({url: "https://open.spotify.com/*"}, function(tabs) {
for (const tab of tabs) {
chrome.tabs.sendMessage(tab.id, {deviceId: deviceId, connectionId: connectionId});
}
});
}
}, { urls: ["<all_urls>"] }, ["requestBody"]);