diff options
Diffstat (limited to 'xP/public')
-rw-r--r-- | xP/public/xP.js | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js index b62d6c2..7fa6bf3 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -127,6 +127,32 @@ class RelayRpc extends EventTarget { } } +// ---- Utilities -------------------------------------------------------------- + +// On macOS, the Alt/Option key transforms characters, which basically breaks +// all event.altKey shortcuts, so require combining them with Control as well +// on that system. +function hasShortcutModifiers(event) { + // This method of detection only works with Blink browsers, as of writing. + return event.altKey && !event.metaKey && + (navigator.userAgentData?.platform === 'macOS') === event.ctrlKey +} + +const audioContext = new AudioContext() + +function beep() { + let gain = audioContext.createGain() + gain.gain.value = 0.5 + gain.connect(audioContext.destination) + + let oscillator = audioContext.createOscillator() + oscillator.type = "triangle" + oscillator.frequency.value = 800 + oscillator.connect(gain) + oscillator.start(audioContext.currentTime) + oscillator.stop(audioContext.currentTime + 0.1) +} + // ---- Event processing ------------------------------------------------------- let rpc = new RelayRpc(proxy) @@ -300,8 +326,11 @@ rpc.addEventListener('BufferLine', event => { // TODO: Find some way of highlighting the tab in a browser. // TODO: Also highlight on unseen private messages, like xC does. - if (!visible && line.isHighlight) - b.highlighted = true + if (line.isHighlight) { + beep() + if (!visible) + b.highlighted = true + } }) rpc.addEventListener('BufferClear', event => { @@ -331,15 +360,6 @@ for (let i = 0; i < 24; i++) { // ---- UI --------------------------------------------------------------------- -// On macOS, the Alt/Option key transforms characters, which basically breaks -// all event.altKey shortcuts, so require combining them with Control as well -// on that system. -function hasShortcutModifiers(event) { - // This method of detection only works with Blink browsers, as of writing. - return event.altKey && !event.metaKey && - (navigator.userAgentData?.platform === 'macOS') === event.ctrlKey -} - let linkRE = [ /https?:\/\//, /([^\[\](){}<>"'\s]|\([^\[\](){}<>"'\s]*\))+/, @@ -616,11 +636,12 @@ let Input = { if (b === undefined) return false - // TODO: Ding otherwise. if (b.historyAt > 0) { if (b.historyAt == b.history.length) b.input = textarea.value textarea.value = b.history[--b.historyAt] + } else { + beep() } return true }, @@ -630,12 +651,13 @@ let Input = { if (b === undefined) return false - // TODO: Ding otherwise. if (b.historyAt < b.history.length) { if (++b.historyAt == b.history.length) textarea.value = b.input else textarea.value = b.history[b.historyAt] + } else { + beep() } return true }, |