forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskeleton.ts
More file actions
35 lines (29 loc) · 946 Bytes
/
skeleton.ts
File metadata and controls
35 lines (29 loc) · 946 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
32
33
34
35
import { init as initTheme } from "@util/dark-mode"
import { type FrameRequest, type FrameResponse } from "./message"
import { injectSkeletonCss } from './style/skeleton'
function injectFrame() {
const iframe: HTMLIFrameElement = document.createElement('iframe')
iframe.src = 'popup.html'
iframe.style.display = 'none'
document.body.append(iframe)
window.onmessage = (ev: MessageEvent) => {
const { stamp, data } = ev.data as FrameRequest || {}
if (data !== 'themeInitialized') return
iframe.style.display = 'block'
const res: FrameResponse = { stamp }
ev.source?.postMessage?.(res)
}
}
/**
* Skeleton screen of popup
*/
async function main() {
// Calculate the latest mode
initTheme()
injectSkeletonCss()
// Resize after init theme
document.body.style.width = '766px'
document.body.style.height = '596px'
setTimeout(() => injectFrame())
}
main()