Skip to content

Commit

Permalink
Assume globalThis exists
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Dec 26, 2023
1 parent 561fd6a commit 0ed0198
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions themes/default/assets/js/gamer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
globalThis?.addEventListener('DOMContentLoaded', () => {
const document = globalThis?.document
globalThis.addEventListener('DOMContentLoaded', () => {
const document = globalThis.document
if (document == null) return
initHandlers(document)
})
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions themes/default/assets/js/modal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
globalThis?.addEventListener('DOMContentLoaded', () => {
const document = globalThis?.document
globalThis.addEventListener('DOMContentLoaded', () => {
const document = globalThis.document
if (document == null) return
initHandlers(document)
})
Expand Down
10 changes: 5 additions & 5 deletions themes/default/assets/js/theme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
globalThis?.addEventListener('DOMContentLoaded', () => {
const document = globalThis?.document
globalThis.addEventListener('DOMContentLoaded', () => {
const document = globalThis.document
if (document == null) return
initHandlers(document)
})
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 0ed0198

Please sign in to comment.