1

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

主.js:

pageMod.PageMod({
  include: ["*"],
  contentScriptWhen: 'end',
  contentScriptFile: data.url("MyContent.js"),
  contentScriptOptions: {
    showOptions: true,
    dataUrl: data.url("MyContent.js") // To parse the URL-Path
  }
  });

我的内容.js:

//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

4

0 回答 0