Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"repository": "https://github.com/Mr-Quin/danmaku-anywhere",
"scripts": {
"dev:web-app": "pnpm -r -F \"./app/web\" start",
"dev:extension": "pnpm -r -F \"./packages/danmaku-anywhere\" dev",
"dev:extension:standalone": "pnpm -r -F \"./packages/danmaku-anywhere\" standalone:dev",
"build": "pnpm -r build",
"build:packages": "pnpm -r -F \"./packages/**\" build",
"format": "pnpm -r -F \"./packages/**\" format",
Expand Down
2 changes: 1 addition & 1 deletion packages/danmaku-anywhere/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const manifest = defineManifest({
run_at: 'document_start',
},
{
matches: ['https://*/*', 'http://*/*'],
matches: ['<all_urls>'],
js: ['src/content/player/index.ts'],
run_at: 'document_start',
all_frames: true,
Expand Down
25 changes: 11 additions & 14 deletions packages/danmaku-anywhere/src/common/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,21 @@ export const matchWithPinyin = (inputString: string, searchString: string) => {
return !!pinyinMatches
}

function fallbackGenerateUUID(): string {
const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return template.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0
const v = c === 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}

export const getRandomUUID = () => {
try {
return globalThis.crypto.randomUUID()
} catch (e) {
console.warn(
'Failed to generate UUID using crypto.randomUUID, falling back to Math.random',
e
)
} catch {
// fallback to Math.random if crypto.randomUUID is not available
const generateUUID = (): string => {
const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return template.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0
const v = c === 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}
return generateUUID()
return fallbackGenerateUUID()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type ILogger, LoggerSymbol } from '@/common/Logger'
import { createRpcServer } from '@/common/rpc/server'
import { playerRpcClient } from '@/common/rpcClient/background/client'
import type { PlayerRelayCommands } from '@/common/rpcClient/background/types'
import { getRandomUUID } from '@/common/utils/utils'
import { PlayerCommandHandler } from '@/content/player/PlayerCommandHandler.service'

/**
Expand All @@ -20,7 +21,7 @@ import { PlayerCommandHandler } from '@/content/player/PlayerCommandHandler.serv
export class PlayerScript {
private logger: ILogger
private frameId = -1
private readonly documentId = crypto.randomUUID()
private readonly documentId = getRandomUUID()

constructor(@inject(LoggerSymbol) logger: ILogger) {
this.logger = logger.sub('[PlayerScript]')
Expand Down
Loading