2022-11-24 01:40:44 +03:00
|
|
|
// duplicate this info for now, don't know if there is a better way than sending messages
|
|
|
|
var pages = {
|
|
|
|
"plex":"Plex",
|
|
|
|
"ytmusic":"YouTube Music",
|
|
|
|
"spotify":"Spotify",
|
|
|
|
"bandcamp":"Bandcamp",
|
|
|
|
"soundcloud":"Soundcloud",
|
|
|
|
"navidrome":"Navidrome"
|
|
|
|
}
|
|
|
|
|
2020-09-04 05:45:38 +03:00
|
|
|
var config_defaults = {
|
|
|
|
serverurl:"http://localhost:42010",
|
|
|
|
apikey:"BlackPinkInYourArea"
|
|
|
|
}
|
|
|
|
|
2022-11-24 01:40:44 +03:00
|
|
|
for (var key in pages) {
|
|
|
|
config_defaults["service_active_" + key] = true;
|
|
|
|
}
|
|
|
|
|
2019-04-07 14:13:12 +03:00
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded",function() {
|
2019-04-07 15:07:50 +03:00
|
|
|
|
2022-11-24 01:40:44 +03:00
|
|
|
var sitelist = document.getElementById("sitelist");
|
|
|
|
|
|
|
|
|
|
|
|
for (var identifier in pages) {
|
|
|
|
sitelist.append(document.createElement('br'));
|
|
|
|
var checkbox = document.createElement('input');
|
|
|
|
checkbox.type = "checkbox";
|
|
|
|
checkbox.id = "service_active_" + identifier;
|
|
|
|
var label = document.createElement('label');
|
|
|
|
label.for = checkbox.id;
|
|
|
|
label.textContent = pages[identifier];
|
|
|
|
sitelist.appendChild(checkbox);
|
|
|
|
sitelist.appendChild(label);
|
|
|
|
|
|
|
|
checkbox.addEventListener("change",toggleSite);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-07 14:13:12 +03:00
|
|
|
document.getElementById("serverurl").addEventListener("change",checkServer);
|
|
|
|
document.getElementById("apikey").addEventListener("change",checkServer);
|
2019-04-07 15:07:50 +03:00
|
|
|
|
|
|
|
document.getElementById("serverurl").addEventListener("focusout",checkServer);
|
|
|
|
document.getElementById("apikey").addEventListener("focusout",checkServer);
|
|
|
|
|
2020-10-08 18:08:52 +03:00
|
|
|
document.getElementById("serverurl").addEventListener("input",saveConfig);
|
|
|
|
document.getElementById("apikey").addEventListener("input",saveConfig);
|
|
|
|
|
2019-04-07 15:07:50 +03:00
|
|
|
|
2019-04-07 18:14:50 +03:00
|
|
|
chrome.runtime.onMessage.addListener(onInternalMessage);
|
|
|
|
|
2020-09-04 05:45:38 +03:00
|
|
|
chrome.storage.local.get(config_defaults,function(result){
|
|
|
|
for (var key in result) {
|
2022-11-24 01:40:44 +03:00
|
|
|
if (result[key] == true || result[key] == false) {
|
|
|
|
document.getElementById(key).checked = result[key];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
document.getElementById(key).value = result[key];
|
|
|
|
}
|
|
|
|
|
2020-09-04 05:45:38 +03:00
|
|
|
}
|
|
|
|
checkServer();
|
|
|
|
})
|
2019-04-07 15:07:50 +03:00
|
|
|
|
2019-04-07 18:14:50 +03:00
|
|
|
chrome.runtime.sendMessage({"type":"query"})
|
|
|
|
|
2019-04-07 15:07:50 +03:00
|
|
|
|
|
|
|
|
2019-04-07 14:13:12 +03:00
|
|
|
});
|
|
|
|
|
2022-11-24 01:40:44 +03:00
|
|
|
function toggleSite(evt) {
|
|
|
|
var element = evt.target;
|
|
|
|
chrome.storage.local.set({ [element.id]: element.checked });
|
|
|
|
}
|
|
|
|
|
2019-04-07 14:13:12 +03:00
|
|
|
|
2019-04-07 18:14:50 +03:00
|
|
|
function onInternalMessage(request,sender) {
|
|
|
|
if (request.type == "response") {
|
|
|
|
players = request.content
|
|
|
|
html = "";
|
|
|
|
for (var i=0;i<players.length;i++) {
|
|
|
|
if (players[i][1]) {
|
|
|
|
html += "<li>" + players[i][0] + ": " + players[i][1] + " - " + players[i][2]
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
html += "<li>" + players[i][0] + ": Playing nothing"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.getElementById("playinglist").innerHTML = html;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-07 14:13:12 +03:00
|
|
|
|
2020-09-04 05:45:38 +03:00
|
|
|
function saveConfig() {
|
|
|
|
for (var key in config_defaults) {
|
|
|
|
var value = document.getElementById(key).value;
|
|
|
|
chrome.storage.local.set({ [key]: value });
|
|
|
|
}
|
2019-04-07 14:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkServer() {
|
2019-05-12 11:20:47 +03:00
|
|
|
url = document.getElementById("serverurl").value + "/api/test?key=" + document.getElementById("apikey").value
|
2019-04-07 15:07:50 +03:00
|
|
|
|
2019-04-07 14:13:12 +03:00
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = createCheckmarks;
|
|
|
|
try {
|
|
|
|
xhttp.open("GET",url,true);
|
|
|
|
xhttp.send();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
//document.getElementById("checkmark_url").innerHTML = "❌"
|
|
|
|
//document.getElementById("checkmark_key").innerHTML = "❌"
|
|
|
|
document.getElementById("serverurl").style.backgroundColor = "red"
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "red"
|
|
|
|
}
|
2019-04-07 15:07:50 +03:00
|
|
|
|
2019-04-07 14:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function createCheckmarks() {
|
|
|
|
if (this.readyState == 4) {
|
2020-09-01 16:22:57 +03:00
|
|
|
if ((this.status >= 200) && (this.status < 300)) {
|
2019-04-07 14:13:12 +03:00
|
|
|
//document.getElementById("checkmark_url").innerHTML = "✔️"
|
|
|
|
//document.getElementById("checkmark_key").innerHTML = "✔️"
|
|
|
|
document.getElementById("serverurl").style.backgroundColor = "lawngreen"
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "lawngreen"
|
|
|
|
}
|
|
|
|
else if (this.status == 403) {
|
|
|
|
//document.getElementById("checkmark_url").innerHTML = "✔️"
|
|
|
|
//document.getElementById("checkmark_key").innerHTML = "❌"
|
|
|
|
document.getElementById("serverurl").style.backgroundColor = "lawngreen"
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "red"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//document.getElementById("checkmark_url").innerHTML = "❌"
|
|
|
|
//document.getElementById("checkmark_key").innerHTML = "❌"
|
|
|
|
document.getElementById("serverurl").style.backgroundColor = "red"
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "red"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|