Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tumble1999 committed Sep 6, 2023
1 parent 91ed430 commit 23ed138
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions sky-remote.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name STBG Sky Remote API
// @namespace https://stb-gaming.github.io
// @version 1.3.8
// @version 1.3.9
// @description The ultimate Sky Remote API (hopefully) containing everything to simulate a sky remote in your browser
// @author Tumble
// @run-at document-start
Expand Down Expand Up @@ -132,7 +132,7 @@
});
};

SkyRemote.triggerEvent = function (event, key, element = document, origin) {
SkyRemote.triggerEvent = function (event, key, element = document, destination) {
if (!event) {
console.error("[SKY REMOTE] No event was provided");
return;
Expand All @@ -147,8 +147,9 @@
cancelable: true,
composed: true
}];
if (origin) {
if (typeof origin !== "string") origin = "https://denki.co.uk";
if (destination) {
if (typeof destination !== "string") origin = "https://denki.co.uk";
if (!(element instanceof Window)) element = window.frames[0];
element.postMessage(eventParams, origin);
}
else
Expand Down Expand Up @@ -177,15 +178,15 @@ Version: ${SkyRemote.version.join(".")} (${IS_THIS_USERSCRIPT_DEV ? "Development
};


SkyRemote.prototype.holdButton = function (btn, element = document, message) {
SkyRemote.prototype.holdButton = function (btn, element = document, destination) {
if (!btn) {
console.error("[SKY REMOTE] No button was provided");
return;
}
if (this.listButtons().includes(btn)) {
let keyCode = this.remote[btn];
this.heldButtons[keyCode] = true;
SkyRemote.triggerEvent("keydown", keyCode, element, message);
SkyRemote.triggerEvent("keydown", keyCode, element, destination);
}
};

Expand All @@ -206,14 +207,14 @@ Version: ${SkyRemote.version.join(".")} (${IS_THIS_USERSCRIPT_DEV ? "Development
});
};

SkyRemote.prototype.releaseButton = function (btn, element = document, message) {
SkyRemote.prototype.releaseButton = function (btn, element = document, destination) {
if (!btn) {
console.error("[SKY REMOTE] No button was provided");
return;
}
let keyCode = this.remote[btn];
if (this.heldButtons[keyCode]) {
SkyRemote.triggerEvent("keyup", keyCode, element, message);
SkyRemote.triggerEvent("keyup", keyCode, element, destination);
this.heldButtons[keyCode] = false;
}
};
Expand All @@ -236,13 +237,13 @@ Version: ${SkyRemote.version.join(".")} (${IS_THIS_USERSCRIPT_DEV ? "Development
});
};

SkyRemote.prototype.pressButton = function (btn, element = document, message) {
SkyRemote.prototype.pressButton = function (btn, element = document, destination) {
if (!btn) {
console.error("[SKY REMOTE] No button was provided");
return;
}
this.holdButton(btn, element, message);
setTimeout(() => this.releaseButton(btn, element), 500, message);
setTimeout(() => this.releaseButton(btn, element, destination), 500);
};

SkyRemote.prototype.onPressButton = function (btn, func, element = document) {
Expand Down

0 comments on commit 23ed138

Please sign in to comment.