Firefox addon Mozilla Daaon:main.js之间交换变量->;MyContent.js->;MyScripts.js

Firefox addon Mozilla Daaon:main.js之间交换变量->;MyContent.js->;MyScripts.js,firefox-addon,Firefox Addon,我正在编写一个插件,为网站添加功能。 但是我需要在.js之间解析变量 main.js: pageMod.PageMod({ include: ["*"], contentScriptWhen: 'end', contentScriptFile: data.url("MyContent.js"), contentScriptOptions: { showOptions: true, dataUrl: data.url("MyContent.js") // To pa

我正在编写一个插件,为网站添加功能。 但是我需要在.js之间解析变量

main.js:

pageMod.PageMod({
  include: ["*"],
  contentScriptWhen: 'end',
  contentScriptFile: data.url("MyContent.js"),
  contentScriptOptions: {
    showOptions: true,
    dataUrl: data.url("MyContent.js") // To parse the URL-Path
  }
  });
//to read the URL like resource://.....:
var dataUrl=self.options.dataUrl.substring(0,self.options.dataUrl.lastIndexOf("/")+1)
var script = document.createElement("script");
script.type = "text/javascript";
script.src = dataUrl+"scripts.js";
window.document.head.appendChild(script);
MyContent.js:

pageMod.PageMod({
  include: ["*"],
  contentScriptWhen: 'end',
  contentScriptFile: data.url("MyContent.js"),
  contentScriptOptions: {
    showOptions: true,
    dataUrl: data.url("MyContent.js") // To parse the URL-Path
  }
  });
//to read the URL like resource://.....:
var dataUrl=self.options.dataUrl.substring(0,self.options.dataUrl.lastIndexOf("/")+1)
var script = document.createElement("script");
script.type = "text/javascript";
script.src = dataUrl+"scripts.js";
window.document.head.appendChild(script);
变量dataUrl存在于MyContent.js中,但不存在于MyScripts.js中 我需要MyScripts.js中的变量dataUrl来知道数据文件夹中保存的一些图像的url。 如何定义可以从所有脚本访问的全局变量?
我可以使用worker在main.js和MyContent.js之间进行通信,但不能使用MyScripts.js

Hi@user2215119。您找到解决方案了吗?如果找到,请您分享,以便其他人受益。我也在寻找解决这类问题的方法。