diff --git a/scrobbler-vivaldi-plex/background.js b/scrobbler-vivaldi-plex/background.js index 9821db1..7ba5bf1 100644 --- a/scrobbler-vivaldi-plex/background.js +++ b/scrobbler-vivaldi-plex/background.js @@ -210,10 +210,17 @@ function scrobble(artist,title,seconds) { console.log("Scrobbling " + artist + " - " + title + "; " + seconds + " seconds playtime") artiststring = encodeURIComponent(artist) titlestring = encodeURIComponent(title) - APIKEY = "YDzcmp8JpYHCcvJbDOVT7nEDoyCEND6K" ///obviously this will not be hardcoded later - var xhttp = new XMLHttpRequest(); - xhttp.open("POST","http://localhost:42010/db/newscrobble",true); - xhttp.send("artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds + "&key=" + APIKEY) + chrome.storage.local.get("apikey",function(result) { + APIKEY = result["apikey"] + chrome.storage.local.get("serverurl",function(result) { + URL = result["serverurl"] + var xhttp = new XMLHttpRequest(); + xhttp.open("POST",URL + "/db/newscrobble",true); + xhttp.send("artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds + "&key=" + APIKEY) + }); + }); + + } function setUpdate() { diff --git a/scrobbler-vivaldi-plex/manifest.json b/scrobbler-vivaldi-plex/manifest.json index f44c358..c979cbd 100644 --- a/scrobbler-vivaldi-plex/manifest.json +++ b/scrobbler-vivaldi-plex/manifest.json @@ -3,7 +3,7 @@ "version": "0.1", "description": "Scrobbles tracks from Plex Web to your Maloja server", "manifest_version": 2, - "permissions": ["activeTab", "declarativeContent","tabs","http://app.plex.tv/*","https://app.plex.tv/*"], + "permissions": ["activeTab", "declarativeContent","tabs","storage","http://app.plex.tv/*","https://app.plex.tv/*"], "background": { "scripts": @@ -19,7 +19,9 @@ { "128":"icon128.png", "48":"icon48.png" - } + }, + "default_popup": "settings.html", + "default_title": "Settings" }, "icons": { diff --git a/scrobbler-vivaldi-plex/settings.html b/scrobbler-vivaldi-plex/settings.html new file mode 100644 index 0000000..16c6807 --- /dev/null +++ b/scrobbler-vivaldi-plex/settings.html @@ -0,0 +1,16 @@ + + + + + Wat + + + +
+

Server:

+ +

API key:

+ +
+ + diff --git a/scrobbler-vivaldi-plex/settings.js b/scrobbler-vivaldi-plex/settings.js new file mode 100644 index 0000000..ab5c403 --- /dev/null +++ b/scrobbler-vivaldi-plex/settings.js @@ -0,0 +1,34 @@ + +document.addEventListener("DOMContentLoaded",function() { + document.getElementById("serverurl").addEventListener("input",updateServer); + document.getElementById("apikey").addEventListener("input",updateAPIKey); + + + chrome.storage.local.get({"serverurl":"http://localhost:42010"},function(result) { + document.getElementById("serverurl").value = result["serverurl"] + }); + chrome.storage.local.get({"apikey":"BlackPinkInYourArea"},function(result) { + document.getElementById("apikey").value = result["apikey"] + }); + +}); + + + +function updateServer() { + + text = document.getElementById("serverurl").value + + if (!text.startsWith("http://") & !text.startsWith("https://")) { + document.getElementById("serverurl").style.backgroundColor = "pink"; + } + else { + document.getElementById("serverurl").style.backgroundColor = "white"; + chrome.storage.local.set({"serverurl":text}) + } +} + +function updateAPIKey() { + text = document.getElementById("apikey").value + chrome.storage.local.set({"apikey":text}) +}