aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay <[email protected]>2022-06-06 17:09:34 -0400
committerAjay <[email protected]>2022-06-06 17:09:34 -0400
commit32a3cb2cfeefa9e4f9d06e56e1e3cc3e5669b892 (patch)
tree6b05541c9dca88ba6937bbbc3889fe23df02fe15
parentd9970bf1104ba5d5e7eb564baee87d688ea91f2e (diff)
downloadSponsorBlock-32a3cb2cfeefa9e4f9d06e56e1e3cc3e5669b892.tar.gz
SponsorBlock-32a3cb2cfeefa9e4f9d06e56e1e3cc3e5669b892.zip
Forward key presses from popup
-rw-r--r--src/background.ts10
-rw-r--r--src/content.ts15
-rw-r--r--src/messageTypes.ts14
-rw-r--r--src/popup.ts30
4 files changed, 63 insertions, 6 deletions
diff --git a/src/background.ts b/src/background.ts
index aa94df5e..1af6038d 100644
--- a/src/background.ts
+++ b/src/background.ts
@@ -84,7 +84,7 @@ chrome.runtime.onMessage.addListener(function (request, _, callback) {
case "unregisterContentScript":
unregisterFirefoxContentScript(request.id)
return false;
- case "tabs":
+ case "tabs": {
chrome.tabs.query({
active: true,
currentWindow: true
@@ -92,11 +92,13 @@ chrome.runtime.onMessage.addListener(function (request, _, callback) {
chrome.tabs.sendMessage(
tabs[0].id,
request.data,
- (response) => callback(response)
+ (response) => {
+ callback(response);
+ }
);
- }
- );
+ });
return true;
+ }
}
});
diff --git a/src/content.ts b/src/content.ts
index 46dbd913..92f80f60 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -223,8 +223,21 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
case "copyToClipboard":
navigator.clipboard.writeText(request.text);
break;
-
+ case "keydown":
+ document.dispatchEvent(new KeyboardEvent('keydown', {
+ key: request.key,
+ keyCode: request.keyCode,
+ code: request.code,
+ which: request.which,
+ shiftKey: request.shiftKey,
+ ctrlKey: request.ctrlKey,
+ altKey: request.altKey,
+ metaKey: request.metaKey
+ }));
+ break;
}
+
+ sendResponse({});
}
/**
diff --git a/src/messageTypes.ts b/src/messageTypes.ts
index 470c95a6..65e5c612 100644
--- a/src/messageTypes.ts
+++ b/src/messageTypes.ts
@@ -47,7 +47,19 @@ interface CopyToClipboardMessage {
text: string;
}
-export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | IsInfoFoundMessage | SubmitVoteMessage | HideSegmentMessage | CopyToClipboardMessage);
+interface KeyDownMessage {
+ message: "keydown";
+ key: string;
+ keyCode: number;
+ code: string;
+ which: number;
+ shiftKey: boolean;
+ ctrlKey: boolean;
+ altKey: boolean;
+ metaKey: boolean;
+}
+
+export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | IsInfoFoundMessage | SubmitVoteMessage | HideSegmentMessage | CopyToClipboardMessage | KeyDownMessage);
export interface IsInfoFoundMessageResponse {
found: boolean;
diff --git a/src/popup.ts b/src/popup.ts
index 927454d6..0dc88176 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -180,6 +180,36 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments);
PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => copyToClipboard(await utils.getHash(Config.config.userID)));
+ // Forward click events
+ if (window !== window.top) {
+ document.addEventListener("keydown", (e) => {
+ const target = e.target as HTMLElement;
+ if (target.tagName === "INPUT"
+ || target.tagName === "TEXTAREA"
+ || e.key === "ArrowUp"
+ || e.key === "ArrowDown") {
+ return;
+ }
+
+ if (e.key === " ") {
+ // No scrolling
+ e.preventDefault();
+ }
+
+ sendTabMessage({
+ message: "keydown",
+ key: e.key,
+ keyCode: e.keyCode,
+ code: e.code,
+ which: e.which,
+ shiftKey: e.shiftKey,
+ ctrlKey: e.ctrlKey,
+ altKey: e.altKey,
+ metaKey: e.metaKey
+ });
+ });
+ }
+
//show proper disable skipping button
const disableSkipping = Config.config.disableSkipping;
if (disableSkipping != undefined && disableSkipping) {