From 561fd6a4fece87ba26af03a6d2efecb747590106 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 25 Dec 2023 20:35:20 -0600 Subject: [PATCH 1/6] Reuse AudioContext --- themes/default/assets/js/gamer.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/themes/default/assets/js/gamer.js b/themes/default/assets/js/gamer.js index d4bbb40..750f962 100644 --- a/themes/default/assets/js/gamer.js +++ b/themes/default/assets/js/gamer.js @@ -61,10 +61,11 @@ const createSound = (src) => { let audioContext const playAudioBuffer = async (arrayBuffer) => { const AudioContext = globalThis?.AudioContext - const context = audioContext ?? new AudioContext() - const source = context.createBufferSource() - source.buffer = await context.decodeAudioData(arrayBuffer.slice(0)) - source.connect(context.destination) + if (AudioContext == null) return + audioContext = audioContext ?? new AudioContext() + const source = audioContext.createBufferSource() + source.buffer = await audioContext.decodeAudioData(arrayBuffer.slice(0)) + source.connect(audioContext.destination) source.start() } From 0ed01987219f1abff0302385d9f46e235dc49449 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 25 Dec 2023 20:37:28 -0600 Subject: [PATCH 2/6] Assume globalThis exists --- themes/default/assets/js/gamer.js | 8 ++++---- themes/default/assets/js/modal.js | 4 ++-- themes/default/assets/js/theme.js | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/themes/default/assets/js/gamer.js b/themes/default/assets/js/gamer.js index 750f962..8e531a4 100644 --- a/themes/default/assets/js/gamer.js +++ b/themes/default/assets/js/gamer.js @@ -1,5 +1,5 @@ -globalThis?.addEventListener('DOMContentLoaded', () => { - const document = globalThis?.document +globalThis.addEventListener('DOMContentLoaded', () => { + const document = globalThis.document if (document == null) return initHandlers(document) }) @@ -48,7 +48,7 @@ const initSound = (n) => { } const createSound = (src) => { - const fetch = globalThis?.fetch + const fetch = globalThis.fetch const preloaded = fetch(src) .then((res) => res.arrayBuffer()) .catch(console.error) @@ -60,7 +60,7 @@ const createSound = (src) => { let audioContext const playAudioBuffer = async (arrayBuffer) => { - const AudioContext = globalThis?.AudioContext + const AudioContext = globalThis.AudioContext if (AudioContext == null) return audioContext = audioContext ?? new AudioContext() const source = audioContext.createBufferSource() diff --git a/themes/default/assets/js/modal.js b/themes/default/assets/js/modal.js index 3b97efb..d9c6954 100644 --- a/themes/default/assets/js/modal.js +++ b/themes/default/assets/js/modal.js @@ -1,5 +1,5 @@ -globalThis?.addEventListener('DOMContentLoaded', () => { - const document = globalThis?.document +globalThis.addEventListener('DOMContentLoaded', () => { + const document = globalThis.document if (document == null) return initHandlers(document) }) diff --git a/themes/default/assets/js/theme.js b/themes/default/assets/js/theme.js index cd7b9bb..9caa943 100644 --- a/themes/default/assets/js/theme.js +++ b/themes/default/assets/js/theme.js @@ -1,5 +1,5 @@ -globalThis?.addEventListener('DOMContentLoaded', () => { - const document = globalThis?.document +globalThis.addEventListener('DOMContentLoaded', () => { + const document = globalThis.document if (document == null) return initHandlers(document) }) @@ -34,16 +34,16 @@ const toggleTheme = (document) => { const setTheme = (document, colorScheme) => { activeColorScheme = colorScheme - globalThis?.sessionStorage?.setItem('activeColorScheme', colorScheme) + globalThis.sessionStorage?.setItem('activeColorScheme', colorScheme) document.querySelector('html').setAttribute('data-theme', colorScheme) } const getActiveTheme = () => - globalThis?.sessionStorage?.getItem('activeColorScheme') ?? + globalThis.sessionStorage?.getItem('activeColorScheme') ?? preferedColorScheme() const preferedColorScheme = () => { - const matchMedia = globalThis?.matchMedia + const matchMedia = globalThis.matchMedia if (matchMedia == null) return const isDark = matchMedia('(prefers-color-scheme: dark)').matches return isDark ? 'dark' : 'light' From 812f4aa62f9f84fb6161863e904205599d04f7d4 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 25 Dec 2023 20:50:28 -0600 Subject: [PATCH 3/6] Remove trailingComma prettier override --- .prettierrc.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.prettierrc.json b/.prettierrc.json index d38f5f5..14c717d 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -2,6 +2,5 @@ "semi": false, "singleQuote": true, "jsxSingleQuote": true, - "trailingComma": "none", "endOfLine": "lf" } From a60235f81d7767ba821a5eb0450b97fdcef4e155 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Tue, 26 Dec 2023 02:51:13 +0000 Subject: [PATCH 4/6] Run format --- themes/default/assets/js/gamer.js | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/themes/default/assets/js/gamer.js b/themes/default/assets/js/gamer.js index 8e531a4..59c679c 100644 --- a/themes/default/assets/js/gamer.js +++ b/themes/default/assets/js/gamer.js @@ -17,7 +17,7 @@ const initHandler = (element) => { if (textEl == null || iconEl == null) return let n = games.findIndex( - ({ icon }) => iconEl.getAttribute('data-icon') === icon + ({ icon }) => iconEl.getAttribute('data-icon') === icon, ) preloadSounds(n) @@ -54,7 +54,7 @@ const createSound = (src) => { .catch(console.error) return { - play: () => preloaded.then(playAudioBuffer).catch(console.error) + play: () => preloaded.then(playAudioBuffer).catch(console.error), } } @@ -73,71 +73,71 @@ const games = [ { icon: 'alien-8bit-solid', sound: - '{{ (resources.Get "audio/shoot.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/shoot.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'block-question-solid', sound: - '{{ (resources.Get "audio/coin.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/coin.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'mushroom-duotone', sound: - '{{ (resources.Get "audio/1up.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/1up.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'dungeon-duotone', sound: - '{{ (resources.Get "audio/secret.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/secret.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'treasure-chest-solid', sound: - '{{ (resources.Get "audio/item.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/item.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'skull-duotone', sound: - '{{ (resources.Get "audio/eekum-bokum.mp3" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/eekum-bokum.mp3" | resources.Fingerprint).RelPermalink }}', }, { icon: 'music-regular', sound: - '{{ (resources.Get "audio/note.ogg" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/note.ogg" | resources.Fingerprint).RelPermalink }}', }, { icon: 'puzzle-piece-duotone', sound: - '{{ (resources.Get "audio/jiggy.ogg" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/jiggy.ogg" | resources.Fingerprint).RelPermalink }}', }, { icon: 'starfighter-twin-ion-engine-solid', sound: - '{{ (resources.Get "audio/tie-fighter.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/tie-fighter.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'starfighter-solid', sound: - '{{ (resources.Get "audio/laser.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/laser.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'starship-freighter-solid', sound: - '{{ (resources.Get "audio/chewbacca.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/chewbacca.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'starship-solid', sound: - '{{ (resources.Get "audio/intercom.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/intercom.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'ring-duotone', sound: - '{{ (resources.Get "audio/ring.wav" | resources.Fingerprint).RelPermalink }}' + '{{ (resources.Get "audio/ring.wav" | resources.Fingerprint).RelPermalink }}', }, { icon: 'ghost-duotone', sound: - '{{ (resources.Get "audio/death.mp3" | resources.Fingerprint).RelPermalink }}' - } + '{{ (resources.Get "audio/death.mp3" | resources.Fingerprint).RelPermalink }}', + }, ] From 83466bcf14bfc3ebe2c00c98df4b7916e87342f7 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 25 Dec 2023 20:52:03 -0600 Subject: [PATCH 5/6] Use globalThis.setTimeout --- themes/default/assets/js/theme.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/default/assets/js/theme.js b/themes/default/assets/js/theme.js index 9caa943..18c5a45 100644 --- a/themes/default/assets/js/theme.js +++ b/themes/default/assets/js/theme.js @@ -24,10 +24,10 @@ const initHandler = (document, element) => { const toggleTheme = (document) => { const colorScheme = activeColorScheme === 'dark' ? 'light' : 'dark' document.querySelector('html').classList.add('theme-transistion') - setTimeout(() => { + globalThis.setTimeout(() => { setTheme(document, colorScheme) }, 0) - setTimeout(() => { + globalThis.setTimeout(() => { document.querySelector('html').classList.remove('theme-transistion') }, 2000) } From e5730af6adb32a958e9599a2db53eb668d0c0742 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 25 Dec 2023 20:56:25 -0600 Subject: [PATCH 6/6] Use '??=' --- themes/default/assets/js/gamer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/default/assets/js/gamer.js b/themes/default/assets/js/gamer.js index 59c679c..a5da6df 100644 --- a/themes/default/assets/js/gamer.js +++ b/themes/default/assets/js/gamer.js @@ -62,7 +62,7 @@ let audioContext const playAudioBuffer = async (arrayBuffer) => { const AudioContext = globalThis.AudioContext if (AudioContext == null) return - audioContext = audioContext ?? new AudioContext() + audioContext ??= new AudioContext() const source = audioContext.createBufferSource() source.buffer = await audioContext.decodeAudioData(arrayBuffer.slice(0)) source.connect(audioContext.destination)