Skip to content

File tree

6 files changed

+78
-20
lines changed

6 files changed

+78
-20
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Displays your bookmarks in multiple columns for quick access from the new tab page.
44

5-
Works in both Chrome and Firefox browsers.
5+
Works in both Chrome and Firefox browsers. Supports light & dark theme based on your operating system theme.
66

77
## Installation
88

@@ -44,6 +44,7 @@ Manually:
4444
## Description
4545

4646
- displays bookmars from Bookmarks Bar
47+
- supports dark mode (based on your operating system theme)
4748
- does NOT manage your bookmarks, use the built-in bookmarks manager for that:
4849
- Chrome: `CMD+ALT+B` / `CTRL+SHIFT+O`
4950
- Firefox: `CMD+SHIFT+O` / `CTRL+SHIFT+O`

chrome/src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "New Tab Page Bookmarks",
33
"description": "Displays your bookmarks in multiple columns for quick access from the new tab page",
4-
"version": "1.8",
4+
"version": "1.9",
55
"manifest_version": 3,
66
"author": "https://github.com/mathio",
77
"chrome_url_overrides": {

firefox/src/manifest.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "New Tab Page Bookmarks",
33
"description": "Displays your bookmarks in multiple columns for quick access from the new tab page",
4-
"version": "1.8",
4+
"version": "1.9",
55
"manifest_version": 2,
66
"author": "https://github.com/mathio",
77
"chrome_url_overrides": {
@@ -13,5 +13,13 @@
1313
"48": "icon48.png",
1414
"128": "icon128.png"
1515
},
16-
"permissions": ["bookmarks"]
16+
"permissions": ["bookmarks"],
17+
"browser_specific_settings": {
18+
"gecko": {
19+
"id": "{4ff4403a-1536-415e-97b9-117f57d67dbf}",
20+
"data_collection_permissions": {
21+
"required": ["none"]
22+
}
23+
}
24+
}
1725
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chrome-new-tab-page-bookmarks",
3-
"version": "1.8.0",
3+
"version": "1.9.0",
44
"main": "index.js",
55
"license": "MIT",
66
"author": "",

src/index.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ body {
99
body {
1010
font-size: 13px;
1111
font-family: sans-serif;
12+
color: #000;
13+
background: #fff;
1214
}
1315
ul#root {
1416
display: flex;
@@ -94,3 +96,30 @@ p#image-attribution a {
9496
background-repeat: no-repeat;
9597
background-position: center;
9698
}
99+
100+
@media (prefers-color-scheme: dark) {
101+
body {
102+
color: #fff;
103+
background: #333;
104+
}
105+
a#toggle {
106+
color: #fff;
107+
background: rgba(50, 50, 50, 0.85);
108+
}
109+
a#toggle:hover {
110+
background: rgba(50, 50, 50, 0.95);
111+
}
112+
ul#root a {
113+
color: #fff;
114+
}
115+
ul#root a:hover {
116+
background: #444;
117+
}
118+
p#image-attribution {
119+
background: rgba(50, 50, 50, 0.85);
120+
color: #e0e0e0;
121+
}
122+
p#image-attribution a {
123+
color: #e0e0e0;
124+
}
125+
}

src/index.js

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const iconUrl = (href) => {
55
return `https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${origin}&size=32`
66
}
77

8-
const addElm = (parent, tag, content, attributes) => {
8+
const addElm = (parent, tag, text, attributes) => {
99
const elm = document.createElement(tag)
10-
if (content) {
11-
elm.innerHTML = content
10+
if (text) {
11+
elm.textContent = text
1212
}
1313
if (attributes) {
1414
Object.entries(attributes).forEach(([key, value]) => {
@@ -34,12 +34,18 @@ const renderNode =
3434
parentUl.className = 'flat-bookmark-structure'
3535
}
3636

37-
const icon = `<img src="${iconUrl(href)}" alt="${title.substring(
38-
0,
39-
1
40-
)}" />`
37+
const link = document.createElement('a')
38+
link.href = href
4139

42-
addElm(li, 'a', `${icon} ${title}`, { href })
40+
const icon = document.createElement('img')
41+
icon.src = iconUrl(href)
42+
icon.alt = title.substring(0, 1)
43+
link.append(icon)
44+
45+
const text = document.createTextNode(` ${title}`)
46+
link.append(text)
47+
48+
li.append(link)
4349
}
4450
}
4551

@@ -95,10 +101,10 @@ const initImage = async () => {
95101
if (!isBookmarksBarHidden()) {
96102
hideImage()
97103
} else {
98-
const image = JSON.parse(
99-
window.localStorage.getItem(IMAGE_KEY_NAME) || '{}'
100-
)
101-
if (image && image.created > Date.now() - IMAGE_VALID_MS) {
104+
let image = JSON.parse(window.localStorage.getItem(IMAGE_KEY_NAME) || '{}')
105+
const hasImage =
106+
image && image.attribution && typeof image.attribution !== 'string'
107+
if (hasImage && image.created > Date.now() - IMAGE_VALID_MS) {
102108
showImage(image)
103109
} else {
104110
const utmParams =
@@ -119,10 +125,13 @@ const initImage = async () => {
119125
.join(' ')
120126
const userLink = `${user?.links?.html}${utmParams}`
121127

122-
const attribution = `Photo by <a href="${userLink}">${userFullName}</a> on <a href="${imageLink}">Unsplash</a>`
123128
const imageData = {
124129
url: imageUrl,
125-
attribution,
130+
attribution: {
131+
userLink,
132+
userFullName,
133+
imageLink,
134+
},
126135
blurhash,
127136
created: Date.now(),
128137
}
@@ -167,7 +176,18 @@ const showImage = ({ url, attribution, blurhash }) => {
167176

168177
const attributionElm = document.createElement('p')
169178
attributionElm.id = 'image-attribution'
170-
attributionElm.innerHTML = attribution
179+
const userLink = document.createElement('a')
180+
userLink.href = attribution.userLink
181+
userLink.textContent = attribution.userFullName
182+
const imageLink = document.createElement('a')
183+
imageLink.href = attribution.imageLink
184+
imageLink.textContent = 'Unsplash'
185+
attributionElm.append(
186+
document.createTextNode('Photo by '),
187+
userLink,
188+
document.createTextNode(' on '),
189+
imageLink
190+
)
171191
document.body.appendChild(attributionElm)
172192
}
173193

0 commit comments

Comments
 (0)