Firefox SDK页面模式不起作用 [英] Firefox SDK page-mod not working

查看:139
本文介绍了Firefox SDK页面模式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了以下扩展程序: EPUBReader Google翻译。后者是使用Firefox SDK构建的,最初有一个 page-mod include:[*] ,所以它只适用于http和https URL。我把这行改为 include:[*,file:// *,about:*] ,这样它也可以用本地文件和 about:links。



原因是我添加了about:*是因为我想要这个扩展名在我用EPUBReader阅读的epub书籍上。 EPUBReader生成一个类似于about:epubreader?id = 5的URL。问题是,当我双击文字时,谷歌翻译仍然不会翻译任何东西。这很有趣,因为每当我尝试打开一个看起来像about:whatever的假about:URL时,它就会起作用。我的意思是,你可以双击任何单词在错误页面,它会翻译。

我在这里粘贴页面的mod代码片段:

  var workers = [],content_script_arr = []; 
pageMod.PageMod({/ * page * /
include:[*,file:// *,about:*],
contentScriptFile:[data.url (content_script / inject.js)],
contentScriptWhen:ready,
contentStyleFile:data.url(content_script / inject.css),
onAttach: {
array.add(workers,worker);
worker.on('pageshow',function(){array.add(workers,this);});
worker.on 'pagehide',function(){array.remove(workers,this);});
worker.on('detach',function(){array.remove(workers,this);});
content_script_arr.forEach(function(arr){
worker.port.on(arr [0],arr [1]);
});
}
}) ;

帮助任何人

解决方案

您可以从

 包括:/.*/,

它将 page-mod 添加到每个URL中,看看罪魁祸首是在 include 中。如果解决了这个问题,你可以进一步缩小范围。

它应该解决这个问题,因为*只匹配 http ftp https URLS。请参阅 https://developer.mozilla。 org / en-US / Add-ons / SDK / Low-Level_APIs / util_match-pattern#通配符
$ b 也许 inject.js 文件需要包含在一个可公开访问的URL中,然后发送给翻译...


I have installed the following extensions: EPUBReader and Google Translator. The latter is built using Firefox SDK and originally has a page-mod include: ["*"] so it works only on http and https URLs. I modified the line into include: ["*","file://*","about:*"] so that it can also work with local files and "about:" links.

The reason i added "about:*" is because i want this extension to words on epub books that i read with EPUBReader. EPUBReader produces a URL something like this "about:epubreader?id=5". The problem is, Google Translator still won't translate anything when i double click on the words. It is interesting because whenever i try and open a fake "about:" URL that looks like "about:whatever", it works. I mean, you can double click on any word in the error page and it will translate.

I am pasting here the page-mod code snippet:

var workers = [], content_script_arr = [];
pageMod.PageMod({ /* page */
  include: ["*","file://*","about:*"],
  contentScriptFile: [data.url("content_script/inject.js")],
  contentScriptWhen: "ready",
  contentStyleFile : data.url("content_script/inject.css"),
  onAttach: function(worker) {
    array.add(workers, worker);
    worker.on('pageshow', function() { array.add(workers, this); });
    worker.on('pagehide', function() { array.remove(workers, this); });
    worker.on('detach', function() { array.remove(workers, this); });
    content_script_arr.forEach(function (arr) {
      worker.port.on(arr[0], arr[1]);
    });
  }
});

Help anyone??

解决方案

You can start with

include: /.*/,

which adds the page-mod to every single URL, and see if the culprit is in the include. If that fixed the problem, you can narrow it down even further.

It should fix the problem, because "*" only matches http, ftp and https URLS. See https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/util_match-pattern#Wildcards.

But maybe the inject.js file needs to be included in a publicly-accessible URL, which then gets sent to the translator...

这篇关于Firefox SDK页面模式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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