2013-02-26 96 views
0

我想使用last.fm & plug.dj API扩展它,直到我开始将脚本嵌入到扩展中,然后发现我无法连接他们都没有。这是安装脚本:扩展找不到类

function Setup(){ 
    console.log('Setup'); 
    API.addEventListener(API.DJ_ADVANCE, callback); 
    cache = new LastFMCache(); 
    lastfm = new LastFM({ 
     apiKey: '<key>', 
     apiSecret: '<secret>', 
     cache: cache 
    }); 
} 

在我的manifest.json()在我访问其他API脚本以下的新LastFMCache

{ 
    "content_scripts": [ { 
     "js": [ "jquery.js","lastfm.api.md5.js", "lastfm.api.cache.js", "lastfm.api.js","lastFMLink.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": [ "lastFMLink.js"], 
    "manifest_version": 2 
} 

错误以及其他地方。其他脚本被加载(如lastFMLink.js和lastFMLink.css),堰事件是事件监听器的工作

安装脚本get按钮上加载时,它尚未初始化,所以通常它没有错误的脚本顺序。

任何人有任何线索可能会出错?

回答

0

这可能不是最好的选择,但我发现它没有工作的原因是由于content_script在后台运行并且无法访问彼此。

,所以我改变了我的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 
} 

,然后我只需要加载脚本和我deffenitly肯定这是不是做到这一点,但它适用于现在,但现在这是我如何加载我的last.fm脚本(在script.js中):

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);