This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
forked from lmichelin/open-github-links-in-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.ts
50 lines (40 loc) · 1.81 KB
/
popup.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
import "./milligram.css"
import { Editor } from "./types"
import { setExtensionIcon, getOptions } from "./utils"
const run = async () => {
const OPTIONS = await getOptions()
const localPathInputElement = document.getElementById("localPathForRepositories") as HTMLInputElement
const defaultIdeSelectElement = document.getElementById("defaultIde") as HTMLSelectElement
const checkboxes = [
"showIconInFileTree",
"showIconOnFileBlockHeaders",
"showIconOnLineNumbers",
"showDebugMessages",
] as const
// set localPathForRepositories and defaultIde values
localPathInputElement.value = OPTIONS.localPathForRepositories
defaultIdeSelectElement.value = OPTIONS.defaultIde
// add EventListener for localPathForRepositories
localPathInputElement.addEventListener("input", event => {
let localPathForRepositories = (event.target as HTMLInputElement).value
if (localPathForRepositories.endsWith("/")) localPathForRepositories = localPathForRepositories.slice(0, -1)
chrome.storage.sync.set({ localPathForRepositories })
})
// add EventListener for defaultIde
defaultIdeSelectElement.addEventListener("change", event => {
const defaultIde = (event.target as HTMLSelectElement).value as Editor
chrome.storage.sync.set({ defaultIde })
setExtensionIcon(defaultIde)
})
checkboxes.forEach(checkbox => {
const checkboxElement = document.getElementById(checkbox) as HTMLInputElement
checkboxElement.checked = OPTIONS[checkbox]
// add EventListener for checkbox
checkboxElement.addEventListener("change", event => {
const eventTarget = event.target as HTMLInputElement
chrome.storage.sync.set({ [eventTarget.id]: eventTarget.checked })
})
})
;(document.getElementById("version") as HTMLSpanElement).innerText = chrome.runtime.getManifest().version
}
void run()