gpt4 book ai didi

firefox - 使用 firefox 插件重定向请求

转载 作者:行者123 更新时间:2023-12-02 03:32:14 24 4
gpt4 key购买 nike

目前我使用addon sdk开发一个 firefox 扩展,它可以重定向一些请求而不加载它们。

例如,一个页面引用 a.js(可能有这样的 <script src='example.com/a.js'> ),然后,我想将此请求重定向到 example2.com/b.js

现在,用nsIContentPolicy我可以屏蔽 example.com/a.js,

但是不知道在a.js被屏蔽的时候如何加载example2.com/b.js。

我的代码现在看起来像这样:

const { Cc, Ci } = require("chrome");
const xpcom = require("sdk/platform/xpcom");
const { Class } = require("sdk/core/heritage");

exports.gcleaner = Class({
extends: xpcom.Unknown,
interfaces: ["nsIContentPolicy"],
shouldLoad: function (contType, contLoc, reqOrig, ctx, typeGuess, extra) {
//https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy#shouldLoad()
if (contType === 2) //2 means js
{
var blockReg = new RegExp('example.com/a.js');
if (contLoc['spec'].match(blockReg))
{
return Ci.nsIContentPolicy.REJECT;
};

};
return Ci.nsIContentPolicy.ACCEPT;
},

shouldProcess: function (contType, contLoc, reqOrig, ctx, mimeType, extra) {
return Ci.nsIContentPolicy.ACCEPT;
}
});

let factory = xpcom.Factory({
Component: exports.gcleaner,
description: "hello world",
contract: "@liujiacai.net/gcleaner"
});

var catman = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
catman.addCategoryEntry("content-policy", "speeding.gcleaner", factory.contract, false, true);

谢谢!

最佳答案

关于firefox - 使用 firefox 插件重定向请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25895903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com