-
Notifications
You must be signed in to change notification settings - Fork 0
/
fonts.js
77 lines (66 loc) · 2.26 KB
/
fonts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
document.addEventListener("DOMContentLoaded", function() {
chrome.storage.sync.get("fonts", function(data) {
const fonts = data.fonts || [];
displayFonts(fonts);
});
document.getElementById("removeFonts").addEventListener("click", () => {
chrome.storage.sync.set({ fonts: [] });
window.location.reload();
});
});
const rtf1 = new Intl.RelativeTimeFormat("en", { style: "short" });
function displayFonts(fonts) {
const fontList = document.getElementById("fontList");
let hoveredFont = undefined;
fontList.innerHTML = "";
if (fonts.length === 0) {
fontList.innerHTML = "<p>No fonts recorded yet.</p>";
} else {
fonts
.sort((a, b) => {
const aDate = new Date(a.packedAt);
const bDate = new Date(b.packedAt);
return bDate - aDate;
})
.forEach(function(fontData) {
const li = document.createElement("li");
li.setAttribute("data-font", fontData.font);
const font = document.createElement("div");
font.classList = "title";
font.style = `font-family: ${fontData.font}, Amulya`;
font.textContent = fontData.instances + "x " + fontData.font;
const href = document.createElement("a");
href.href = fontData.href;
href.id = "href";
href.textContent = fontData.displayHostName;
const date = document.createElement("div");
date.id = "date";
date.textContent =
"last visited: " + new Date(fontData.packedAt).toLocaleString();
li.appendChild(font);
li.appendChild(href);
li.appendChild(date);
fontList.appendChild(li);
});
}
const listItems = document.querySelectorAll("li");
// Add event listeners to each list item
listItems.forEach(function(item) {
item.addEventListener("mouseover", function() {
var title = item.getAttribute("data-font");
listItems.forEach(function(li) {
if (li.getAttribute("data-font") === title) {
li.classList.add("highlight");
} else {
li.classList.remove("highlight");
}
});
});
item.addEventListener("mouseout", function() {
// Remove highlights on mouseout
listItems.forEach(function(li) {
li.classList.remove("highlight");
});
});
});
}