mirror of
https://github.com/XFox111/TabsAsideExtension.git
synced 2026-04-22 07:58:01 +03:00
Added thumbnails to saved tabs
This commit is contained in:
+40
-3
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
Reference in New Issue
Block a user