Skip to content

The only downloader you need. 下载器的集大成者。

fix(extension): 修复图片嗅探注入后正则丢失 & bump 2.1.2

XiaoYouChR0232fdf4f46c
diff --git a/app/config/constants.py b/app/config/constants.py
index 1440d0a2..5b2a9109 100644
--- a/app/config/constants.py
+++ b/app/config/constants.py
@@ -3,7 +3,7 @@ AUTHOR = "XiaoYouChR"
VERSION = "4.2.0"
DESKTOP_ID = "io.github.xiaoyouchr.GhostDownloader"
DESKTOP_OBJECT_PATH = "/" + DESKTOP_ID.replace(".", "/")
-LATEST_EXTENSION_VERSION = "2.1.1"
+LATEST_EXTENSION_VERSION = "2.1.2"
AUTHOR_URL = "https://space.bilibili.com/437313511"
FEEDBACK_URL = "https://github.com/XiaoYouChR/Ghost-Downloader-3/issues"
FIREFOX_ADDONS_URL = "https://addons.mozilla.org/zh-CN/firefox/addon/ghost-downloader/"
diff --git a/browser_extension/app/package.json b/browser_extension/app/package.json
index 3b99410e..08219d4f 100644
--- a/browser_extension/app/package.json
+++ b/browser_extension/app/package.json
@@ -1,7 +1,7 @@
{
"name": "ghost-downloader-browser-extension",
"private": true,
- "version": "2.1.1",
+ "version": "2.1.2",
"type": "module",
"scripts": {
"build": "node ./scripts/build.mjs",
diff --git a/browser_extension/app/public/manifest.json b/browser_extension/app/public/manifest.json
index 93dfd8d3..b93cd62b 100644
--- a/browser_extension/app/public/manifest.json
+++ b/browser_extension/app/public/manifest.json
@@ -3,7 +3,7 @@
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"default_locale": "en",
- "version": "2.1.1",
+ "version": "2.1.2",
"permissions": [
"alarms",
"contextMenus",
diff --git a/browser_extension/app/src/popup/scan-images.ts b/browser_extension/app/src/popup/scan-images.ts
index 246d33d5..8967d4e8 100644
--- a/browser_extension/app/src/popup/scan-images.ts
+++ b/browser_extension/app/src/popup/scan-images.ts
@@ -2,10 +2,6 @@ import type {ScannedImage} from "../shared/types";
const IMAGE_REFERER_RULE_ID = 9999;
-const IMAGE_EXT_RE = /\.(png|jpg|jpeg|gif|webp|svg|bmp|ico|avif|heic|tif|tiff|apng|jfif)(\?.*)?$/i;
-const URL_RE = /https?:\/\/[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b[-a-zA-Z0-9@:%_+.~#?&/=]*/gi;
-const BG_URL_RE = /url\(\s*['"]?\s*(\S+?)\s*['"]?\s*\)/i;
-
function scanPageImages(): ScannedImage[] {
const seen = new Set<string>();
const results: ScannedImage[] = [];
@@ -22,22 +18,25 @@ function scanPageImages(): ScannedImage[] {
add(src, img.naturalWidth, img.naturalHeight, img.alt || "");
}
+ const bgUrlRe = /url\(\s*['"]?\s*(\S+?)\s*['"]?\s*\)/i;
const pseudos: (string | null)[] = [null, "::before", "::after"];
for (const el of Array.from(document.querySelectorAll("*"))) {
for (const pseudo of pseudos) {
const bg = getComputedStyle(el, pseudo).getPropertyValue("background-image");
if (bg === "none" || !bg) continue;
- const m = BG_URL_RE.exec(bg);
+ const m = bgUrlRe.exec(bg);
if (m?.[1]) add(m[1], 0, 0, "");
}
}
+ const urlRe = /https?:\/\/[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b[-a-zA-Z0-9@:%_+.~#?&/=]*/gi;
+ const imageExtRe = /\.(png|jpg|jpeg|gif|webp|svg|bmp|ico|avif|heic|tif|tiff|apng|jfif)(\?.*)?$/i;
const html = document.documentElement.outerHTML;
- const urls = html.match(URL_RE);
+ const urls = html.match(urlRe);
if (urls) {
for (const raw of new Set(urls)) {
const cleaned = raw.replace(/&(quot|lt|gt|amp);?$/i, "");
- if (IMAGE_EXT_RE.test(cleaned)) add(cleaned, 0, 0, "");
+ if (imageExtRe.test(cleaned)) add(cleaned, 0, 0, "");
}
}