forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.ts
More file actions
31 lines (25 loc) · 981 Bytes
/
document.ts
File metadata and controls
31 lines (25 loc) · 981 Bytes
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
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'
}