-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.ts
69 lines (59 loc) · 2.01 KB
/
index.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const textElements: Array<HTMLElement> = [
get("shortBlurb"),
get("download"),
get("totalUsers"),
]
const translator = new Translator(lang, langs)
async function index() {
document.documentElement.lang = lang
if (isArScript) document.dir = "rtl"
else document.dir = "ltr"
await translator.initialize()
textElements.forEach((element: HTMLElement) => {
element.innerHTML = translator.get(element.id)
})
}
function specifics() {
// Language specific actions
switch (lang) {
case ar: {
textElements.forEach((element: HTMLElement) => {
element.style.fontFamily = arFont
element.style.lineHeight = "1.3em"
})
break
}
case fa: {
textElements.forEach((element: HTMLElement) => {
element.style.fontFamily = faFont
element.style.lineHeight = "1.3em"
})
break
}
default : {
break
}
}
}
async function displayTotalUsers() {
const chromeResponse = await (await fetch(`https://api.allorigins.win/get?url=${
encodeURIComponent("https://chrome.google.com/webstore/detail/wudooh/nigfaloeeeakmmgndbdcijjegolpjfhn")}`)
).json()
const chromeUsers: number = parseInt(
("" + chromeResponse.contents.match(/<span class="e-f-ih" title="([\d]*?) users">([\d]*?) users<\/span>/)).split(",")[2]
)
const firefoxResponse = await (await fetch(`https://api.allorigins.win/get?url=${
encodeURIComponent("https://addons.mozilla.org/en-US/firefox/addon/wudooh/")}`)
).json()
const firefoxUsers = parseInt(
("" + firefoxResponse.contents.match(/<dd class="MetadataCard-content">([\d]*?)<\/dd>/)).match(/\d+/g)[0]
)
const totalUsers = chromeUsers + firefoxUsers
let text: string = "..."
if (isNaN(totalUsers)) displayTotalUsers()
else text = totalUsers.toString()
get("numUsers").innerHTML = text
}
specifics()
index()
//displayTotalUsers()