mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-26 03:00:53 +02:00
6bb818e62a
* Removed innerHTML * Removed innerHTML * Removed innerHTML * Removed innerHTML
32 lines
875 B
JavaScript
32 lines
875 B
JavaScript
// Get the saved stats and render the data in the popup window.
|
|
chrome.storage.local.get("hostNavigationStats", results => {
|
|
if (!results.hostNavigationStats) {
|
|
return;
|
|
}
|
|
|
|
const {hostNavigationStats} = results;
|
|
const sortedHostnames = Object.keys(hostNavigationStats).sort((a, b) => {
|
|
return hostNavigationStats[a] <= hostNavigationStats[b];
|
|
});
|
|
|
|
if (sortedHostnames.length === 0) {
|
|
return;
|
|
}
|
|
|
|
let listEl = document.querySelector("ul");
|
|
while(listEl.firstChild)
|
|
listEl.removeChild(listEl.firstChild);
|
|
|
|
const MAX_ITEMS = 5;
|
|
for (let i=0; i < sortedHostnames.length; i++) {
|
|
if (i >= MAX_ITEMS) {
|
|
break;
|
|
}
|
|
|
|
const listItem = document.createElement("li");
|
|
const hostname = sortedHostnames[i];
|
|
listItem.textContent = `${hostname}: ${hostNavigationStats[hostname]} visit(s)`;
|
|
listEl.appendChild(listItem);
|
|
}
|
|
});
|