问题
I have published a add-on in mozilla add-on website, it got rejected because of remote scripts.
lib/Main.js:
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
var _workers = [];
pageMod.PageMod({
include: "some url",
contentScriptWhen: "ready",
contentScriptFile: data.url("./inject.js"),
contentStyleFile: data.url("style.css"),
attachTo: 'top'
});
data/inject.js:
var script = document.createElement('script');
script.type = "text/javascript";
script1.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.body.appendChild(script);
var script2 = document.createElement('script');
script2.type = "text/javascript";
script2.src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js";
document.body.appendChild(script2);
var script3 = document.createElement('script');
script3.type = "text/javascript";
script3.src = "resource://addon-id/addon-name/data/popup.js";
document.body.appendChild(script3);
Please help me to insert these scripts to the web content or insert these scripts locally from my addon. And what is remote script?
回答1:
All the code you use should be reviewable and immutable, google.com being controlled by a suspicious company, is not trustworthy, and can replace jquery.min.js with password/credit card collector, without Mozilla noticing.
To avoid suspicion, copy files required to your plugin's directory, and use them as:
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*.mozilla.org",
contentScriptFile: [data.url("jquery.min.js"),
data.url("jquery-ui.js"),
data.url("popup.js")]
});
See page-mod manual, it has all needed instructions.
来源:https://stackoverflow.com/questions/30504534/how-to-inject-script-locally-in-firefox-add-on