Skip to content

Commit 943cd59

Browse files
committed
feat: add keyboard shortcuts to browser extension for ruler and mask
1 parent 9ae6187 commit 943cd59

File tree

1 file changed

+34
-1
lines changed
  • apps/browser-extension-template/src/app/contentScript

1 file changed

+34
-1
lines changed

apps/browser-extension-template/src/app/contentScript/index.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import browser from 'webextension-polyfill'
1+
import browser, { browserAction, runtime } from 'webextension-polyfill'
22
import { ReadingToolsMask } from '@/features/readingToolsMask'
33
import { ReadingToolsRuler } from '@/features/readingToolsRuler'
44

@@ -299,6 +299,39 @@ document.addEventListener('keydown', (event) => {
299299
ReadingToolsMask.remove()
300300
}
301301
})
302+
// keyboard shortcuts for reading tools
303+
const map = { r: false, n: false, Control: false, Meta: false, Alt: false }
304+
document.addEventListener('keydown', (event) => {
305+
if (event.key in map) {
306+
;(map as { [key: string]: boolean })[event.key] = true
307+
if ((map['Control'] || map['Meta']) && map['Alt']) {
308+
if (map['r']) {
309+
if (ReadingToolsRuler.state.enabled) {
310+
ReadingToolsRuler.remove()
311+
} else {
312+
if (ReadingToolsMask.state.enabled) {
313+
ReadingToolsMask.remove()
314+
}
315+
ReadingToolsRuler.add()
316+
}
317+
} else if (map['n']) {
318+
if (ReadingToolsMask.state.enabled) {
319+
ReadingToolsMask.remove()
320+
} else {
321+
if (ReadingToolsRuler.state.enabled) {
322+
ReadingToolsRuler.remove()
323+
}
324+
ReadingToolsMask.add()
325+
}
326+
}
327+
}
328+
}
329+
})
330+
document.addEventListener('keyup', (event) => {
331+
if (event.key in map) {
332+
;(map as { [key: string]: boolean })[event.key] = false
333+
}
334+
})
302335
// end reading tools
303336

304337
// get extension state

0 commit comments

Comments
 (0)