Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 扩展can';我找不到课_Javascript_Jquery_Api_Last.fm - Fatal编程技术网

Javascript 扩展can';我找不到课

Javascript 扩展can';我找不到课,javascript,jquery,api,last.fm,Javascript,Jquery,Api,Last.fm,我正在尝试使用last.fm&plug.dj API制作一个chrome扩展,它一直在工作,直到我开始将脚本嵌入扩展中,然后我无法连接到这两个插件。这是安装脚本: function Setup(){ console.log('Setup'); API.addEventListener(API.DJ_ADVANCE, callback); cache = new LastFMCache(); lastfm = new LastFM({ apiKey:

我正在尝试使用last.fm&plug.dj API制作一个chrome扩展,它一直在工作,直到我开始将脚本嵌入扩展中,然后我无法连接到这两个插件。这是安装脚本:

function Setup(){
    console.log('Setup');
    API.addEventListener(API.DJ_ADVANCE, callback);
    cache = new LastFMCache();
    lastfm = new LastFM({
        apiKey: '<key>',
        apiSecret: '<secret>',
        cache: cache
    });
}
它在新的LastFMCache()和脚本中访问其他API的其他地方出错。加载其他脚本(如lastFMLink.js和lastFMLink.css),关键是事件侦听器可以工作

当按下一个按钮时,安装脚本会被加载,并且它还没有初始化,所以通常不会因为脚本顺序而出错


有人知道哪里出了问题吗?

这可能不是最好的选择,但我发现它不起作用的原因是内容脚本在后台运行,并且彼此之间没有访问权限

因此,我将manifest.json更改为:

{
   "content_scripts": [ {
      "js": ["script.js"],
      "css": [ "LastFMLink.css" ],
      "matches": [ "http://plug.dj/*", "http://plug.dj/*/*" ],
      "run_at": "document_end"
   } ],

   "name": "Plug.Dj VS last.Fm",
   "description": "Implement information about the artist",
   "icons": { "16": "cookie.png", "48": "cookie.png", "128": "cookie.png" },
   "permissions": [ "http://plug.dj/*", "http://plug.dj/*/*" ],
   "version": "0.0.1",
   "web_accessible_resources": [ "jquery.js","lastfm.api.md5.js", "lastfm.api.cache.js", "lastfm.api.js","lastFMLink.js","script.js"],
   "manifest_version": 2
}
然后我只需加载脚本,我确信这不是实现的方法,但它现在可以工作,但这就是我加载last.fm脚本的方式(在script.js中):

{
   "content_scripts": [ {
      "js": ["script.js"],
      "css": [ "LastFMLink.css" ],
      "matches": [ "http://plug.dj/*", "http://plug.dj/*/*" ],
      "run_at": "document_end"
   } ],

   "name": "Plug.Dj VS last.Fm",
   "description": "Implement information about the artist",
   "icons": { "16": "cookie.png", "48": "cookie.png", "128": "cookie.png" },
   "permissions": [ "http://plug.dj/*", "http://plug.dj/*/*" ],
   "version": "0.0.1",
   "web_accessible_resources": [ "jquery.js","lastfm.api.md5.js", "lastfm.api.cache.js", "lastfm.api.js","lastFMLink.js","script.js"],
   "manifest_version": 2
}
var s = document.createElement('script');
s.src = chrome.extension.getURL("lastFMLink.js");
var s2 = document.createElement('script');
s2.src = chrome.extension.getURL("lastfm.api.md5.js");
var s3 = document.createElement('script');
s3.src = chrome.extension.getURL("lastfm.api.cache.js");
var s4 = document.createElement('script');
s4.src = chrome.extension.getURL("lastfm.api.js");

s.onload = function() {
    this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
(document.head||document.documentElement).appendChild(s2);
(document.head||document.documentElement).appendChild(s3);
(document.head||document.documentElement).appendChild(s4);