WIP
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user