Google chrome extension 谷歌浏览器扩展没有显示任何数据。
这是我的manifest.json:Google chrome extension 谷歌浏览器扩展没有显示任何数据。,google-chrome-extension,Google Chrome Extension,这是我的manifest.json: { "name": "Chritter", "version": "1.0", "description": "A Twitter button for your toolbar.", "icons": {"128": "icon.png"}, "browser_action": { "default_icon": "icon.png", "default_t
{
"name": "Chritter",
"version": "1.0",
"description": "A Twitter button for your toolbar.",
"icons": {"128": "icon.png"},
"browser_action": {
"default_icon": "icon.png",
"default_title": "Chritter",
"popup": "popup.html"
},
"permissions": ["http://twitter.com/*", "tabs"]
}
This is my popup.html:
<html>
<head>
<script>
onload = setTimeout(init, 0); // workaround for http://crbug.com/24467
// initialize timeline template
function init() {
timeline = document.getElementById('timeline');
template = xpath('//ol[@id="template"]/li', document);
link = xpath('//div[@class="thumbnail"]/a', template);
image = xpath('img', link);
author = xpath('//div[@class="text"]/a', template);
content = xpath('//div[@class="text"]/span', template);
getTweets();
}
function getTweets() {
req = new XMLHttpRequest();
req.open('GET', 'http://twitter.com/statuses/public_timeline.json');
req.onload = processTweets;
req.send();
}
// process new batch of tweets
function processTweets() {
var res = JSON.parse(req.responseText);
tweets = res.concat(tweets);
update();
}
for (var i in tweets) {
user = tweets[i].user;
url = 'http://twitter.com/' + user.screen_name;
// thumbnail
link.title = user.name;
link.href = openInNewTab(url);
image.src = user.profile_image_url;
image.alt = user.name;
// text
author.href = openInNewTab(url);
author.innerHTML = user.name;
content.innerHTML = linkify(tweets[i].text);
// copy node and update
item = template.cloneNode(true);
timeline.appendChild(item);
}
</script>
</head>
<body>
<div id="body">
<div id="title">
<h2>Chritter</h2>
</div>
<ol id="timeline" />
</div>
<ol id="template">
<li>
<div class="thumbnail">
<a>
<img />
</a>
</div>
<div class="text">
<a></a>
<span></span>
</div>
<div class="clear"></div>
</li>
</ol>
</body>
</html>
{
“名称”:“Chritter”,
“版本”:“1.0”,
“说明”:“用于工具栏的Twitter按钮。”,
“icons”:{“128”:“icon.png”},
“浏览器操作”:{
“默认图标”:“icon.png”,
“默认标题”:“Chritter”,
“popup”:“popup.html”
},
“权限”:[“http://twitter.com/*“,“选项卡”]
}
这是我的popup.html:
onload=setTimeout(init,0);//解决方法http://crbug.com/24467
//初始化时间线模板
函数init(){
timeline=document.getElementById(“timeline”);
template=xpath('//ol[@id=“template”]/li',document);
link=xpath('//div[@class=“缩略图”]/a',模板);
image=xpath('img',link);
author=xpath('//div[@class=“text”]/a',模板);
content=xpath('//div[@class=“text”]/span',模板);
getTweets();
}
函数getTweets(){
req=新的XMLHttpRequest();
请求打开('GET','http://twitter.com/statuses/public_timeline.json');
req.onload=处理tweets;
请求发送();
}
//处理新一批推文
函数processTweets(){
var res=JSON.parse(req.responseText);
tweets=res.concat(tweets);
更新();
}
for(tweets中的var i){
user=tweets[i]。用户;
url='1〕http://twitter.com/'+user.screen_名称;
//缩略图
link.title=user.name;
link.href=openInNewTab(url);
image.src=user.profile\u image\u url;
image.alt=user.name;
//正文
author.href=openInNewTab(url);
author.innerHTML=user.name;
content.innerHTML=linkify(tweets[i].text);
//复制节点并更新
item=模板.克隆节点(true);
时间线。追加子项(项目);
}
克里特
当我点击扩展时,我没有得到任何数据。我做错什么了吗?我应该在popup.js而不是popup.html中编写js吗 脚本中有错误<代码>推文和
xpath
未定义。在脚本开头添加以下内容以修复它:
var tweets,xpath代码>
要在弹出窗口中调试脚本,请单击扩展图标打开弹出窗口,然后在弹出窗口中单击鼠标右键并选择“检查元素”。控制台选项卡将显示错误。您好,您所说的无数据
是什么意思?根本没有弹出窗口?