如何在Firefox插件更改脚本位置? [英] How to change script location on firefox addon?

查看:264
本文介绍了如何在Firefox插件更改脚本位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是让Firefox的插件,它重复这种铬功能最简单的方法:

What is the simplest way to make the firefox addon, which repeats this chrome functionality:

chrome.webRequest.onBeforeRequest.addListener(
  function(info) {
    if(info.url.indexOf("notifier") + 1){
        return {redirectUrl: "https://domain.null/1.js"};
    }

  },
  {
    urls: [
      "*://domain2.null/*"
    ],
    types: ["script"]
  }, ["blocking"]);

我知道的 nsIContentPolicy 在Firefox,但我不知道如何使用它。

I know about nsIContentPolicy in firefox, but I don't understand how to use it.

所有的意见,建议和帮助将AP preciated

All opinions, advice, and help will be appreciated

我已经决定与扩展无需重启问题。结果
要阻止内容弗拉基米尔说,我们可以使用nsIContentPolicy。我们也可以用的WindowListener (aWindow.gBrowser)注入脚本页面。

I've determined the problem with the restartless extension.
To block content we can use nsIContentPolicy as Wladimir said. We also can inject script to page with windowListener (aWindow.gBrowser).

例如,这种做法完美的作品:的https://github.com/jvillalobos/AMO-Admin-Assistant/blob/master/src/bootstrap.js

For example, this practice works perfectly: https://github.com/jvillalobos/AMO-Admin-Assistant/blob/master/src/bootstrap.js

推荐答案

我不认为这可以没有大的黑客,现在来完成。这是受错误765934 ,将增加一个 redirectTo()方法到<一个href=\"https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIHttpChannel\"><$c$c>nsIHttpChannel接口。一旦它被执行code像这应该工作:

I don't think that this can be done without major hacks right now. This is subject of bug 765934 that will add a redirectTo() method to the nsIHttpChannel interface. Once it is implemented code like this should work:

const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

var observer = {
  QueryInterface: XPCOMUtils.generateQI([
    Ci.nsIObserver,
    Ci.nsISupportsWeakReference
  ]),

  observe: function(subject, topic, data)
  {
    if (topic == "http-on-modify-request" &&
        subject instanceof Ci.nsIHttpChannel)
    {
      var uri = subject.URI;
      if (uri.host == "domain2.null" && /\.js(\?|$)/.test(uri.path))
      {
        var redirectUri = Services.io.newURI("https://domain.null/1.js",
                                             null, null);
        subject.redirectTo(redirectUri);
      }
    }
  }
};

Services.obs.addObserver(observer, "http-on-modify-request", true);

有关引用:<一href=\"https://developer.mozilla.org/en-US/docs/JavaScript_$c$c_modules/Services.jsm\">Services.jsm, <一href=\"https://developer.mozilla.org/en-US/docs/JavaScript_$c$c_modules/XPCOMUtils.jsm\">XPCOMUtils.jsm, 观察者通知中,<一个href=\"https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIHttpChannel\">nsIHttpChannel, nsIURI

For reference: Services.jsm, XPCOMUtils.jsm, observer notifications, nsIHttpChannel, nsIURI

这篇关于如何在Firefox插件更改脚本位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆