2013-02-27 30 views
1

我試圖從一個Chrome擴展存取權限的plug.dj API但每次我鍵入API.bar()它給了我:網站的API沒有定義

Uncaught ReferenceError: API is not defined

我用下面的manifest.json

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

任何人都知道我可能會做錯什麼?或忘記?

回答

0

等待網站加載完成。看:

function init() { 
    //Write your code here 
} 
function cinit() { 
    if (typeof API == "object" && API.getVolume() != undefined) { 
     clearInterval(loadClock); 
     init(); 
     return 1; 
    } else { 
     return 0; 
    } 
} 
var loadClock = setInterval(cinit, 500);