Skip to content

Commit b949004

Browse files
committed
Support Chrome bookmarks sync changes
https://developer.chrome.com/blog/bookmarks-sync-changes Bugfix for latest Firefox Update UI for flat mode (without subfolders in Bookmarks Bar)
1 parent 6cd1b8e commit b949004

File tree

6 files changed

+111
-79
lines changed

6 files changed

+111
-79
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ![icon](https://raw.githubusercontent.com/mathio/chrome-new-tab-page-bookmarks/main/src/icon32.png) New Tab Page Bookmarks
1+
# ![icon](https://raw.githubusercontent.com/mathio/chrome-new-tab-page-bookmarks/main/src/icon32.png) New Tab Page Bookmarks
22

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

@@ -9,55 +9,59 @@ Works in both Chrome and Firefox browsers.
99
### Chrome
1010

1111
From Chrome Web Store:
12+
1213
1. go to [Chrome Web Store](https://chrome.google.com/webstore/detail/new-tab-page-bookmarks/nenadkoihofnhlaokenacmknknmlgdcm)
1314
2. Click `Add to Chrome` button
1415

1516
Manually:
17+
1618
1. [Download latest Chrome release from Github](https://github.com/mathio/chrome-new-tab-page-bookmarks/releases/download/latest/chrome-extension.zip)
1719
2. Unpack contents of the zip file to a directory (eg. `chrome-extension/`)
18-
3. Go to Chrome menu `` -> `More Tools` -> `Extensions` and enable `Developer mode` in the top right corner.
20+
3. Go to Chrome menu `` -> `Extensions` -> `Manage Extensions` and enable `Developer mode` in the top right corner.
1921
4. Click on `Load unpacked` button and point to `chrome-extension/` directory.
2022
5. Open new browser tab to see the extension!
2123

2224
### Firefox
2325

2426
From Firefox Add-ons:
27+
2528
1. go to [Firefox Add-ons](https://addons.mozilla.org/en-US/firefox/addon/new-tab-page-bookmarks/)
2629
2. click `Add to Firefox` button
2730

2831
Manually:
32+
2933
1. [Download latest Firefox release from Github](https://github.com/mathio/chrome-new-tab-page-bookmarks/releases/download/latest/firefox-extension.zip)
30-
2. Go to Firefox menu `` -> `Add-ons and themes`
34+
2. Go to Firefox menu `` -> `Extensions and themes`
3135
3. Click gear icon `` -> `Debug add-ons`
32-
4. Click `Load temporary add-on` button
36+
4. Expand `Temporary Extensions`, then click `Load temporary add-on` button
3337
5. Select `firefox-extension.zip`
3438
6. Open new browser tab to see the extension!
3539

3640
## Preview
3741

38-
![Chrome Screenshot](https://raw.githubusercontent.com/mathio/chrome-new-tab-page-bookmarks/main/store/chrome_screenshot_1280x800.png "Chrome Screenshot")
42+
![Chrome Screenshot](https://raw.githubusercontent.com/mathio/chrome-new-tab-page-bookmarks/main/store/chrome_screenshot_1280x800.png 'Chrome Screenshot')
3943

4044
## Description
4145

46+
- displays bookmars from Bookmarks Bar
4247
- does NOT manage your bookmarks, use the built-in bookmarks manager for that:
43-
- Chrome: `CMD+ALT+B` / `CTRL+SHIFT+O`
44-
- Firefox: `CMD+SHIFT+O` / `CTRL+SHIFT+O`
48+
- Chrome: `CMD+ALT+B` / `CTRL+SHIFT+O`
49+
- Firefox: `CMD+SHIFT+O` / `CTRL+SHIFT+O`
4550
- does NOT sync your bookmarks, your browser already does that
46-
- [Sync in Chrome](https://support.google.com/chrome/answer/185277)
47-
- [Firefox Sync](https://www.mozilla.org/en-US/firefox/sync/)
51+
- [Sync in Chrome](https://support.google.com/chrome/answer/185277)
52+
- [Firefox Sync](https://www.mozilla.org/en-US/firefox/sync/)
4853
- there are NO settings, deal with it
4954
- just displays your bookmarks in multiple columns for quick access from the new tab page
55+
- organize your bookmarks in folders under Bookmarks Bar to display in columns (or don't)
5056
- displays favicons for your bookmarks (via Google API)
5157
- displays small "show" / "hide" toggle in bottom right corner to hide all your bookmarks (for when you are sharing your screen or someone is looking over your shoulder)
5258
- when you hide bookmarks [a random photo](https://unsplash.com/documentation#get-a-random-photo) from [wallpaper topic on Unsplash](https://unsplash.com/t/wallpapers?utm_source=chrome-new-tab-page-bookmarks&utm_medium=referral) is displayed once every 15 minutes
5359

54-
5560
## Privacy and permission justification
5661

5762
Extension requires [permissions to access your bookmarks](https://developer.chrome.com/docs/extensions/reference/bookmarks/) to display them on the new tab page. Your bookmarks do not leave your device. It loads favicons via Google API ([using t2.gstatic.com/faviconV2 like this](https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://github.com&size=16)) and might disclose domains & subdomains (not full URLs) from your bookmarks to Google.
5863

59-
Wallpaper images from Unsplash API are loaded via proxy. All requests are anonymous and rate-limited via IP address hash. Image is loaded directly from Unsplash CDN and is [tracked by Unsplash](https://unsplash.com/documentation#hotlinking).
60-
64+
Wallpaper images from Unsplash API are loaded via proxy. All requests are anonymous and rate-limited via IP address hash. Image is loaded directly from Unsplash CDN and is [tracked by Unsplash](https://unsplash.com/documentation#hotlinking).
6165

6266
## Development
6367

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.7",
4+
"version": "1.8",
55
"manifest_version": 3,
66
"author": "https://github.com/mathio",
77
"chrome_url_overrides": {

firefox/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.7",
4+
"version": "1.8",
55
"manifest_version": 2,
66
"author": "https://github.com/mathio",
77
"chrome_url_overrides": {

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.7.0",
3+
"version": "1.8.0",
44
"main": "index.js",
55
"license": "MIT",
66
"author": "",

src/index.css

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,96 @@
11
* {
2-
margin: 0;
3-
padding: 0;
2+
margin: 0;
3+
padding: 0;
44
}
5-
html, body {
6-
height: 100%;
5+
html,
6+
body {
7+
height: 100%;
78
}
89
body {
9-
font-size: 13px;
10-
font-family: sans-serif;
10+
font-size: 13px;
11+
font-family: sans-serif;
1112
}
1213
ul#root {
13-
display: flex;
14-
flex-direction: row;
15-
flex-wrap: nowrap;
16-
margin-left: 20px;
14+
display: flex;
15+
flex-direction: row;
16+
flex-wrap: nowrap;
17+
margin-left: 20px;
18+
}
19+
ul#root.flat-bookmark-structure {
20+
flex-direction: column;
21+
flex-wrap: wrap;
22+
width: fit-content;
23+
height: 100%;
1724
}
1825
ul#root > li {
19-
margin-right: 20px;
26+
margin-right: 20px;
2027
}
2128
ul#root h3 {
22-
margin-top: 15px;
23-
font-size: 18px;
29+
margin-top: 15px;
30+
font-size: 18px;
2431
}
2532
ul {
26-
list-style: none;
27-
padding: 10px 0 10px 6px;
33+
list-style: none;
34+
padding: 10px 0 10px 6px;
2835
}
2936
ul#root li {
30-
margin-bottom: 4px;
37+
margin-bottom: 4px;
3138
}
3239
ul#root a {
33-
display: block;
34-
color: black;
35-
text-decoration: none;
36-
padding: 3px;
37-
line-height: 22px;
40+
display: block;
41+
color: black;
42+
text-decoration: none;
43+
padding: 3px;
44+
line-height: 22px;
3845
}
3946
ul#root a:hover {
40-
background: #eee;
47+
background: #eee;
4148
}
4249
ul#root a > img {
43-
margin-right: 4px;
44-
width: 16px;
45-
height: 16px;
46-
vertical-align: text-bottom;
50+
margin-right: 4px;
51+
width: 16px;
52+
height: 16px;
53+
vertical-align: text-bottom;
4754
}
4855
a#toggle {
49-
color: #000;
50-
font-size: 10px;
51-
cursor: pointer;
52-
position: fixed;
53-
bottom: 10px;
54-
right: 10px;
55-
padding: 5px;
56-
background: rgba(255,255,255,0.75);
57-
z-index: 9;
56+
color: #000;
57+
font-size: 10px;
58+
cursor: pointer;
59+
position: fixed;
60+
bottom: 10px;
61+
right: 10px;
62+
padding: 5px;
63+
background: rgba(255, 255, 255, 0.75);
64+
z-index: 9;
5865
}
5966
a#toggle:hover {
60-
background: rgba(255,255,255,0.9);
67+
background: rgba(255, 255, 255, 0.9);
6168
}
6269
p#image-attribution {
63-
font-size: 10px;
64-
position: fixed;
65-
bottom: 10px;
66-
left: 10px;
67-
padding: 5px;
68-
background: rgba(255,255,255,0.75);
69-
color: #000;
70-
z-index: 9;
70+
font-size: 10px;
71+
position: fixed;
72+
bottom: 10px;
73+
left: 10px;
74+
padding: 5px;
75+
background: rgba(255, 255, 255, 0.75);
76+
color: #000;
77+
z-index: 9;
7178
}
7279
p#image-attribution a {
73-
color: #000;
80+
color: #000;
7481
}
7582
#canvas {
76-
width: 100%;
77-
height: 100%;
78-
position: absolute;
79-
z-index: -1;
83+
width: 100%;
84+
height: 100%;
85+
position: absolute;
86+
z-index: -1;
8087
}
8188
#bg-image {
82-
width: 100%;
83-
height: 100%;
84-
position: absolute;
85-
z-index: 1;
86-
background-size: cover;
87-
background-repeat: no-repeat;
88-
background-position: center;
89-
}
89+
width: 100%;
90+
height: 100%;
91+
position: absolute;
92+
z-index: 1;
93+
background-size: cover;
94+
background-repeat: no-repeat;
95+
background-position: center;
96+
}

src/index.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const renderNode =
2929
const ul = addElm(li, 'ul')
3030
children.forEach(renderNode(ul))
3131
} else if (href) {
32+
const parentUl = li.closest('ul')
33+
if (parentUl?.id === 'root') {
34+
parentUl.className = 'flat-bookmark-structure'
35+
}
36+
3237
const icon = `<img src="${iconUrl(href)}" alt="${title.substring(
3338
0,
3439
1
@@ -38,11 +43,28 @@ const renderNode =
3843
}
3944
}
4045

41-
const renderBookmarksBar = (bookmarksBarId) => {
42-
chrome.bookmarks.getSubTree(bookmarksBarId, function ([rootNode]) {
43-
const root = document.querySelector('#root')
44-
rootNode.children.forEach(renderNode(root))
45-
})
46+
const renderBookmarksBar = async () => {
47+
const currentBrowser = typeof browser !== 'undefined' ? browser : chrome
48+
const domRoot = document.querySelector('#root')
49+
50+
const [rootNode] = await currentBrowser.bookmarks.getTree()
51+
52+
if (!rootNode?.children) {
53+
throw new Error('Unable to retrieve bookmarks')
54+
}
55+
56+
//
57+
rootNode.children
58+
.filter(
59+
(item) =>
60+
item.folderType === 'bookmarks-bar' || // chrome: find using folderType, there can be more than one (https://developer.chrome.com/blog/bookmarks-sync-changes)
61+
item.id === 'toolbar_____' // firefox: find using ID
62+
)
63+
.forEach((bar) => {
64+
bar.children.forEach(renderNode(domRoot))
65+
})
66+
67+
console.log(rootNode)
4668
}
4769

4870
const TOGGLE_KEY_NAME = 'hideBookmarksBar'
@@ -150,8 +172,7 @@ const showImage = ({ url, attribution, blurhash }) => {
150172
}
151173

152174
window.addEventListener('load', () => {
153-
const bookmarksBarId = !!chrome ? '1' : 'toolbar_____'
154-
renderBookmarksBar(bookmarksBarId)
175+
renderBookmarksBar()
155176
renderToggleLink()
156177
initImage()
157178
})

0 commit comments

Comments
 (0)