Skip to content

Commit ee6b1b7

Browse files
bugfixes
- fix chrome rename bug (rename on chrome triggered "change" event which led to redundant thumbnails being captured) - fix context menu bug which led to duplicate thumbnails - fix thumbnail path issue for relative urls (leading / in url should be a path relative to the domain root) - support for speed dials created via bookmarks manager in chrome
1 parent d64184c commit ee6b1b7

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/js/background.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ function onClickHandler(info, tab) {
4646
parentId: speedDialId,
4747
title: tab.title,
4848
url: tab.url
49-
}).then(response => {
50-
getThumbnails(tab.url).then(() => {
51-
pushToCache(tab.url).then(() => refreshOpen())
52-
});
53-
});
49+
})
5450
}
5551
});
5652
}
@@ -70,10 +66,14 @@ function convertUrlToAbsolute(origin, path) {
7066
return 'https:' + path;
7167
} else {
7268
let url = new URL(origin);
73-
if (url.pathname.slice(-1) !== "/") {
74-
url.pathname = url.pathname + "/";
69+
if (path.slice(0,1) === "/") {
70+
return url.origin + path;
71+
} else {
72+
if (url.pathname.slice(-1) !== "/") {
73+
url.pathname = url.pathname + "/";
74+
}
75+
return url.origin + url.pathname + path;
7576
}
76-
return url.origin + url.pathname + path;
7777
}
7878
}
7979

@@ -339,12 +339,19 @@ function changeBookmark(id, info) {
339339
if (info.url) {
340340
browser.bookmarks.get(id).then(bookmark => {
341341
if (bookmark[0].parentId === speedDialId) {
342-
// todo: skip if already in the cache
343-
getThumbnails(bookmark[0].url).then(() => {
344-
pushToCache(bookmark[0].url).then(() => {
345-
refreshOpen()
346-
})
347-
})
342+
browser.storage.local.get(bookmark[0].url).then(result => {
343+
if (result[bookmark[0].url]) {
344+
// a pre-existing bookmark is being modified; dont fetch new thumbnails
345+
// todo: there might be a race condition here for bookmarks created via context menu
346+
return
347+
} else {
348+
getThumbnails(bookmark[0].url).then(() => {
349+
pushToCache(bookmark[0].url).then(() => {
350+
refreshOpen()
351+
})
352+
})
353+
}
354+
});
348355
}
349356
});
350357
}
@@ -394,7 +401,10 @@ function init() {
394401
browser.runtime.onConnect.addListener(connected);
395402
// ff triggers 'moved' for bookmarks saved to different folder than default
396403
browser.bookmarks.onMoved.addListener(updateBookmark);
404+
// ff triggers 'changed' for bookmarks created manually? todo: confirm
397405
browser.bookmarks.onChanged.addListener(changeBookmark);
406+
// chrome triggers oncreated for bookmarks created manually in bookmark mgr. todo: make sure this doesnt hurt ff
407+
browser.bookmarks.onCreated.addListener(changeBookmark);
398408
browser.bookmarks.onRemoved.addListener(removeBookmark);
399409
browser.contextMenus.onClicked.addListener(onClickHandler);
400410

0 commit comments

Comments
 (0)