The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
移除现有 `chrome_extension` 和 `firefox_extension`
XiaoYouChR8f6bd92e7080
diff --git a/chrome_extension/background.js b/chrome_extension/background.jsdeleted file mode 100644index d9cb5e1e..00000000--- a/chrome_extension/background.js+++ /dev/null@@ -1,185 +0,0 @@-// background.js--let socket;-let isConnected = false;-let shouldDisableExtension = false;-let heartbeatInterval = null;--// 创建 WebSocket 连接-function connectWebSocket() {- try {- socket = new WebSocket("ws://localhost:14370");-- socket.onopen = () => {- console.log("WebSocket connection opened");- updateConnectionStatus(true);- startHeartbeat();- };-- socket.onmessage = function(event) {- const message = JSON.parse(event.data);- // console.log("Received message", message.ClientVersion, message.LatestExtensionVersion);- if (message.type === "version") {- // 保存版本信息到 chrome.storage.local- chrome.storage.local.set({ ClientVersion: message.ClientVersion }, function() {- // console.log("ClientVersion stored:", message.ClientVersion);- });- chrome.storage.local.set({ LatestExtensionVersion: message.LatestExtensionVersion }, function() {- // console.log("LatestExtensionVersion stored:", message.LatestExtensionVersion);- });- } else {- console.log("Received message:", event.data);- }- };-- socket.onerror = (error) => {- console.log("WebSocket error: ", error);- updateConnectionStatus(false);- stopHeartbeat(); // 关闭连接时停止心跳- };-- socket.onclose = () => {- console.log("WebSocket connection closed, retrying in 2500 microseconds");- updateConnectionStatus(false);- if (!shouldDisableExtension) {- setTimeout(connectWebSocket, 2500);- }- stopHeartbeat(); // 关闭连接时停止心跳- };- } catch (e) {- console.log("Exception in WebSocket connection: ", e);- setTimeout(connectWebSocket, 2500);- }-}--// 更新连接状态并更新扩展状态和徽章-function updateConnectionStatus(connected) {- isConnected = connected;- updateBadge(connected ? "connected" : "disconnected");- updateStatus(connected);-}--// 更新扩展图标徽章-function updateBadge(status) {- const badgeColor = (status === "connected") ? "green" : "pink";- const badgeText = (status === "connected") ? "√" : "×";- chrome.action.setBadgeBackgroundColor({ color: badgeColor });- chrome.action.setBadgeText({ text: badgeText });-}--// 更新扩展状态-function updateStatus(connected) {- chrome.storage.local.set({ isConnected: connected }, () => {- console.log(`Status updated: ${connected ? "Connected" : "Disconnected"}`);- });-}--// 启动心跳机制-function startHeartbeat() {- if (!heartbeatInterval) { // 检查是否已有定时器- heartbeatInterval = setInterval(() => {- if (socket.readyState === WebSocket.OPEN) {- try {- socket.send(JSON.stringify({ type: 'heartbeat', timestamp: Date.now() }));- console.log("Heartbeat sent");- } catch (error) {- console.error("Error sending heartbeat:", error); // 仅记录错误,不影响执行- }- }- }, 5000); // 每5秒发送一次心跳- }-}--// 停止心跳机制-function stopHeartbeat() {- if (heartbeatInterval) {- clearInterval(heartbeatInterval); // 清除定时器- heartbeatInterval = null; // 重置定时器变量- }-}--// 提取获取 shouldDisableExtension 的逻辑到一个单独的函数-function isExtensionDisabled(callback) {- chrome.storage.local.get(["shouldDisableExtension"], (result) => {- callback(result.shouldDisableExtension || false);- });-}--// 监听下载开始事件并阻止下载-chrome.downloads.onDeterminingFilename.addListener((downloadItem) => {- if (downloadItem.state === "in_progress") {- chrome.storage.local.get(["shouldDisableExtension"], (result) => {- if (!result.shouldDisableExtension && isConnected && socket.readyState === WebSocket.OPEN) {- console.log("Download started: ", downloadItem);- if (downloadItem.finalUrl.startsWith("http")) {- chrome.downloads.cancel(downloadItem.id);-- // 从映射表中获取对应的请求头- const requestHeaders = requestHeadersMap.get(downloadItem.finalUrl) || {};-- // 构造完整的请求信息- const requestInfo = {- url: downloadItem.finalUrl,- // filesize: downloadItem.fileSize === -1 ? 0 : downloadItem.fileSize, // Ghost Downloader 用 fileSize === 0 表示未知大小, 而 Chrome 使用 -1 表示未知大小- filename: downloadItem.filename,- referer: downloadItem.referrer || "",- headers: requestHeaders,- };-- console.log("捕获到的下载请求信息:", requestInfo);-- // 将请求信息发送到 WebSocket- sendDownloadInfo(requestInfo);-- // 清空 requestHeadersMap- requestHeadersMap.clear();- }- }- });- }-});--let requestHeadersMap = new Map(); // 存储请求头信息的映射表--// 监听 onBeforeSendHeaders 事件,捕获请求头信息并转为字典形式-chrome.webRequest.onBeforeSendHeaders.addListener(- (details) => {- // 将请求头数组转换为字典(键值对形式)- const requestHeadersDict = details.requestHeaders.reduce((acc, header) => {- acc[header.name.toLowerCase()] = header.value;- return acc;- }, {});-- // 存储请求头信息到映射表中,以请求 ID 为键- requestHeadersMap.set(details.url, requestHeadersDict);- console.log("Details url:", details.url);- },- {- urls: ["<all_urls>"], // 监听所有请求- types: ["main_frame", "sub_frame", "xmlhttprequest", "other"], // 资源类型- },- ["requestHeaders", "extraHeaders"] // 需要访问请求头-);--// 修改 sendDownloadInfo 函数,将请求信息发送到 WebSocket-function sendDownloadInfo(requestInfo) {- if (isConnected && socket.readyState === WebSocket.OPEN) {- try {- socket.send(JSON.stringify(requestInfo));- } catch (error) {- console.error("发送下载信息时发生错误:", error);- }- } else {- console.error("WebSocket 未连接");- }-}---// 启动 WebSocket 连接-connectWebSocket();--// 在扩展启动时检查禁用状态-chrome.storage.local.get(["shouldDisableExtension"], (result) => {- shouldDisableExtension = result.shouldDisableExtension || false;- console.log("Extension disable status:", shouldDisableExtension);-});diff --git a/chrome_extension/icon128.png b/chrome_extension/icon128.pngdeleted file mode 100644index 12063d98..00000000Binary files a/chrome_extension/icon128.png and /dev/null differdiff --git a/chrome_extension/icon16.png b/chrome_extension/icon16.pngdeleted file mode 100644index c1fb192d..00000000Binary files a/chrome_extension/icon16.png and /dev/null differdiff --git a/chrome_extension/icon48.png b/chrome_extension/icon48.pngdeleted file mode 100644index 31191227..00000000Binary files a/chrome_extension/icon48.png and /dev/null differdiff --git a/chrome_extension/manifest.json b/chrome_extension/manifest.jsondeleted file mode 100644index d0d96d8b..00000000--- a/chrome_extension/manifest.json+++ /dev/null@@ -1,24 +0,0 @@-{- "name": "Ghost Downloader Browser Extension",- "version": "1.1.1",- "manifest_version": 3,- "description": "Ghost Downloader 的浏览器辅助插件,用于捕获浏览器下载任务.",- "background": {- "service_worker": "background.js"- },- "action": {- "default_popup": "popup.html",- "default_icon": {- "16": "icon16.png",- "48": "icon48.png",- "128": "icon128.png"- }- },- "icons": {- "16": "icon16.png",- "48": "icon48.png",- "128": "icon128.png"- },- "permissions": ["downloads", "webRequest", "activeTab", "storage"],- "host_permissions": ["<all_urls>"]-}diff --git a/chrome_extension/popup.html b/chrome_extension/popup.htmldeleted file mode 100644index e5898be3..00000000--- a/chrome_extension/popup.html+++ /dev/null@@ -1,93 +0,0 @@-<!DOCTYPE html>-<html lang="zh">-<head>- <meta charset="UTF-8">- <meta name="viewport" content="width=device-width, initial-scale=1.0">- <title>Ghost Downloader Browser Extension</title>- <style>- body {- font-family: "Segoe UI", Tahoma, Geneva, sans-serif;- width: 250px;- margin: 0;- padding: 20px;- background-color: #f4f4f4;- border-radius: 8px;- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);- transition: background-color 0.3s, transform 0.2s;- }- body:hover {- background-color: #e9e9e9;- transform: translateY(-1px);- }- #status {- margin-bottom: 5px;- font-size: 16px;- color: #333;- }- #version {- font-size: 14px;- color: #666;- margin-top: 5px;- margin-bottom: 5px;- }- button {- padding: 12px;- border: none;- border-radius: 4px;- width: 100%;- cursor: pointer;- transition: background-color 0.3s, transform 0.2s;- font-size: 16px;- font-weight: bold;- }- #enable-button {- background-color: #ff4c4c;- color: white;- }- #enable-button:hover {- background-color: #ff0000;- transform: scale(1.02);- }- #disable-button {- background-color: #4caf50;- color: white;- display: none; /* Initially hidden */- }- #disable-button:hover {- background-color: #45a049;- transform: scale(1.02);- }- /* 添加深色模式样式 */- body.dark-mode {- background-color: #333;- color: #fff;- }- body.dark-mode:hover {- background-color: #444;- }- body.dark-mode #status {- color: #ccc;- }- body.dark-mode #version {- color: #aaa;- }- body.dark-mode button {- color: white;- }- body.dark-mode #enable-button {- background-color: #ff4c4c;- }- body.dark-mode #disable-button {- background-color: #4caf50;- }- </style>-</head>-<body>-<div id="status">状态: <span id="status-text">正在尝试连接...</span></div>-<div id="version"></div>-<button id="enable-button">插件已禁用</button>-<button id="disable-button">插件已启用</button>--<script src="popup.js"></script>-</body>-</html>\ No newline at end of filediff --git a/chrome_extension/popup.js b/chrome_extension/popup.jsdeleted file mode 100644index fed3282f..00000000--- a/chrome_extension/popup.js+++ /dev/null@@ -1,94 +0,0 @@-// popup.js--// 获取状态元素和禁用按钮-const statusText = document.getElementById("status-text");-const disableButton = document.getElementById("disable-button");-const enableButton = document.getElementById("enable-button");--// 更新状态文本-function updateStatus() {- chrome.storage.local.get("isConnected", (data) => {- statusText.textContent = data.isConnected ? "连接成功" : "连接已断开";- });-- // 检查禁用状态- chrome.storage.local.get("shouldDisableExtension", (result) => {- if (result.shouldDisableExtension) {- disableButton.style.display = "none";- enableButton.style.display = "block";- } else {- disableButton.style.display = "block";- enableButton.style.display = "none";- }- });-}--// 添加禁用按钮点击事件监听器-disableButton.addEventListener("click", () => {- chrome.storage.local.set({ shouldDisableExtension: true }, () => {- console.log("Extension disabled.");- updateStatus();- });-});--// 添加启用按钮点击事件监听器-enableButton.addEventListener("click", () => {- chrome.storage.local.set({ shouldDisableExtension: false }, () => {- console.log("Extension enabled.");- updateStatus();- });-});--// 监听存储变化-chrome.storage.onChanged.addListener((changes, areaName) => {- if (areaName === 'local' && changes.isConnected) {- updateStatus(); // 当 isConnected 发生变化时,更新状态- }-});--function isVersionNewer(v1, v2) {- const parts1 = v1.split('.').map(Number);- const parts2 = v2.split('.').map(Number);-- for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {- const num1 = parts1[i] || 0;- const num2 = parts2[i] || 0;- if (num1 !== num2) {- return num1 > num2; // 如果 v1 更新,返回 true- }- }- return false;-}--// 打印插件版本到插件页面-// 打印插件版本到插件页面-document.addEventListener('DOMContentLoaded', () => {-- const ExtensionVersion = chrome.runtime.getManifest().version;-- // 获取客户端版本和最新插件版本- chrome.storage.local.get(["ClientVersion", "LatestExtensionVersion"], (result) => {- const ClientVersion = result.ClientVersion || "Unknown";- const LatestExtensionVersion = result.LatestExtensionVersion || "Unknown";- // console.log(ExtensionVersion, ClientVersion, LatestExtensionVersion);-- if (isVersionNewer(LatestExtensionVersion, ExtensionVersion)) {- document.getElementById('version').innerHTML = `插件版本: ${ExtensionVersion}  客户端版本: ${ClientVersion}<br/><span style="color: palevioletred;">插件有新版本,请前往客户端手动更新!</span>`;- } else {- document.getElementById('version').innerHTML = `插件版本: ${ExtensionVersion}  客户端版本: ${ClientVersion}`;- }- });-- // 检测系统颜色模式并在初始时设置- if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {- document.body.classList.add('dark-mode');- }-});--// 添加检测系统颜色模式变化的事件监听器-window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (event) => {- document.body.classList.toggle('dark-mode', event.matches);-});--// 更新状态-updateStatus();diff --git a/firefox_extension/background.js b/firefox_extension/background.jsdeleted file mode 100644index 89c14f22..00000000--- a/firefox_extension/background.js+++ /dev/null@@ -1,182 +0,0 @@-// background.js--let socket;-let isConnected = false;-let shouldDisableExtension = false;-let heartbeatInterval = null;--// 创建 WebSocket 连接-function connectWebSocket() {- try {- socket = new WebSocket("ws://localhost:14370");-- socket.onopen = () => {- console.log("WebSocket connection opened");- updateConnectionStatus(true);- startHeartbeat();- };-- socket.onmessage = function(event) {- const message = JSON.parse(event.data);- // console.log("Received message", message.ClientVersion, message.LatestExtensionVersion);- if (message.type === "version") {- // 保存版本信息到 browser.storage.local- browser.storage.local.set({ ClientVersion: message.ClientVersion }, function() {- // console.log("ClientVersion stored:", message.ClientVersion);- });- browser.storage.local.set({ LatestExtensionVersion: message.LatestExtensionVersion }, function() {- // console.log("LatestExtensionVersion stored:", message.LatestExtensionVersion);- });- } else {- console.log("Received message:", event.data);- }- };-- socket.onerror = (error) => {- console.log("WebSocket error: ", error);- updateConnectionStatus(false);- stopHeartbeat(); // 关闭连接时停止心跳- };-- socket.onclose = () => {- console.log("WebSocket connection closed, retrying in 2500 microseconds");- updateConnectionStatus(false);- if (!shouldDisableExtension) {- setTimeout(connectWebSocket, 2500);- }- stopHeartbeat(); // 关闭连接时停止心跳- };- } catch (e) {- console.log("Exception in WebSocket connection: ", e);- setTimeout(connectWebSocket, 2500);- }-}--// 更新连接状态并更新扩展状态和徽章-function updateConnectionStatus(connected) {- isConnected = connected;- updateBadge(connected ? "connected" : "disconnected");- updateStatus(connected);-}--// 更新扩展图标徽章-function updateBadge(status) {- const badgeColor = (status === "connected") ? "green" : "pink";- const badgeText = (status === "connected") ? "√" : "×";- browser.browserAction.setBadgeBackgroundColor({ color: badgeColor });- browser.browserAction.setBadgeText({ text: badgeText });--}--// 更新扩展状态-function updateStatus(connected) {- browser.storage.local.set({ isConnected: connected }, () => {- console.log(`Status updated: ${connected ? "Connected" : "Disconnected"}`);- });-}--// 启动心跳机制-function startHeartbeat() {- if (!heartbeatInterval) { // 检查是否已有定时器- heartbeatInterval = setInterval(() => {- if (socket.readyState === WebSocket.OPEN) {- try {- socket.send(JSON.stringify({ type: 'heartbeat', timestamp: Date.now() }));- console.log("Heartbeat sent");- } catch (error) {- console.error("Error sending heartbeat:", error); // 仅记录错误,不影响执行- }- }- }, 5000); // 每5秒发送一次心跳- }-}--// 停止心跳机制-function stopHeartbeat() {- if (heartbeatInterval) {- clearInterval(heartbeatInterval); // 清除定时器- heartbeatInterval = null; // 重置定时器变量- }-}--// 根据浏览器类型添加不同的下载事件监听器, 监听下载开始事件并阻止下载-browser.downloads.onCreated.addListener((downloadItem) => {- if (downloadItem.state === "in_progress") {- browser.storage.local.get(["shouldDisableExtension"], (result) => {- if (!result.shouldDisableExtension && isConnected && socket.readyState === WebSocket.OPEN) {- console.log("Download started: ", downloadItem);- if (downloadItem.url.startsWith("http")) {- browser.downloads.cancel(downloadItem.id);- browser.downloads.erase({id: downloadItem.id})--- // 从映射表中获取对应的请求头- const requestHeaders = requestHeadersMap.get(downloadItem.url) || {};-- console.log(downloadItem.fileSize)-- // 构造完整的请求信息- const requestInfo = {- url: downloadItem.url,- filename: downloadItem.filename.replaceAll("\\", "/").split('/').pop(),- referer: downloadItem.referrer || "",- headers: requestHeaders,- };-- console.log("捕获到的下载请求信息:", requestInfo);-- // 将请求信息发送到 WebSocket- sendDownloadInfo(requestInfo);-- // 清空 requestHeadersMap- requestHeadersMap.clear();- }- }- });- }-})--let requestHeadersMap = new Map(); // 存储请求头信息的映射表--// 监听 onBeforeSendHeaders 事件,捕获请求头信息并转为字典形式-browser.webRequest.onBeforeSendHeaders.addListener(- (details) => {- // 将请求头数组转换为字典(键值对形式)- const requestHeadersDict = details.requestHeaders.reduce((acc, header) => {- acc[header.name.toLowerCase()] = header.value;- return acc;- }, {});-- // 存储请求头信息到映射表中,以请求 ID 为键- requestHeadersMap.set(details.url, requestHeadersDict);- console.log("Details url:", details.url);- },- {- urls: ["<all_urls>"], // 监听所有请求- types: ["main_frame", "sub_frame", "xmlhttprequest", "other"], // 资源类型- },- typeof browser !== 'undefined' ? ["requestHeaders"] : ["requestHeaders", "extraHeaders"] // 根据浏览器类型添加不同的参数-);--// 修改 sendDownloadInfo 函数,将请求信息发送到 WebSocket-function sendDownloadInfo(requestInfo) {- if (isConnected && socket.readyState === WebSocket.OPEN) {- try {- socket.send(JSON.stringify(requestInfo));- } catch (error) {- console.error("发送下载信息时发生错误:", error);- }- } else {- console.error("WebSocket 未连接");- }-}---// 启动 WebSocket 连接-connectWebSocket();--// 在扩展启动时检查禁用状态-browser.storage.local.get(["shouldDisableExtension"], (result) => {- shouldDisableExtension = result.shouldDisableExtension || false;- console.log("Extension disable status:", shouldDisableExtension);-});diff --git a/firefox_extension/icon128.png b/firefox_extension/icon128.pngdeleted file mode 100644index 12063d98..00000000Binary files a/firefox_extension/icon128.png and /dev/null differdiff --git a/firefox_extension/icon16.png b/firefox_extension/icon16.pngdeleted file mode 100644index c1fb192d..00000000Binary files a/firefox_extension/icon16.png and /dev/null differdiff --git a/firefox_extension/icon48.png b/firefox_extension/icon48.pngdeleted file mode 100644index 31191227..00000000Binary files a/firefox_extension/icon48.png and /dev/null differdiff --git a/firefox_extension/manifest.json b/firefox_extension/manifest.jsondeleted file mode 100644index 733253df..00000000--- a/firefox_extension/manifest.json+++ /dev/null@@ -1,37 +0,0 @@-{- "name": "Ghost Downloader Browser Extension",- "version": "1.1.2",- "manifest_version": 2,- "description": "Ghost Downloader 的浏览器辅助插件,用于捕获浏览器下载任务.",- "background": {- "scripts": [- "background.js"- ],- "persistent": true- },- "browser_action": {- "default_popup": "popup.html",- "default_icon": {- "16": "icon16.png",- "48": "icon48.png",- "128": "icon128.png"- },- "default_title": "Ghost Downloader Browser Extension"- },- "icons": {- "16": "icon16.png",- "48": "icon48.png",- "128": "icon128.png"- },- "permissions": [- "downloads",- "webRequest",- "activeTab",- "storage"- ],- "browser_specific_settings": {- "gecko": {- "id": "[email protected]"- }- }-}\ No newline at end of filediff --git a/firefox_extension/popup.html b/firefox_extension/popup.htmldeleted file mode 100644index e5898be3..00000000--- a/firefox_extension/popup.html+++ /dev/null@@ -1,93 +0,0 @@-<!DOCTYPE html>-<html lang="zh">-<head>- <meta charset="UTF-8">- <meta name="viewport" content="width=device-width, initial-scale=1.0">- <title>Ghost Downloader Browser Extension</title>- <style>- body {- font-family: "Segoe UI", Tahoma, Geneva, sans-serif;- width: 250px;- margin: 0;- padding: 20px;- background-color: #f4f4f4;- border-radius: 8px;- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);- transition: background-color 0.3s, transform 0.2s;- }- body:hover {- background-color: #e9e9e9;- transform: translateY(-1px);- }- #status {- margin-bottom: 5px;- font-size: 16px;- color: #333;- }- #version {- font-size: 14px;- color: #666;- margin-top: 5px;- margin-bottom: 5px;- }- button {- padding: 12px;- border: none;- border-radius: 4px;- width: 100%;- cursor: pointer;- transition: background-color 0.3s, transform 0.2s;- font-size: 16px;- font-weight: bold;- }- #enable-button {- background-color: #ff4c4c;- color: white;- }- #enable-button:hover {- background-color: #ff0000;- transform: scale(1.02);- }- #disable-button {- background-color: #4caf50;- color: white;- display: none; /* Initially hidden */- }- #disable-button:hover {- background-color: #45a049;- transform: scale(1.02);- }- /* 添加深色模式样式 */- body.dark-mode {- background-color: #333;- color: #fff;- }- body.dark-mode:hover {- background-color: #444;- }- body.dark-mode #status {- color: #ccc;- }- body.dark-mode #version {- color: #aaa;- }- body.dark-mode button {- color: white;- }- body.dark-mode #enable-button {- background-color: #ff4c4c;- }- body.dark-mode #disable-button {- background-color: #4caf50;- }- </style>-</head>-<body>-<div id="status">状态: <span id="status-text">正在尝试连接...</span></div>-<div id="version"></div>-<button id="enable-button">插件已禁用</button>-<button id="disable-button">插件已启用</button>--<script src="popup.js"></script>-</body>-</html>\ No newline at end of filediff --git a/firefox_extension/popup.js b/firefox_extension/popup.jsdeleted file mode 100644index 947630a1..00000000--- a/firefox_extension/popup.js+++ /dev/null@@ -1,94 +0,0 @@-// popup.js--// 获取状态元素和禁用按钮-const statusText = document.getElementById("status-text");-const disableButton = document.getElementById("disable-button");-const enableButton = document.getElementById("enable-button");--// 更新状态文本-function updateStatus() {- browser.storage.local.get("isConnected", (data) => {- statusText.textContent = data.isConnected ? "连接成功" : "连接已断开";- });-- // 检查禁用状态- browser.storage.local.get("shouldDisableExtension", (result) => {- if (result.shouldDisableExtension) {- disableButton.style.display = "none";- enableButton.style.display = "block";- } else {- disableButton.style.display = "block";- enableButton.style.display = "none";- }- });-}--// 添加禁用按钮点击事件监听器-disableButton.addEventListener("click", () => {- browser.storage.local.set({ shouldDisableExtension: true }, () => {- console.log("Extension disabled.");- updateStatus();- });-});--// 添加启用按钮点击事件监听器-enableButton.addEventListener("click", () => {- browser.storage.local.set({ shouldDisableExtension: false }, () => {- console.log("Extension enabled.");- updateStatus();- });-});--// 监听存储变化-browser.storage.onChanged.addListener((changes, areaName) => {- if (areaName === 'local' && changes.isConnected) {- updateStatus(); // 当 isConnected 发生变化时,更新状态- }-});--function isVersionNewer(v1, v2) {- const parts1 = v1.split('.').map(Number);- const parts2 = v2.split('.').map(Number);-- for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {- const num1 = parts1[i] || 0;- const num2 = parts2[i] || 0;- if (num1 !== num2) {- return num1 > num2; // 如果 v1 更新,返回 true- }- }- return false;-}--// 打印插件版本到插件页面-// 打印插件版本到插件页面-document.addEventListener('DOMContentLoaded', () => {-- const ExtensionVersion = browser.runtime.getManifest().version;-- // 获取客户端版本和最新插件版本- browser.storage.local.get(["ClientVersion", "LatestExtensionVersion"], (result) => {- const ClientVersion = result.ClientVersion || "Unknown";- const LatestExtensionVersion = result.LatestExtensionVersion || "Unknown";- // console.log(ExtensionVersion, ClientVersion, LatestExtensionVersion);-- if (isVersionNewer(LatestExtensionVersion, ExtensionVersion)) {- document.getElementById('version').innerHTML = `插件版本: ${ExtensionVersion}  客户端版本: ${ClientVersion}<br/><span style="color: palevioletred;">插件有新版本,请前往客户端手动更新!</span>`;- } else {- document.getElementById('version').innerHTML = `插件版本: ${ExtensionVersion}  客户端版本: ${ClientVersion}`;- }- });-- // 检测系统颜色模式并在初始时设置- if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {- document.body.classList.add('dark-mode');- }-});--// 添加检测系统颜色模式变化的事件监听器-window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (event) => {- document.body.classList.toggle('dark-mode', event.matches);-});--// 更新状态-updateStatus();