1

我正在尝试从 Chrome 扩展程序访问 plug.dj APIAPI.bar() ,但每次我输入它都会给我:

未捕获的 ReferenceError:未定义 API

我使用以下 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
}

任何人都知道我可能做错了什么?还是忘记?

4

1 回答 1

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);
于 2013-08-22T17:22:12.630 回答