Skip to content

Commit

Permalink
fix: Sync target not working in content
Browse files Browse the repository at this point in the history
  • Loading branch information
ronparkdev committed Aug 5, 2024
1 parent a85efee commit d693a90
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type { TargetConfig } from 'services/config'
void (async () => {
let lastRightClick: { element: Element } | null = null
let lastElement: Element | null = null
let lastTargets: TargetConfig[] = []
let lastLocalTargets: TargetConfig[] = []
let lastSyncTargets: TargetConfig[] = []
let mode: 'standby' | 'addTarget' = 'standby'

// Top priority functions (for save mouse position for contextmenu)
Expand Down Expand Up @@ -36,18 +37,26 @@ void (async () => {
])

ChromeStorageUtils.get<TargetConfig[]>('local', ConfigService.TARGETS_KEY, []).then(targets => {
lastTargets = targets
lastLocalTargets = targets
})

ChromeStorageUtils.listen<TargetConfig[]>('local', ConfigService.TARGETS_KEY, targets => {
lastTargets = targets
lastLocalTargets = targets
})

ChromeStorageUtils.get<TargetConfig[]>('sync', ConfigService.TARGETS_KEY, []).then(targets => {
lastSyncTargets = targets
})

ChromeStorageUtils.listen<TargetConfig[]>('sync', ConfigService.TARGETS_KEY, targets => {
lastSyncTargets = targets
})

document.addEventListener('keydown', async event => {
const url = UrlUtils.getCurrentUrl()
const hotKey = HotKeyService.parse(event)

const hitTargets = lastTargets
const hitTargets = [...lastLocalTargets, ...lastSyncTargets]
.filter(target => UrlUtils.checkIsMatchedUrl(target.url, url))
.filter(target => HotKeyService.checkIsSame(hotKey, target.hotKey))

Expand Down

0 comments on commit d693a90

Please sign in to comment.