diff --git a/css/style.css b/css/style.css index ccfc97b..3425240 100644 --- a/css/style.css +++ b/css/style.css @@ -191,6 +191,8 @@ background-color: #c2c2c2 !important; background-image: url("chrome-extension://__MSG_@@extension_id__/images/tab_thumbnail.png"); + background-size: cover !important; + background-position-x: center !important; display: inline-grid !important; grid-template-rows: 1fr auto !important; diff --git a/js/aside-script.js b/js/aside-script.js index d8d71d3..f35ddb8 100644 --- a/js/aside-script.js +++ b/js/aside-script.js @@ -123,7 +123,7 @@ function AddCollection(collection) for (var i = 0; i < collection.links.length; i++) { rawTabs += - "
" + + "
" + "" + "
" + "
" + @@ -204,6 +204,7 @@ function RestoreTabs(collectionData, removeCollection = true) chrome.runtime.sendMessage( { command: "restoreTabs", + removeCollection: removeCollection, collectionIndex: Array.prototype.slice.call(collectionData.parentElement.children).indexOf(collectionData) - 1 }, function () diff --git a/js/background.js b/js/background.js index f502723..1a4d8b6 100644 --- a/js/background.js +++ b/js/background.js @@ -179,8 +179,8 @@ function SaveCollection() tabsCount: tabs.length, titles: tabs.map(tab => tab.title ?? ""), links: tabs.map(tab => tab.url ?? ""), - icons: tabs.map(tab => tab.favIconUrl ?? "")//, - //tumbnails: tabs.map(tab => chrome.tabs.captureVisibleTab) + icons: tabs.map(tab => tab.favIconUrl ?? ""), + thumbnails: tabs.map(tab => thumbnails.find(i => i.tabId == tab.id)?.url ?? "") }; var rawData; @@ -282,4 +282,41 @@ function RemoveTab(collectionIndex, tabIndex) localStorage.setItem("sets", JSON.stringify(collections)); UpdateTheme(); -} \ No newline at end of file +} + +var thumbnails = []; + +function AppendThumbnail(tabId, cahngeInfo, tab) +{ + if (!tab.active || !tab.url.startsWith("http")) + return; + + chrome.tabs.captureVisibleTab( + { + format: "jpeg", + quality: 1 + }, + function (dataUrl) + { + if(!dataUrl) + { + console.log("Failed to retrieve thumbnail"); + return; + } + + console.log("Thumbnail retrieved"); + var item = thumbnails.find(i => i.tabId == tabId); + if (item) + item.url = dataUrl; + else + thumbnails.unshift( + { + tabId: tabId, + url: dataUrl + } + ); + } + ); +} + +chrome.tabs.onUpdated.addListener(AppendThumbnail); \ No newline at end of file diff --git a/manifest.json b/manifest.json index d2e141b..22258ec 100644 --- a/manifest.json +++ b/manifest.json @@ -8,7 +8,7 @@ [ "tabs", "unlimitedStorage", - "activeTab" + "" ], "icons":