This commit is contained in:
2026-04-08 21:28:36 -04:00
parent b6dca80670
commit d4f788dca9
4 changed files with 75 additions and 34 deletions

View File

@@ -1,9 +1,37 @@
Pebble.addEventListener("ready", function (e) {
Pebble.sendAppMessage({ APP_READY: true });
Pebble.addEventListener("ready", function () {
Pebble.sendAppMessage({ JS_READY: 1 });
});
Pebble.addEventListener("appmessage", function (dict) {
if (dict.payload["API_FULL_URL"]) {
console.log("Time to harass " + dict.payload["API_FULL_URL"] + " to find what you watched at " + dict.payload["SLEEP_TIME"]);
if (dict.payload["API_HOST"]) {
console.log("WOAH BRO");
if (dict.payload["API_IS_PLEX"] == true) {
callAPI(dict.payload["API_HOST"] + "/status/sessions/history/all", true, dict.payload["API_KEY"]);
} else {
callAPI(dict.payload["API_HOST"] + "/System/ActivityLog/Entries", false, dict.payload["API_KEY"]);
}
}
});
function callAPI(fullURL, isPlex, apiKey) {
let data = null;
let xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("GET", fullURL);
xhr.setRequestHeader("accept", "application/json");
if (isPlex == true) {
xhr.setRequestHeader("X-Plex-Token", apiKey);
} else {
xhr.setRequestHeader("Authorization", 'MediaBrowser Token="' + apiKey + '"');
}
xhr.send(data);
}