Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/content-script/limit/modal/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getUrl, sendMsg2Runtime } from '@api/chrome/runtime'
import { getRuntimeId, getUrl, sendMsg2Runtime } from '@api/chrome/runtime'
import optionService from '@service/option-service'
import { init as initTheme, toggle } from '@util/dark-mode'
import { createApp, Ref, type App } from 'vue'
Expand Down Expand Up @@ -46,23 +46,30 @@ const createHeader = () => {
}

class ScreenLocker {
private doLock() {
const ele = document?.documentElement
if (ele) {
document.documentElement.style.setProperty('overflow', 'hidden', 'important')
}
}
private styleId = `time-tracker-style-${getRuntimeId()}`
private lockedCls = `time-tracker-locked-${getRuntimeId()}`

lock() {
this.doLock()
// Re-lock after 200ms to avoid being unlocked by the original website
setTimeout(() => this.doLock(), 200)
this.insertStyle()
document?.documentElement?.classList?.add?.(this.lockedCls)
}

unlock() {
if (document?.documentElement) {
document.documentElement.style.overflow = 'auto'
}
document?.documentElement?.classList?.remove(this.lockedCls)
}

private insertStyle() {
if (!document) return
if (document.getElementById(this.styleId)) return
const style = document.createElement('style')
style.id = this.styleId
const css = `
.${this.lockedCls} {
overflow: hidden !important;
}
`
style.appendChild(document.createTextNode(css))
document.head?.appendChild(style)
}
}

Expand Down