我一直在寻找 stackoverflow 和谷歌的答案,但我找不到任何东西......我对 javascript 还是很陌生,所以我有点困惑;
清单.json
{
"manifest_version": 2,
"name": "Twitch Streams List",
"description": "Find all the streams directly through Chrome",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"http://api.twitch.tv/kraken/streams?limit=20"
],
"web_accessible_resources": ["twitch.js"]
}
popup.html
<!doctype html>
<html>
<head>
<title>Getting top streams from Twitch</title>
<style>
body {
min-width: 350px;
}
</style>
<script src="twitch.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
抽搐.js
var streamGenerator = {
/* url where to get the streams from */
url: chrome.extension.getURL('http://api.twitch.tv/kraken/streams?limit=20'),
/* go get the streams from the json at the url given */
requestStreams: function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', this.url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var resp = JSON.parse(xhr.responseText);
}
}
xhr.send();
},
/* import the streams in the html page */
showStreams: function (e) {
var streams = resp.streams;
var output = '<ul>';
for (var i = 0; i < streams.length; i++) {
output += '<li>' + streams[i].channel.display_name + ' - ' + streams[i].channel.viewers + ' - ' + streams[i].channel.game + '</li>';
}
output += '</ul>';
console.log(output);
document.body.appendChild(output);
}
};
/* Run the script as soon as the popup is loaded */
document.addEventListener('DOMContentLoaded', function () {
streamGenerator.requestStreams();
});
弹出窗口中没有任何内容,控制台显示
Failed to load resource chrome-extension://dihpppnflhlpkehcgnjggjcipffmjlgp/http://api.twitch.tv/kraken/streams?limit=20
该怎么办???
谢谢