Skip to content

Commit

Permalink
🐞 fix(修复HttpxCookieManager的规则匹配问题):
Browse files Browse the repository at this point in the history
update @require version
  • Loading branch information
WhiteSevs committed Jun 23, 2024
1 parent 6c5b1e8 commit 18f6a2a
Show file tree
Hide file tree
Showing 51 changed files with 1,208 additions and 493 deletions.
4 changes: 2 additions & 2 deletions packages/CSDN优化/SCRIPT_VERSION.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"time": 1718792750105,
"version": "2024.6.19"
"time": 1719112425327,
"version": "2024.6.23"
}
8 changes: 4 additions & 4 deletions packages/CSDN优化/dist/CSDN优化.min.user.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// ==UserScript==
// @name CSDN优化
// @namespace https://github.com/WhiteSevs/TamperMonkeyScript
// @version 2024.6.19
// @version 2024.6.23
// @author WhiteSevs
// @description 支持手机端和PC端,屏蔽广告,优化浏览体验,自动跳转拦截的URL
// @license GPL-3.0-only
// @icon https://www.csdn.net/favicon.ico
// @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues
// @match *://*.csdn.net/*
// @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js
// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js
// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js
// @require https://fastly.jsdelivr.net/npm/[email protected]/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].2/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].1/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].8/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].2/dist/index.umd.js
// @grant GM_addStyle
// @grant GM_deleteValue
// @grant GM_getValue
Expand Down
8 changes: 4 additions & 4 deletions packages/CSDN优化/dist/CSDN优化.user.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// ==UserScript==
// @name CSDN优化
// @namespace https://github.com/WhiteSevs/TamperMonkeyScript
// @version 2024.6.19
// @version 2024.6.23
// @author WhiteSevs
// @description 支持手机端和PC端,屏蔽广告,优化浏览体验,自动跳转拦截的URL
// @license GPL-3.0-only
// @icon https://www.csdn.net/favicon.ico
// @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues
// @match *://*.csdn.net/*
// @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js
// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js
// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js
// @require https://fastly.jsdelivr.net/npm/[email protected]/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].2/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].1/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].8/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].2/dist/index.umd.js
// @grant GM_addStyle
// @grant GM_cookie
// @grant GM_deleteValue
Expand Down
8 changes: 4 additions & 4 deletions packages/CSDN优化/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"clear": "del .\\SCRIPT_VERSION.json && pnpm store prune"
},
"dependencies": {
"@whitesev/domutils": "^1.1.1",
"@whitesev/utils": "^1.5.2",
"@whitesev/domutils": "^1.1.2",
"@whitesev/utils": "^1.5.8",
"qmsg": "^1.1.2"
},
"devDependencies": {
"@types/node": "^20.14.5",
"typescript": "^5.4.5",
"@types/node": "^20.14.8",
"typescript": "^5.5.2",
"vite": "^5.3.1",
"vite-plugin-monkey": "4.0.3"
}
Expand Down
51 changes: 27 additions & 24 deletions packages/CSDN优化/src/utils/HttpxCookieManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { log, utils } from "@/env";
import { PopsPanel } from "@/setting/setting";
import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx";

interface HttpxCookieManagerRule {
/** PopsPanel存储的键名 */
key: string;
/** 匹配url的hostname的正则或字符串 */
hostname: RegExp | string;
}

export const HttpxCookieManager = {
$data: {
/** 是否启用 */
Expand All @@ -12,14 +19,7 @@ export const HttpxCookieManager = {
get useDocumentCookie() {
return PopsPanel.getValue<boolean>("httpx-use-document-cookie");
},
cookieList: <
{
/** PopsPanel的键名 */
key: string;
/** 域名匹配规则 */
hostname: RegExp;
}[]
>[],
cookieRule: <HttpxCookieManagerRule[]>[],
},
/**
* 补充cookie末尾分号
Expand Down Expand Up @@ -48,11 +48,11 @@ export const HttpxCookieManager = {
},
/**
* 处理cookie
* @param data
* @param details
* @returns
*/
handle(data: Required<HttpxDetails>) {
if (data.fetch) {
handle(details: Required<HttpxDetails>) {
if (details.fetch) {
// fetch不做处理
return;
}
Expand All @@ -63,7 +63,7 @@ export const HttpxCookieManager = {
}
let ownCookie = "";

let url = data.url;
let url = details.url;
// 完善Url
if (url.startsWith("//")) {
url = window.location.protocol + url;
Expand All @@ -78,11 +78,11 @@ export const HttpxCookieManager = {
// 通过document.cookie获取添加
ownCookie = this.concatCookie(ownCookie, document.cookie.trim());
}

this.$data.cookieList.forEach((item) => {
if (item.hostname.test(urlObj.hostname)) {
this.$data.cookieRule.forEach((rule) => {
// 正则不要使用test匹配
if (urlObj.hostname.match(rule.hostname)) {
// 域名匹配成功
let cookie = PopsPanel.getValue(item.key) as string;
let cookie = PopsPanel.getValue(rule.key) as string;
if (utils.isNull(cookie)) {
return;
}
Expand All @@ -91,22 +91,25 @@ export const HttpxCookieManager = {
});

if (utils.isNotNull(ownCookie)) {
if (data.headers && data.headers["Cookie"]) {
data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie);
if (details.headers && details.headers["Cookie"]) {
details.headers.Cookie = this.concatCookie(
details.headers.Cookie,
ownCookie
);
} else {
data.headers["Cookie"] = ownCookie;
details.headers["Cookie"] = ownCookie;
}
log.info(["Httpx => 设置cookie:", data]);
log.info(["Httpx => 设置cookie:", details]);
}

if (
data.headers &&
data.headers.Cookie != null &&
utils.isNull(data.headers.Cookie)
details.headers &&
details.headers.Cookie != null &&
utils.isNull(details.headers.Cookie)
) {
// 有cookie,但是cookie是空的
// 删除该设置
delete data.headers.Cookie;
delete details.headers.Cookie;
}
},
};
4 changes: 2 additions & 2 deletions packages/GreasyFork优化/SCRIPT_VERSION.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"time": 1718792796513,
"version": "2024.6.19"
"time": 1719112475415,
"version": "2024.6.23"
}
8 changes: 4 additions & 4 deletions packages/GreasyFork优化/dist/GreasyFork优化.min.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @name GreasyFork优化
// @name:en-US GreasyFork Optimization
// @namespace https://github.com/WhiteSevs/TamperMonkeyScript
// @version 2024.6.19
// @version 2024.6.23
// @author WhiteSevs
// @description 自动登录账号、快捷寻找自己库被其他脚本引用、更新自己的脚本列表、库、优化图片浏览、美化页面、Markdown复制按钮
// @description:en-US Automatically log in to the account, quickly find your own library referenced by other scripts, update your own script list, library, optimize image browsing, beautify the page, Markdown copy button
Expand All @@ -11,10 +11,10 @@
// @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues
// @match *://greasyfork.org/*
// @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js
// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js
// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js
// @require https://fastly.jsdelivr.net/npm/[email protected]/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].2/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].1/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].8/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].2/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/[email protected]/dist/viewer.min.js
// @require https://fastly.jsdelivr.net/npm/[email protected]/i18next.min.js
// @resource ViewerCSS https://fastly.jsdelivr.net/npm/[email protected]/dist/viewer.min.css
Expand Down
8 changes: 4 additions & 4 deletions packages/GreasyFork优化/dist/GreasyFork优化.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @name GreasyFork优化
// @name:en-US GreasyFork Optimization
// @namespace https://github.com/WhiteSevs/TamperMonkeyScript
// @version 2024.6.19
// @version 2024.6.23
// @author WhiteSevs
// @description 自动登录账号、快捷寻找自己库被其他脚本引用、更新自己的脚本列表、库、优化图片浏览、美化页面、Markdown复制按钮
// @description:en-US Automatically log in to the account, quickly find your own library referenced by other scripts, update your own script list, library, optimize image browsing, beautify the page, Markdown copy button
Expand All @@ -11,10 +11,10 @@
// @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues
// @match *://greasyfork.org/*
// @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js
// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js
// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js
// @require https://fastly.jsdelivr.net/npm/[email protected]/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].2/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].1/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].8/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected].2/dist/index.umd.js
// @require https://fastly.jsdelivr.net/npm/[email protected]/dist/viewer.min.js
// @require https://fastly.jsdelivr.net/npm/[email protected]/i18next.min.js
// @resource ViewerCSS https://fastly.jsdelivr.net/npm/[email protected]/dist/viewer.min.css
Expand Down
8 changes: 4 additions & 4 deletions packages/GreasyFork优化/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"clear": "del .\\SCRIPT_VERSION.json && pnpm store prune"
},
"dependencies": {
"@whitesev/domutils": "^1.1.1",
"@whitesev/utils": "^1.5.2",
"@whitesev/domutils": "^1.1.2",
"@whitesev/utils": "^1.5.8",
"i18next": "^23.11.5",
"qmsg": "^1.1.2"
},
"devDependencies": {
"@types/node": "^20.14.5",
"typescript": "^5.4.5",
"@types/node": "^20.14.8",
"typescript": "^5.5.2",
"vite": "^5.3.1",
"vite-plugin-monkey": "4.0.3"
}
Expand Down
51 changes: 27 additions & 24 deletions packages/GreasyFork优化/src/utils/HttpxCookieManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { log, utils } from "@/env";
import { PopsPanel } from "@/setting/setting";
import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx";

interface HttpxCookieManagerRule {
/** PopsPanel存储的键名 */
key: string;
/** 匹配url的hostname的正则或字符串 */
hostname: RegExp | string;
}

export const HttpxCookieManager = {
$data: {
/** 是否启用 */
Expand All @@ -12,14 +19,7 @@ export const HttpxCookieManager = {
get useDocumentCookie() {
return PopsPanel.getValue<boolean>("httpx-use-document-cookie");
},
cookieList: <
{
/** PopsPanel的键名 */
key: string;
/** 域名匹配规则 */
hostname: RegExp;
}[]
>[],
cookieRule: <HttpxCookieManagerRule[]>[],
},
/**
* 补充cookie末尾分号
Expand Down Expand Up @@ -48,11 +48,11 @@ export const HttpxCookieManager = {
},
/**
* 处理cookie
* @param data
* @param details
* @returns
*/
handle(data: Required<HttpxDetails>) {
if (data.fetch) {
handle(details: Required<HttpxDetails>) {
if (details.fetch) {
// fetch不做处理
return;
}
Expand All @@ -63,7 +63,7 @@ export const HttpxCookieManager = {
}
let ownCookie = "";

let url = data.url;
let url = details.url;
// 完善Url
if (url.startsWith("//")) {
url = window.location.protocol + url;
Expand All @@ -78,11 +78,11 @@ export const HttpxCookieManager = {
// 通过document.cookie获取添加
ownCookie = this.concatCookie(ownCookie, document.cookie.trim());
}

this.$data.cookieList.forEach((item) => {
if (item.hostname.test(urlObj.hostname)) {
this.$data.cookieRule.forEach((rule) => {
// 正则不要使用test匹配
if (urlObj.hostname.match(rule.hostname)) {
// 域名匹配成功
let cookie = PopsPanel.getValue(item.key) as string;
let cookie = PopsPanel.getValue(rule.key) as string;
if (utils.isNull(cookie)) {
return;
}
Expand All @@ -91,22 +91,25 @@ export const HttpxCookieManager = {
});

if (utils.isNotNull(ownCookie)) {
if (data.headers && data.headers["Cookie"]) {
data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie);
if (details.headers && details.headers["Cookie"]) {
details.headers.Cookie = this.concatCookie(
details.headers.Cookie,
ownCookie
);
} else {
data.headers["Cookie"] = ownCookie;
details.headers["Cookie"] = ownCookie;
}
log.info(["Httpx => 设置cookie:", data]);
log.info(["Httpx => 设置cookie:", details]);
}

if (
data.headers &&
data.headers.Cookie != null &&
utils.isNull(data.headers.Cookie)
details.headers &&
details.headers.Cookie != null &&
utils.isNull(details.headers.Cookie)
) {
// 有cookie,但是cookie是空的
// 删除该设置
delete data.headers.Cookie;
delete details.headers.Cookie;
}
},
};
4 changes: 2 additions & 2 deletions packages/demo-vite-typescript/SCRIPT_VERSION.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"time": 1716963436556,
"version": "2024.5.29"
"time": 1719112527603,
"version": "2024.6.23"
}
Loading

0 comments on commit 18f6a2a

Please sign in to comment.