-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathdocument.ts
More file actions
36 lines (29 loc) · 1.09 KB
/
document.ts
File metadata and controls
36 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export const setDir = (direction: 'ltr' | 'rtl') => {
if (isNotExtensionPage()) return
const htmlEl = document.getElementsByTagName("html")?.[0]
htmlEl?.setAttribute('dir', direction)
}
export const setLocale = (locale: timer.Locale) => {
if (isNotExtensionPage()) return
const htmlEl = document.getElementsByTagName("html")?.[0]
htmlEl?.setAttribute('data-locale', locale)
}
const isNotExtensionPage = (): boolean => {
if (typeof location === 'undefined' || typeof chrome === 'undefined' || typeof window === 'undefined') {
return true
}
const { protocol } = location || {}
if (protocol === 'https:' || protocol === 'http:' || protocol === "ftp:" || protocol === "file:") {
return true
}
return !chrome.runtime?.id
}
export const isRtl = (): boolean => {
if (isNotExtensionPage()) return false
const htmlEl = document.getElementsByTagName("html")?.[0]
return htmlEl?.getAttribute('dir') === 'rtl'
}
export function stopPropagationAfter<T extends Event>(ev: T, handle: (ev: T) => void) {
handle?.(ev)
ev?.stopPropagation?.()
}