Firefox 插件开发:检测不兼容的插件?

发布于 2024-08-11 07:22:29 字数 49 浏览 4 评论 0原文

很少有插件与我的插件不兼容,那么如何检测它们的存在并通知用户。

谢谢

Few addons are not compatible with mine, so how to detect their presence and inform the user.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心欲静而疯不止 2024-08-18 07:22:29

好的,明白了,这是如何完成的:

  function isExtEnabled(){

    if(!Application.extensions.has('EXTENSION_ID_HERE')) {

      return false;
    }
    return true;
  }

OK got it here is how this is done :

  function isExtEnabled(){

    if(!Application.extensions.has('EXTENSION_ID_HERE')) {

      return false;
    }
    return true;
  }
彩扇题诗 2024-08-18 07:22:29

这是来自邪恶的 noscript-1.9.2.xpi 的示例,它修改了 adblock 插件设置

function MRD(ns) {
  this.enabled = ns.getPref("mrd", true);
  if (!this.enabled) return;

  var c = CC[this.id];
  if (c) {
    this.ns = ns;
    this.c = c.createInstance().wrappedJSObject;
    this._w._mrd = this;
    var eh = this.c["elemhide"];
    eh.watch("url", this._w);
    eh.apply();
    ns.mrd = this;
    ns.initContentPolicy();
  } else this.enabled = false;
}  
MRD.prototype = {
  id: "@mozilla.org/adblockplus;1",
  _nobind: "{-moz-binding: none !important}",
  _ms: null,
  _w: function(p, o, n) {
    if (!n) return n;
    var mrd = arguments.callee._mrd;
    var u = decodeURIComponent(n.spec);

    var mm = u.match(/@-moz-document\s+domain[^\)]*?(?:(?:noscript|flashgot|hackademix)\.net|informaction\.com|googlesyndication\.com)[^\}]*\}/g);
    if (mm) {
      var ns = mrd.ns;
      mrd._ms = mm.join('').replace(/(\{[^\{\}]*)\{[^\}]*/g, '$1' + mrd._nobind);
    }

    /*
    var uu = n.spec.split(',');
    uu[1] = encodeURIComponent(decodeURIComponent(uu[1]).replace(/@-moz-document\s+domain[^\)]*?(?:(?:noscript|flashgot|hackademix)\.net|informaction\.com|googlesyndication\.com)[^\}]*\}/g, ''));
    n.spec = uu.join(',');
    */
    mrd.ns.delayExec(function() { mrd.apply(); }, 0);
    return n;
  },
  _dd: function(a, s) {
    return "@-moz-document domain(" + a.join("),domain(") + "){" + s + "} ";
  },

  get _def() {
    delete this.__proto__._def;
    return this.__proto__._def = this.ns.prefService.getDefaultBranch(this.ns.prefs.root).getCharPref("default");
  },
  get _wl() {
    delete this.__proto__._wl;
    return this.__proto__._wl = this._def.match(/\w+[^r].\.n\w+|in\w+on\.c\w+/g).concat(this.ns.getPref("xblHack", "").split(/\s+/));
  },
  get _wlrx() {
    delete this.__proto__._wlrx;
    return this.__proto__._wlrx = new RegExp("^(?:[\\w\\-\\.]*\\.)?(?:" + this._wl.join("|").replace(/\./g, "\\.").concat(")$"));
  },
  get _es() {
    delete this.__proto__._es;
    try {
      var ss = [], lastS = '';
      for(var j = 0; j < 5; j++) {
        ss.push(lastS += " #k" + j);
      }
      es = this._dd(this._wl, ss.join(' *,') + ' *' + this._nobind) +
           this._dd(this._def.match(/\w+[^r].\.n\w+|\w+on\.c\w+/g), "#a\u0064s, #\u0061ds .ad" + this._nobind);
    } catch (e) {
      if (this.ns.consoleDump) this.ns.dump("MRD ES Error: " + e);
    }
    return this.__proto__._es = es;
  },

  apply: function() {
    var ns = this.ns; 
    for each(var s in [this._es, this._ms]){
      if (s) {
        ns.updateStyleSheet(s, false);
        ns.updateStyleSheet(s, true);
      }
    }
  },

  attach: function() {
    if (!this.enabled) return false;
    try {
      var p = this.c.policy;
      var ns = this.ns;
      var wlrx = this._wlrx;
      if (!wlrx) return false;
      ns._mrd_shouldLoad = ns.shouldLoad;
      ns.shouldLoad = function(ct, cl, ro, ctx, mm, internal) {
        if (!internal) try {
          var w = ctx && (ctx.defaultView || ctx.ownerDocument && ctx.ownerDocument.defaultView || ctx);
          if (w) {
            l = w.top.location;
            if (!(/^https?/.test(l.protocol) && wlrx.test(l.hostname))) {
              var res = p.shouldLoad(ct, cl, ro, ctx, mm, internal);
              if (res != CP_OK) return res;
            }
          }
        } catch(e) {
          if (ns.consoleDump) ns.dump(e);
        }
        return ns._mrd_shouldLoad(ct, cl, ro, ctx, mm, internal);
      };
    } catch(e) {
      if (this.ns.consoleDump) this.ns.dump("MRD Attach Error: " + e);
      return false;
    }
    return true;
  }
}

Here is an example from the evil noscript-1.9.2.xpi which modified adblock plugin settings

function MRD(ns) {
  this.enabled = ns.getPref("mrd", true);
  if (!this.enabled) return;

  var c = CC[this.id];
  if (c) {
    this.ns = ns;
    this.c = c.createInstance().wrappedJSObject;
    this._w._mrd = this;
    var eh = this.c["elemhide"];
    eh.watch("url", this._w);
    eh.apply();
    ns.mrd = this;
    ns.initContentPolicy();
  } else this.enabled = false;
}  
MRD.prototype = {
  id: "@mozilla.org/adblockplus;1",
  _nobind: "{-moz-binding: none !important}",
  _ms: null,
  _w: function(p, o, n) {
    if (!n) return n;
    var mrd = arguments.callee._mrd;
    var u = decodeURIComponent(n.spec);

    var mm = u.match(/@-moz-document\s+domain[^\)]*?(?:(?:noscript|flashgot|hackademix)\.net|informaction\.com|googlesyndication\.com)[^\}]*\}/g);
    if (mm) {
      var ns = mrd.ns;
      mrd._ms = mm.join('').replace(/(\{[^\{\}]*)\{[^\}]*/g, '$1' + mrd._nobind);
    }

    /*
    var uu = n.spec.split(',');
    uu[1] = encodeURIComponent(decodeURIComponent(uu[1]).replace(/@-moz-document\s+domain[^\)]*?(?:(?:noscript|flashgot|hackademix)\.net|informaction\.com|googlesyndication\.com)[^\}]*\}/g, ''));
    n.spec = uu.join(',');
    */
    mrd.ns.delayExec(function() { mrd.apply(); }, 0);
    return n;
  },
  _dd: function(a, s) {
    return "@-moz-document domain(" + a.join("),domain(") + "){" + s + "} ";
  },

  get _def() {
    delete this.__proto__._def;
    return this.__proto__._def = this.ns.prefService.getDefaultBranch(this.ns.prefs.root).getCharPref("default");
  },
  get _wl() {
    delete this.__proto__._wl;
    return this.__proto__._wl = this._def.match(/\w+[^r].\.n\w+|in\w+on\.c\w+/g).concat(this.ns.getPref("xblHack", "").split(/\s+/));
  },
  get _wlrx() {
    delete this.__proto__._wlrx;
    return this.__proto__._wlrx = new RegExp("^(?:[\\w\\-\\.]*\\.)?(?:" + this._wl.join("|").replace(/\./g, "\\.").concat(")$"));
  },
  get _es() {
    delete this.__proto__._es;
    try {
      var ss = [], lastS = '';
      for(var j = 0; j < 5; j++) {
        ss.push(lastS += " #k" + j);
      }
      es = this._dd(this._wl, ss.join(' *,') + ' *' + this._nobind) +
           this._dd(this._def.match(/\w+[^r].\.n\w+|\w+on\.c\w+/g), "#a\u0064s, #\u0061ds .ad" + this._nobind);
    } catch (e) {
      if (this.ns.consoleDump) this.ns.dump("MRD ES Error: " + e);
    }
    return this.__proto__._es = es;
  },

  apply: function() {
    var ns = this.ns; 
    for each(var s in [this._es, this._ms]){
      if (s) {
        ns.updateStyleSheet(s, false);
        ns.updateStyleSheet(s, true);
      }
    }
  },

  attach: function() {
    if (!this.enabled) return false;
    try {
      var p = this.c.policy;
      var ns = this.ns;
      var wlrx = this._wlrx;
      if (!wlrx) return false;
      ns._mrd_shouldLoad = ns.shouldLoad;
      ns.shouldLoad = function(ct, cl, ro, ctx, mm, internal) {
        if (!internal) try {
          var w = ctx && (ctx.defaultView || ctx.ownerDocument && ctx.ownerDocument.defaultView || ctx);
          if (w) {
            l = w.top.location;
            if (!(/^https?/.test(l.protocol) && wlrx.test(l.hostname))) {
              var res = p.shouldLoad(ct, cl, ro, ctx, mm, internal);
              if (res != CP_OK) return res;
            }
          }
        } catch(e) {
          if (ns.consoleDump) ns.dump(e);
        }
        return ns._mrd_shouldLoad(ct, cl, ro, ctx, mm, internal);
      };
    } catch(e) {
      if (this.ns.consoleDump) this.ns.dump("MRD Attach Error: " + e);
      return false;
    }
    return true;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文