简体   繁体   English

pageMod似乎没有工作

[英]pageMod doesn't seem to be working

I'm currently making a Firefox extension, however I'm unable to get the function to run when I browse to a specific url. 我目前正在进行Firefox扩展,但是当浏览到特定网址时,我无法运行该功能。

In my chrome.manifest I have overlay chrome://browser/content/browser.xul chrome://boxcutter/content/overlay.xul and content/ in the actual filesystem is located at chrome/content/ (I used the extension generator). 在我的chrome.manifest用于我有overlay chrome://browser/content/browser.xul chrome://boxcutter/content/overlay.xulcontent/实际的文件系统位于chrome/content/ (我用的是扩展生成)。

So I assumed that I can then use a script tag in my overlay.xul to reference to my main.js file which contains my pageMod function. 所以,我认为我可以再使用的脚本代码在我overlay.xul引用我main.js其中包含我pageMod功能文件。

My pageMod function is (I've probably stuffed something up here, and its why this isn't working): 我的pageMod函数是(我可能在这里填充了一些东西,以及它为什么不起作用):

(function() {
    var pageMod;
    pageMod = require('page-mod');

    new pageMod.PageMod({
        include: ["http://battlelog.battlefield.com/bf3/*"],
        contentScriptFile: data.url('boxcutter.js')
    });
}).call(this);

This should call my boxcutter.js file when the user goes to Battlelog, however nothing seems to happen. 当用户访问Battlelog时,这应该调用我的boxcutter.js文件,但似乎没有任何事情发生。 At one point I thought it was my JS that I had in boxcutter.js that wasn't working properly however upon adding alert('test'); 有一次,我认为我的JS是我在boxcutter.js中没有正常工作但是添加alert('test'); and refreshing the page, nothing happened. 并刷新页面,没有任何反应。

This lead me to believe that I had done something wrong with my overlay.xul file however I was able to call jQuery functions via Firebug on the Battlelog site (Which I know for a fact does not have the jQuery library, because I checked). 这使我相信,我已经做错了我的overlay.xul文件,但是我能够通过萤火虫在Battlelog网站调用jQuery函数(我知道一个事实,没有jQuery库,因为我选中)。

So I assume its something wrong with my pageMod script (above) that isn't working correctly or that I have done something wrong when I wrote the pageMod script. 因此,我认为我的pageMod脚本(上面)出现了问题,但是我在编写pageMod脚本时工作不正常或者我做错了。

page-mod is a module provided by the Firefox Add-on SDK - this is a framework for building extensions. page-modFirefox Add-on SDK提供的模块 - 这是一个用于构建扩展的框架。 If you don't use that framework (and given that you are talking about chrome manifest and overlays you apparently don't) then you obviously cannot use its features. 如果您不使用该框架(并且鉴于您正在讨论chrome清单和覆盖,您显然没有),那么您显然无法使用其功能。 If you want to stay with classic extensions then you probably want to add a handler for the DOMContentLoaded event in your overlay, check whether the page matches your criteria and do something with it then. 如果您希望继续使用经典扩展,那么您可能希望在叠加层中DOMContentLoaded事件添加处理程序 ,检查页面是否符合您的条件,然后对其执行某些操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM