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
28 lines (23 loc) · 905 Bytes
/
document.ts
File metadata and controls
28 lines (23 loc) · 905 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
import { anyMatch } from "./array"
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
}
if (location.hostname !== chrome.runtime?.id) return true
return !window?.document
}
export const isRtl = (): boolean => {
if (isNotExtensionPage()) return false
const htmlEl = document.getElementsByTagName("html")?.[0]
return htmlEl?.getAttribute('dir') === 'rtl'
}