Firefox扩展内容脚本拒绝加载 [英] Firefox extension content script refuses to load

查看:187
本文介绍了Firefox扩展内容脚本拒绝加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地将我的greasemonkey userscript转换成了Chrome扩展,没有任何问题。但最后2天,我有问题,而试图将其转换为Firefox扩展也!我从这里尝试了几个例子,并使用Request / page-mod / ajax的firefox builder网站,但没有任何工作。

main.js:



I successfully converted my greasemonkey userscript to a chrome extension without any problem. But the last 2 days i am having issues while trying to convert it to a firefox extension also! I tried several examples from here and firefox builder website with Request/page-mod/ajax but nothing worked. I am now trying this:

var data = require("self").data;
var tabs = require("tabs");
var Request = require("request").Request;
var pm = require("page-mod").PageMod({
    include: "http://www.example.com/player/*",
    contentScriptFile: [data.url("jquery.js"), data.url("player.js")],
    var replacediv = jQuery("div#box").eq(0).find('td').eq(3); // this is the div where i need to place the info from the "fetchedwebsite.com"
    onAttach: function(worker) {
        Request({
            url: "http://www.fetchedwebsite.com/players/item/4556834",
            onComplete: function (response) {
                worker.port.emit('got-request', response.text);
            }
        }).get();
    }
});



player.js:



player.js:

self.port.on('got-request', function(data) {
  var columns = $('div.columns',data); // Here i want to keep only the div i want from the "fetchedwebsite.com"
  columns.appendTo(replacediv); // And afaik this is to replace the divs
});

请原谅我的误会!我是所有这些jquery / javascript / firefox-addon中的新东西:P
有人可以帮助我,或者指出我正确的方向吗?
对不起,我的英语不好,谢谢了很多!

Please excuse me about any misunderstandings! I am new in all these jquery/javascript/firefox-addon things :P Can someone help me or point me in the correct direction, please? Sorry for my bad English and thanks a lot in advance!

推荐答案

下面这行不属于 main.js

var replacediv = jQuery("div#box").eq(0).find('td').eq(3);

这会导致语法错误,因为您已经将它放在对象文本中间 - if你打开错误控制台(Ctrl-Shift-J),你应该看到这个语法错误。如果你删除该行(或者将其移动到内容脚本的开头?),那么你的代码应该可以正常工作。

This should cause a syntax error because you've put it in the middle of an object literal - if you open Error Console (Ctrl-Shift-J) you should see that syntax error. If you remove that line (or move it to the beginning of the content script?) your code should work fine from the look of it.

这篇关于Firefox扩展内容脚本拒绝加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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