easy-claude 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +19 -4
- package/native/Overlay.swift +130 -15
- package/native/build/EasyClaudeOverlay.app/Contents/Info.plist +1 -1
- package/native/build/EasyClaudeOverlay.app/Contents/MacOS/EasyClaudeOverlay +0 -0
- package/package.json +1 -1
- package/src/overlay-ip.js +3 -0
- package/src/public-ip.js +39 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## v0.2.13(2026-10-20,America/Los_Angeles)
|
|
4
|
+
|
|
5
|
+
- 新增“跟随IP时区”开关,默认关闭;开启后自动显示网络出口时区时间并隐藏手动时区选择,关闭恢复原城市和时区。
|
|
6
|
+
- 获取不到IP或有效时区时显示自定义时区的时间;开关保持开启,后续获取成功自动继续跟随。继续支持系统12/24小时制与夏令时。
|
|
7
|
+
- IP菜单改为“城市名称·IP地址”,无空格;IP获取失败仍显示“IP异常”。城市和时区通过已验证IP查询地理信息,不按城市猜测时区。
|
|
8
|
+
|
|
9
|
+
## v0.2.12(2026-10-21)
|
|
10
|
+
|
|
11
|
+
- 菜单新增公网IP和城市,固定从ip.sb获取IP,再查询该IP的出口城市;启动及每5分钟刷新,点击地址可立即刷新。
|
|
12
|
+
- 获取不到IP时显示“IP异常”;仅城市查询失败时保留IP并显示“城市未知”。支持IPv4/IPv6和现有环境/系统HTTPS代理,不保存IP历史。
|
|
13
|
+
|
|
3
14
|
## v0.2.11(2026-10-21)
|
|
4
15
|
|
|
5
16
|
- 新增一次性“额度可用提醒”:同时受5小时和周额度限制时,等待较晚的恢复时间,在线确认全部可用后发送系统通知和提示音,随后自动关闭。
|
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
|
|
6
6
|
|
|
7
|
-
## v0.2.
|
|
7
|
+
## v0.2.13 更新说明
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
9
|
+
- 新增“跟随IP时区”开关,默认关闭;开启后自动显示网络出口时区时间并隐藏手动时区选择,关闭恢复原城市和时区。
|
|
10
|
+
- 获取不到IP或有效时区时显示自定义时区的时间;开关保持开启,后续获取成功自动继续跟随。继续支持系统12/24小时制与夏令时。
|
|
11
|
+
- IP菜单改为“城市名称·IP地址”,无空格;IP获取失败仍显示“IP异常”。城市和时区通过已验证IP查询地理信息,不按城市猜测时区。
|
|
12
12
|
|
|
13
13
|
历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
|
|
14
14
|
|
|
@@ -90,3 +90,18 @@ npm run build:overlay
|
|
|
90
90
|
只有5小时或只有周额度时等待对应恢复;两项都耗尽时等待较晚时间,仍有剩余的窗口不参与等待。到点后约每分钟查询,确认所有已知窗口均有剩余,才发送一次系统通知和提示音,然后自动关闭开关。若等待期间再次耗尽,会继续等到有效恢复。
|
|
91
91
|
|
|
92
92
|
开启状态跨更新/重启保存;关闭可取消。浮窗运行时即使目标应用不在前台也能检查,断网则保留提醒并重试。休眠会延后至唤醒,工具完全退出期间不能提醒,重新启动后补查;系统通知权限、专注模式和声音设置可能影响通知展示或声音。不调用模型、不消耗对话额度。
|
|
93
|
+
|
|
94
|
+
## 公网IP与城市
|
|
95
|
+
|
|
96
|
+
菜单显示“城市名称·IP地址”,由 `https://ip.sb/ip` 获取IP,再通过 `https://api.ip.sb/geoip/<IP>` 获取对应城市;城市名称按接口返回显示。启动和每5分钟刷新,点击该菜单项可立即重查。IP取不到显示“IP异常”;城市取不到显示“城市未知”。
|
|
97
|
+
|
|
98
|
+
查询遵循已有HTTPS/ALL代理环境或macOS系统HTTPS代理。这里显示查询服务看到的网络出口;Clash分流时可能与AI请求不同,城市不代表电脑所在地,关闭“跟随IP时区”时不改变时钟时区。不主动保存IP历史,不发送账号凭据。
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
IP地理库的城市与时区可能存在偏差或互相不一致;显示接口返回值,仅校验时区名称有效性,不根据城市猜测时区。
|
|
102
|
+
|
|
103
|
+
## 跟随IP时区
|
|
104
|
+
|
|
105
|
+
菜单开启“跟随IP时区”后,时钟按地理接口返回的IANA时区显示当地时间,自动处理夏令时,继续跟随系统12/24小时制;时钟下方显示“IP时区”,手动时区选择隐藏。IP每5分钟刷新或点击IP菜单刷新,时区同步更新。
|
|
106
|
+
|
|
107
|
+
关闭后恢复之前手动选择的城市和时区,并重新显示选择菜单。取不到IP或有效时区时,时钟回退到手动设置的时区,菜单提示“IP时区不可用,显示自定义时间”;开关仍开启,获取成功后继续跟随。开关和手动设置跨重启/更新保存,不保存IP历史。IP地理数据可能不准确,跟随的是出口时区,不修改电脑系统时区。
|
package/native/Overlay.swift
CHANGED
|
@@ -232,6 +232,26 @@ final class ClockView: RingView {
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
struct IPClockState {
|
|
236
|
+
private(set) var zone: TimeZone?
|
|
237
|
+
mutating func update(_ identifier: String?) -> Bool {
|
|
238
|
+
guard let identifier, let next = TimeZone(identifier: identifier) else { zone = nil; return false }
|
|
239
|
+
zone = next
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
func resolved(manual: TimeZone, following: Bool) -> TimeZone { following ? zone ?? manual : manual }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
struct PublicIP: Decodable {
|
|
246
|
+
let ip: String?
|
|
247
|
+
let city: String?
|
|
248
|
+
let timezone: String?
|
|
249
|
+
}
|
|
250
|
+
func publicIPText(ip: String?, city: String?) -> String {
|
|
251
|
+
guard let ip, !ip.isEmpty else { return "IP异常" }
|
|
252
|
+
return "\(city ?? "城市未知")·\(ip)"
|
|
253
|
+
}
|
|
254
|
+
|
|
235
255
|
// 只等待耗尽窗口,但确认恢复时必须同时检查所有已知窗口,缺失或未知不能报可用。
|
|
236
256
|
struct AvailabilityReminder: Codable {
|
|
237
257
|
var ids: [String]
|
|
@@ -270,8 +290,15 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
270
290
|
let clock = ClockView(frame: CGRect(x: 0, y: 0, width: 96, height: 46))
|
|
271
291
|
var clockInset = CGPoint(x: 164, y: 0)
|
|
272
292
|
var clockEnabled = true
|
|
293
|
+
var followIPTimeZone = UserDefaults.standard.bool(forKey: "followIPTimeZone")
|
|
294
|
+
var ipClock = IPClockState()
|
|
295
|
+
var manualClockZone = TimeZone(identifier: "America/Los_Angeles")!
|
|
296
|
+
var manualClockCity = "硅谷"
|
|
273
297
|
var status: NSStatusItem?
|
|
274
298
|
var timer: Timer?
|
|
299
|
+
var ipQuery: Process?
|
|
300
|
+
var ipLastAttempt = Date.distantPast
|
|
301
|
+
var ipText = "正在获取IP…"
|
|
275
302
|
var query: Process?
|
|
276
303
|
var updater: Process?
|
|
277
304
|
var versionCheck: Process?
|
|
@@ -311,6 +338,8 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
311
338
|
?? ClockCity.presets.first { $0.identifier == identifier }
|
|
312
339
|
clock.cityName = preset?.name ?? identifier
|
|
313
340
|
}
|
|
341
|
+
manualClockZone = clock.zone; manualClockCity = clock.cityName
|
|
342
|
+
applyClockTimeZone()
|
|
314
343
|
ring.showWeeklyPercentage = prefs.bool(forKey: "showWeeklyPercentage")
|
|
315
344
|
clockEnabled = prefs.object(forKey: "clockEnabled") == nil || prefs.bool(forKey: "clockEnabled")
|
|
316
345
|
if prefs.object(forKey: "clockLeftInset") != nil {
|
|
@@ -358,6 +387,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
358
387
|
@objc func hide() { panel.orderOut(nil); clockPanel.orderOut(nil) }
|
|
359
388
|
@objc func tick() {
|
|
360
389
|
checkVersionIfNeeded()
|
|
390
|
+
if Date().timeIntervalSince(ipLastAttempt) >= 300 { refreshIP() }
|
|
361
391
|
if let reminder, Date().timeIntervalSince(lastAttempt) >= (Date().timeIntervalSince1970 >= reminder.due ? 60 : 300) { refresh() }
|
|
362
392
|
guard let rect = targetWindow() else { hide(); lastRect = nil; return }
|
|
363
393
|
lastRect = rect
|
|
@@ -434,6 +464,47 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
434
464
|
do { try process.run() }
|
|
435
465
|
catch { query = nil; self.error = "无法启动额度查询,请重新运行 easy-claude show"; updateRing() }
|
|
436
466
|
}
|
|
467
|
+
func applyClockTimeZone() {
|
|
468
|
+
clock.zone = ipClock.resolved(manual: manualClockZone, following: followIPTimeZone)
|
|
469
|
+
clock.cityName = followIPTimeZone && ipClock.zone != nil ? "IP时区" : manualClockCity
|
|
470
|
+
clock.needsDisplay = true
|
|
471
|
+
}
|
|
472
|
+
func receiveIPTimeZone(_ identifier: String?) {
|
|
473
|
+
_ = ipClock.update(identifier)
|
|
474
|
+
applyClockTimeZone()
|
|
475
|
+
}
|
|
476
|
+
@objc func toggleFollowIPTimeZone() {
|
|
477
|
+
followIPTimeZone.toggle()
|
|
478
|
+
UserDefaults.standard.set(followIPTimeZone, forKey: "followIPTimeZone")
|
|
479
|
+
applyClockTimeZone()
|
|
480
|
+
if followIPTimeZone { refreshIP() }
|
|
481
|
+
}
|
|
482
|
+
@objc func refreshIP() {
|
|
483
|
+
guard ipQuery == nil else { return }
|
|
484
|
+
ipLastAttempt = Date()
|
|
485
|
+
let process = Process(), pipe = Pipe()
|
|
486
|
+
process.executableURL = URL(fileURLWithPath: node)
|
|
487
|
+
process.arguments = [URL(fileURLWithPath: script).deletingLastPathComponent().appendingPathComponent("overlay-ip.js").path]
|
|
488
|
+
var env = ProcessInfo.processInfo.environment
|
|
489
|
+
env["PATH"] = searchPath
|
|
490
|
+
process.environment = env
|
|
491
|
+
process.standardOutput = pipe
|
|
492
|
+
process.standardError = FileHandle.nullDevice
|
|
493
|
+
process.terminationHandler = { [weak self] process in
|
|
494
|
+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
|
495
|
+
let value = try? JSONDecoder().decode(PublicIP.self, from: data)
|
|
496
|
+
let text = publicIPText(ip: process.terminationStatus == 0 ? value?.ip : nil, city: value?.city)
|
|
497
|
+
let timezone = process.terminationStatus == 0 ? value?.timezone : nil
|
|
498
|
+
Task { @MainActor in
|
|
499
|
+
guard let self else { return }
|
|
500
|
+
self.ipQuery = nil; self.ipText = text
|
|
501
|
+
self.receiveIPTimeZone(timezone)
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
ipQuery = process
|
|
505
|
+
do { try process.run() }
|
|
506
|
+
catch { ipQuery = nil; ipText = "IP异常"; receiveIPTimeZone(nil) }
|
|
507
|
+
}
|
|
437
508
|
func saveReminder() {
|
|
438
509
|
if let reminder, let data = try? JSONEncoder().encode(reminder) {
|
|
439
510
|
UserDefaults.standard.set(data, forKey: "availabilityReminder")
|
|
@@ -516,6 +587,9 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
516
587
|
menu.addItem(item(lastRect == nil ? "等待 Claude 前台窗口" : "拖动圆环可调整位置", nil))
|
|
517
588
|
if let error { menu.addItem(item(error, nil)) }
|
|
518
589
|
if snapshot?.restricted == true { menu.addItem(item("服务端提示:当前使用受限", nil)) }
|
|
590
|
+
let address = item(ipText, ipQuery == nil ? #selector(refreshIP) : nil)
|
|
591
|
+
address.toolTip = "点击刷新公网IP;城市为网络出口位置"
|
|
592
|
+
menu.addItem(address)
|
|
519
593
|
menu.addItem(.separator())
|
|
520
594
|
for (id, label) in [("five_hour:primary", "5小时"), ("seven_day:primary", "周")] {
|
|
521
595
|
guard let window = snapshot?.windows.first(where: { $0.id == id }) else { continue }
|
|
@@ -539,17 +613,25 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
539
613
|
let toggle = item("显示时间", #selector(toggleClock))
|
|
540
614
|
toggle.state = clockEnabled ? .on : .off
|
|
541
615
|
menu.addItem(toggle)
|
|
542
|
-
let
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
616
|
+
let follow = item("跟随IP时区", #selector(toggleFollowIPTimeZone))
|
|
617
|
+
follow.state = followIPTimeZone ? .on : .off
|
|
618
|
+
menu.addItem(follow)
|
|
619
|
+
if followIPTimeZone && ipClock.zone == nil {
|
|
620
|
+
menu.addItem(item("IP时区不可用,显示自定义时间", nil))
|
|
621
|
+
}
|
|
622
|
+
if !followIPTimeZone {
|
|
623
|
+
let zones = NSMenu()
|
|
624
|
+
for city in ClockCity.presets {
|
|
625
|
+
let option = item(city.name, #selector(selectTimeZone(_:)))
|
|
626
|
+
option.representedObject = city.name
|
|
627
|
+
option.state = clock.cityName == city.name && clock.zone.identifier == city.identifier ? .on : .off
|
|
628
|
+
zones.addItem(option)
|
|
629
|
+
}
|
|
630
|
+
zones.addItem(item("自定义时区…", #selector(customTimeZone)))
|
|
631
|
+
let zoneItem = item("\(clock.cityName)·\(clockText(at: Date(), zone: clock.zone))", nil)
|
|
632
|
+
zoneItem.submenu = zones
|
|
633
|
+
menu.addItem(zoneItem)
|
|
634
|
+
}
|
|
553
635
|
menu.addItem(.separator())
|
|
554
636
|
let updateItem = item(updater == nil ? "更新版本·\(appVersion)" : "正在更新…·\(appVersion)",
|
|
555
637
|
updater == nil ? #selector(updateVersion) : nil)
|
|
@@ -590,11 +672,13 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
590
672
|
}
|
|
591
673
|
func setTimeZone(_ identifier: String, cityName: String? = nil) -> Bool {
|
|
592
674
|
guard let zone = TimeZone(identifier: identifier) else { return false }
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
UserDefaults.standard.set(
|
|
675
|
+
manualClockZone = zone
|
|
676
|
+
manualClockCity = cityName ?? ClockCity.presets.first { $0.identifier == zone.identifier }?.name ?? zone.identifier
|
|
677
|
+
UserDefaults.standard.set(manualClockCity, forKey: "clockCity")
|
|
596
678
|
UserDefaults.standard.set(zone.identifier, forKey: "clockTimeZone")
|
|
597
|
-
|
|
679
|
+
followIPTimeZone = false
|
|
680
|
+
UserDefaults.standard.set(false, forKey: "followIPTimeZone")
|
|
681
|
+
applyClockTimeZone()
|
|
598
682
|
return true
|
|
599
683
|
}
|
|
600
684
|
@objc func selectTimeZone(_ sender: NSMenuItem) {
|
|
@@ -745,6 +829,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
745
829
|
}
|
|
746
830
|
@objc func quit() { NSApp.terminate(nil) }
|
|
747
831
|
func applicationWillTerminate(_ notification: Notification) {
|
|
832
|
+
ipQuery?.terminate()
|
|
748
833
|
timer?.invalidate()
|
|
749
834
|
query?.terminate()
|
|
750
835
|
versionCheck?.terminate()
|
|
@@ -772,6 +857,36 @@ struct Main {
|
|
|
772
857
|
}
|
|
773
858
|
|
|
774
859
|
if CommandLine.arguments.contains("--self-test") {
|
|
860
|
+
let manualIPTest = TimeZone(identifier: "Asia/Shanghai")!
|
|
861
|
+
var ipClockTest = IPClockState()
|
|
862
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: true) == manualIPTest)
|
|
863
|
+
precondition(ipClockTest.update("America/Los_Angeles"))
|
|
864
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: true).identifier == "America/Los_Angeles")
|
|
865
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: false) == manualIPTest)
|
|
866
|
+
precondition(!ipClockTest.update(nil) && !ipClockTest.update("Invalid/Zone"))
|
|
867
|
+
precondition(ipClockTest.zone == nil)
|
|
868
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: true) == manualIPTest)
|
|
869
|
+
precondition(ipClockTest.update("Asia/Singapore"))
|
|
870
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: true).identifier == "Asia/Singapore")
|
|
871
|
+
_ = NSApplication.shared
|
|
872
|
+
let clockMenuTest = Overlay()
|
|
873
|
+
clockMenuTest.manualClockZone = manualIPTest
|
|
874
|
+
clockMenuTest.manualClockCity = "上海"
|
|
875
|
+
clockMenuTest.followIPTimeZone = true
|
|
876
|
+
_ = clockMenuTest.ipClock.update("America/Los_Angeles")
|
|
877
|
+
clockMenuTest.applyClockTimeZone()
|
|
878
|
+
precondition(clockMenuTest.clock.zone.identifier == "America/Los_Angeles")
|
|
879
|
+
precondition(!clockMenuTest.makeMenu().items.contains { $0.submenu != nil })
|
|
880
|
+
clockMenuTest.receiveIPTimeZone(nil)
|
|
881
|
+
precondition(clockMenuTest.clock.zone == manualIPTest && clockMenuTest.clock.cityName == "上海")
|
|
882
|
+
precondition(clockMenuTest.followIPTimeZone)
|
|
883
|
+
clockMenuTest.followIPTimeZone = false
|
|
884
|
+
clockMenuTest.applyClockTimeZone()
|
|
885
|
+
precondition(clockMenuTest.makeMenu().items.contains { $0.submenu != nil })
|
|
886
|
+
print("跟随IP时区:开关、手动恢复、失败回退及出口变化检查通过")
|
|
887
|
+
precondition(publicIPText(ip: nil, city: "City") == "IP异常")
|
|
888
|
+
precondition(publicIPText(ip: "203.0.113.1", city: nil) == "城市未知·203.0.113.1")
|
|
889
|
+
precondition(publicIPText(ip: "203.0.113.1", city: "City") == "City·203.0.113.1")
|
|
775
890
|
func quota(_ id: String, _ remaining: Double?, _ reset: Double?) -> UsageWindow {
|
|
776
891
|
UsageWindow(id: id, label: id, name: id, remaining: remaining, resetsAt: reset)
|
|
777
892
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<key>CFBundleIdentifier</key><string>com.unionschool.easy-claude.overlay</string>
|
|
6
6
|
<key>CFBundleName</key><string>Easy Claude Overlay</string>
|
|
7
7
|
<key>CFBundlePackageType</key><string>APPL</string>
|
|
8
|
-
<key>CFBundleShortVersionString</key><string>0.2.
|
|
8
|
+
<key>CFBundleShortVersionString</key><string>0.2.13</string>
|
|
9
9
|
<key>LSMinimumSystemVersion</key><string>14.0</string>
|
|
10
10
|
<key>LSUIElement</key><true/>
|
|
11
11
|
<key>NSHighResolutionCapable</key><true/>
|
|
Binary file
|
package/package.json
CHANGED
package/src/public-ip.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { isIP } from 'node:net';
|
|
4
|
+
import { systemProxy } from './transport.js';
|
|
5
|
+
|
|
6
|
+
export async function readPublicIP({ run = promisify(execFile), env = process.env, platform = process.platform } = {}) {
|
|
7
|
+
let proxy = env.https_proxy || env.HTTPS_PROXY || env.all_proxy || env.ALL_PROXY;
|
|
8
|
+
if (!proxy && platform === 'darwin') {
|
|
9
|
+
const { stdout } = await run('/usr/sbin/scutil', ['--proxy'], { timeout: 2000, maxBuffer: 65536 });
|
|
10
|
+
proxy = systemProxy(stdout);
|
|
11
|
+
}
|
|
12
|
+
const request = async url => {
|
|
13
|
+
const { stdout } = await run('/usr/bin/curl', ['-q', '--silent', '--show-error', '--fail', '--proto', '=https',
|
|
14
|
+
'--connect-timeout', '5', '--max-time', '12', '--max-redirs', '0', url], {
|
|
15
|
+
timeout: 15000, maxBuffer: 8192, env: proxy ? { ...env, https_proxy: proxy } : env
|
|
16
|
+
});
|
|
17
|
+
return stdout;
|
|
18
|
+
};
|
|
19
|
+
let ip;
|
|
20
|
+
try { ip = (await request('https://ip.sb/ip')).trim(); }
|
|
21
|
+
catch { throw new Error('IP异常'); }
|
|
22
|
+
if (!isIP(ip)) throw new Error('IP异常');
|
|
23
|
+
let city = null, timezone = null;
|
|
24
|
+
try {
|
|
25
|
+
const data = JSON.parse(await request('https://api.ip.sb/geoip/' + ip));
|
|
26
|
+
if (data.ip === ip) {
|
|
27
|
+
if (typeof data.city === 'string') {
|
|
28
|
+
city = data.city.replace(/[\x00-\x1f\x7f-\x9f]/g, ' ').trim().slice(0, 60) || null;
|
|
29
|
+
}
|
|
30
|
+
if (typeof data.timezone === 'string' && data.timezone.length <= 100) {
|
|
31
|
+
try {
|
|
32
|
+
new Intl.DateTimeFormat('en', { timeZone: data.timezone });
|
|
33
|
+
timezone = data.timezone;
|
|
34
|
+
} catch { /* 无效时区保持未知,不改用电脑时区。 */ }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch { /* 城市查询失败仍保留已确认的IP。 */ }
|
|
38
|
+
return { ip, city, timezone };
|
|
39
|
+
}
|