Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【建议】MV3新增Api用于处理Header|重定向|拦截 #288

Open
WhiteSevs opened this issue Jun 18, 2024 · 3 comments
Open

【建议】MV3新增Api用于处理Header|重定向|拦截 #288

WhiteSevs opened this issue Jun 18, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@WhiteSevs
Copy link

类似插件https://he.firefoxcn.net/guide/custom-function#%E5%A6%82%E4%BD%95%E8%B0%83%E8%AF%95%E8%87%AA%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0的功能,但是可自定义更强

  • 修改请求头/响应头,如RefererUser-Agent
  • 重定向链接
  • 拦截链接
interface CAT_headerEditor_Rule {
    /**
     * 匹配规则
     */
    pattern: string | RegExp;
    /**
     * 排除规则
     */
    exclude: string | RegExp;
}
interface CAT_headerEditor_HeaderRule {
    /**
     * 传入Header,修改header
     * @param headers
     * @example
     * (headers)=>{
     *    headers.set("Referer","xxxxxx");
     *    headers.delete("Referer");
     *    headers.set("User-Agent": "xxxx");
     *    return headers;
     * }
     */
    callback: (headers: Headers) => Headers;
}
/**
 * 阻止请求
 */
interface CAT_headerEditor_blockRequest extends CAT_headerEditor_Rule {
    ruleType: "blockRequest";
}
/**
 * 重定向请求
 */
interface CAT_headerEditor_redirectRequest extends CAT_headerEditor_Rule {
    ruleType: "redirectRequest";
    /**
     * 传入完整的url
     * @param url
     * @returns
     * + null|undefined: 跳过
     * + string: 重定向URL
     * + "_header_editor_cancel_": 取消请求
     */
    callback: (
        url: string
    ) => string | null | undefined | "_header_editor_cancel_";
}
/**
 * 修改请求头
 */
interface CAT_headerEditor_modifyRequestHeader
    extends CAT_headerEditor_Rule,
        CAT_headerEditor_HeaderRule {
    ruleType: "modifyRequestHeader";
}
/**
 * 修改响应头
 */
interface CAT_headerEditor_modifyResponseHeader
    extends CAT_headerEditor_Rule,
        CAT_headerEditor_HeaderRule {
    ruleType: "modifyResponseHeader";
}
/**
 * 修改响应体
 * @only firefox
 */
interface CAT_headerEditor_modifyResponseBody extends CAT_headerEditor_Rule {
    ruleType: "modifyResponseBody";
}
/**
 * 所有的规则类型
 */
type CAT_headerEditor_OptionRuleType =
    | CAT_headerEditor_blockRequest["ruleType"]
    | CAT_headerEditor_redirectRequest["ruleType"]
    | CAT_headerEditor_modifyRequestHeader["ruleType"]
    | CAT_headerEditor_modifyResponseHeader["ruleType"]
    | CAT_headerEditor_modifyResponseBody["ruleType"];

/**
 * 配置
 */
interface CAT_headerEditor_Option {
    ruleType: CAT_headerEditor_OptionRuleType;
}

export const CAT_headerEditor = function (option: CAT_headerEditor_Option) {
    // 具体实现
};
@CodFrm CodFrm added the enhancement New feature or request label Jun 20, 2024
@CodFrm
Copy link
Member

CodFrm commented Jun 20, 2024

感觉不错,具体的等mv3重构完成再看看如何设计

@CodFrm CodFrm added this to the Manifest V3之后计划 milestone Jul 9, 2024
@Xdy1579883916
Copy link

v3 响应结果好像改不了

@CodFrm
Copy link
Member

CodFrm commented Jul 30, 2024

响应结果mv2、mv3都改不了的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants