mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Forward key presses from popup
This commit is contained in:
parent
d9970bf110
commit
32a3cb2cfe
4 changed files with 63 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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({});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
30
src/popup.ts
30
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) {
|
||||
|
|
Loading…
Reference in a new issue