清单文件:
{
"name": "Paz Dashboard",
"version": "1.0",
"description": "Accompanying extension for Paz Dashboard.",
"permissions": ["topSites", "activeTab"],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["https://paz.yt/dash/*"],
"js": ["bg.js"]
}
],
"manifest_version": 2
}
内容脚本:
function buildPopupDom(mostVisitedURLs) {
var element = document.createElement("div");
document.getElementById('topsites').appendChild(element);
var sites = [];
for (var i = 0; i < mostVisitedURLs.length; i++) {
ii = {};
ii.url = mostVisitedURLs[i].url;
ii.title = mostVisitedURLs[i].title;
sites.push(ii);
}
console.log(ii);
element.innerText = "The chrome extension has succesfully been installed.";
}
chrome.topSites.get(buildPopupDom);
我正在尝试在我的信息中心网站上放置一张卡片,其中包含所有来自chrome的热门网站。它尝试在站点上创建一个元素,然后(不在此代码中)通过链接将顶部站点添加到该元素。当前的脚本仅将最终数组发送到控制台,但是它不能首先获得顶部站点。..这是一个问题。