diff --git a/src/index.ts b/src/index.ts index 3ec34b0..a563da4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,8 +119,16 @@ const instance = new FakeFingerPrint({ // width: 9999, // height: 88, // }, - canvas: { - fillText: 'gaga梦', + // canvas: { + // fillText: 'gaga梦', + // }, + // audio: { + // strength: 100, + // }, + timezone: { + zone: 'America/NewYork', + locale: 'en-US', + offset: -5, }, }, report: (arg) => { @@ -128,4 +136,4 @@ const instance = new FakeFingerPrint({ }, }) -instance.open(['canvas']) +instance.open(['timezone']) diff --git a/src/lib/timezone.ts b/src/lib/timezone.ts index 8d3f4fe..676716e 100644 --- a/src/lib/timezone.ts +++ b/src/lib/timezone.ts @@ -1,9 +1,11 @@ import { type AbstractBaseFunc, Base } from './base' export interface TimezoneOpts { - text: string - zone: string - locale: string + /* eg: 'Asia/Shanghai' | 'America/New_York' | 'Europe/London' */ + zone: Intl.DateTimeFormatOptions['timeZone'] + /* eg: 'zh-CN' 'en-US' 'en-GB'...*/ + locale: Intl.LocalesArgument + /* offest of time. unit is hour */ offset: number } @@ -24,18 +26,17 @@ export class TimezoneHandle extends Base implement proxy() { const self = this - Reflect.defineProperty(Intl, 'DateTimeFormat', { - value: new Proxy(Intl.DateTimeFormat, { - get: () => { - self.report({ type: 'timezone', key: 'dateTimeFormat' }) - return function (this: any, ...args: Parameters) { - args[0] = self.config?.locale ?? args[0] - args[1] = { timeZone: self.config?.zone, ...args[1] } - return self.oriDateTimeFormat.apply(this, args) - } - }, - }), - }) + + // @ts-expect-error + Intl.DateTimeFormat = function ( + this: Intl.DateTimeFormat, + ...args: ConstructorParameters + ) { + self.report({ type: 'timezone', key: 'dateTimeFormat' }) + args[0] = (self.config?.locale as any) ?? args[0] + args[1] = { timeZone: self.config?.zone, ...args[1] } + return self.oriDateTimeFormat.apply(this, args) + } Date.prototype.getTimezoneOffset = function (this: Date) { self.report({ type: 'timezone', key: 'getTimezoneOffset' })