2013-02-26 94 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);