mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-27 13:29:34 +07:00
* Update sample file structure. * Update description * Fix wrong favicon path * Add basic sample * Update README.md * Fix comments
26 lines
919 B
JavaScript
26 lines
919 B
JavaScript
// Event listener for clicks on links in an action popup.
|
|
// Open the link in a new tab of the current window.
|
|
function onAnchorClick(event) {
|
|
chrome.tabs.create({ url: event.target.href });
|
|
return false;
|
|
}
|
|
|
|
// Given an array of URLs, build a DOM list of these URLs in the action popup.
|
|
function buildPopupDom(mostVisitedURLs) {
|
|
const popupDiv = document.getElementById('mostVisited_div');
|
|
const ol = popupDiv.appendChild(document.createElement('ol'));
|
|
|
|
for (let i = 0; i < mostVisitedURLs.length; i++) {
|
|
const li = ol.appendChild(document.createElement('li'));
|
|
const a = li.appendChild(document.createElement('a'));
|
|
a.href = mostVisitedURLs[i].url;
|
|
a.appendChild(document.createTextNode(mostVisitedURLs[i].title));
|
|
a.addEventListener('click', onAnchorClick);
|
|
}
|
|
}
|
|
|
|
window.onload = async () => {
|
|
const mostVisitedURLs = await chrome.topSites.get();
|
|
buildPopupDom(mostVisitedURLs);
|
|
};
|