1
0
mirror of https://github.com/XFox111/TabsAsideExtension.git synced 2026-04-22 07:58:01 +03:00

Minor 1.6 (#24)

- Added localization system (#23)
- Added Russian locale (#23)
- Feedback button link is now based on the extension download source (#20)
- Added badge counter to the extension icon
- Added keyboard shortcuts (#22)
- Added action items to the extension icon context menu (#22)
- Added ability to change primary extension icon action to save tabs instead of opening the pane (#22)
This commit is contained in:
Michael Gordeev
2020-07-15 16:54:50 +03:00
committed by GitHub
parent 2eae09583c
commit 39f7cd391a
6 changed files with 475 additions and 55 deletions
+61 -37
View File
@@ -62,6 +62,8 @@ function Initialize()
});
}
UpdateLocale();
if (window.matchMedia("(prefers-color-scheme: dark)").matches)
{
pane.parentElement.setAttribute("darkmode", "");
@@ -72,7 +74,8 @@ function Initialize()
document.querySelector("nav > p > small").textContent = chrome.runtime.getManifest()["version"];
var loadOnRestoreCheckbox = document.querySelector("nav > p > input[type=checkbox]");
// Tabs dismiss option
var loadOnRestoreCheckbox = document.querySelector("#loadOnRestore");
chrome.storage.sync.get(
{ "loadOnRestore": false },
values => loadOnRestoreCheckbox.checked = values.loadOnRestore
@@ -91,8 +94,39 @@ function Initialize()
})
);
// Exntension browser icon action
var swapIconAction = document.querySelector("#swapIconAction");
chrome.storage.sync.get(
{ "setAsideOnClick": false },
values => swapIconAction.checked = values.setAsideOnClick
);
chrome.storage.onChanged.addListener((changes, namespace) =>
{
if (namespace == 'sync')
for (key in changes)
if (key === 'setAsideOnClick')
swapIconAction.checked = changes[key].newValue
});
swapIconAction.addEventListener("click", () =>
chrome.storage.sync.set(
{
"setAsideOnClick": swapIconAction.checked
})
);
document.querySelectorAll(".tabsAside.pane > header nav button").forEach(i =>
i.onclick = () => window.open(i.value, '_blank'));
i.onclick = () =>
{
if (i.hasAttribute("feedback-button"))
{
if (chrome.runtime.getManifest()["update_url"] && chrome.runtime.getManifest()["update_url"].includes("edge.microsoft.com"))
window.open("https://microsoftedge.microsoft.com/addons/detail/tabs-aside/kmnblllmalkiapkfknnlpobmjjdnlhnd", "_blank")
else
window.open("https://chrome.google.com/webstore/detail/tabs-aside/mgmjbodjgijnebfgohlnjkegdpbdjgin", "_blank")
}
else
window.open(i.value, "_blank");
});
chrome.runtime.sendMessage({ command: "loadData" }, (collections) =>
{
@@ -104,6 +138,12 @@ function Initialize()
setTimeout(() => pane.setAttribute("opened", ""), 100);
}
function UpdateLocale()
{
document.querySelectorAll("*[loc]").forEach(i => i.textContent = chrome.i18n.getMessage(i.getAttribute("loc")));
document.querySelectorAll("*[loc_alt]").forEach(i => i.title = chrome.i18n.getMessage(i.getAttribute("loc_alt")));
}
function AddCollection(collection)
{
var list = document.querySelector(".tabsAside section");
@@ -119,7 +159,7 @@ function AddCollection(collection)
"<div>" +
"<div" + ((collection.icons[i] == 0 || collection.icons[i] == null) ? "" : " style='background-image: url(\"" + collection.icons[i] + "\")'") + "></div>" +
"<span>" + collection.titles[i] + "</span>" +
"<button class='btn remove' title='Remove tab from collection'></button>" +
"<button loc_alt='name' class='btn remove' title='Remove tab from collection'></button>" +
"</div>" +
"</div>";
}
@@ -127,20 +167,22 @@ function AddCollection(collection)
list.innerHTML +=
"<div class='collectionSet'>" +
"<div class='header'>" +
"<span>Tabs: " + collection.links.length + "</span>" +
"<span>" + chrome.i18n.getMessage("tabs") + ": " + collection.links.length + "</span>" +
"<small>" + GetAgo(collection.timestamp) + "</small>" +
"<a class='restoreCollection'>Restore tabs</a>" +
"<a loc='restoreTabs' class='restoreCollection'>Restore tabs</a>" +
"<div>" +
"<button class='btn more' title='More...'></button>" +
"<button loc_alt='more' class='btn more' title='More...'></button>" +
"<nav>" +
"<button class='restoreCollection noDelete'>Restore without removing</button>" +
"<button loc='restoreNoRemove' class='restoreCollection noDelete'>Restore without removing</button>" +
"</nav>" +
"</div>" +
"<button class='btn remove' title='Remove collection'></button>" +
"<button loc_alt='removeCollection' class='btn remove' title='Remove collection'></button>" +
"</div>" +
"<div class='set' class='tabsList'>" + rawTabs + "</div>" +
"</div>"
"</div>";
UpdateLocale();
list.querySelectorAll(".restoreCollection").forEach(i =>
i.onclick = () => RestoreTabs(i.parentElement.parentElement));
@@ -187,7 +229,7 @@ function RestoreTabs(collectionData, removeCollection = true)
function RemoveTabs(collectionData)
{
if (!confirm("Are you sure you want to delete this collection?"))
if (!confirm(chrome.i18n.getMessage("removeCollectionConfirm")))
return;
chrome.runtime.sendMessage(
@@ -201,7 +243,7 @@ function RemoveTabs(collectionData)
function RemoveOneTab(tabData)
{
if (!confirm("Are you sure you want to delete this tab?"))
if (!confirm(chrome.i18n.getMessage("removeTabConfirm")))
return;
chrome.runtime.sendMessage(
@@ -212,7 +254,7 @@ function RemoveOneTab(tabData)
},
() =>
{
tabData.parentElement.previousElementSibling.children[0].textContent = "Tabs: " + (tabData.parentElement.children.length - 1);
tabData.parentElement.previousElementSibling.children[0].textContent = chrome.i18n.getMessage("tabs") + ": " + (tabData.parentElement.children.length - 1);
if (tabData.parentElement.children.length < 2)
{
RemoveElement(tabData.parentElement.parentElement);
@@ -229,37 +271,19 @@ function GetAgo(timestamp)
var minutes = (Date.now() - timestamp) / 60000;
if (minutes < 1)
return "Just now";
else if (Math.floor(minutes) == 1)
return "1 minute ago";
return chrome.i18n.getMessage("justNow");
else if (minutes < 60)
return Math.floor(minutes) + " minutes ago";
else if (Math.floor(minutes / 60) == 1)
return "1 hour ago";
return Math.floor(minutes) + " " + chrome.i18n.getMessage("minutes") + " " + chrome.i18n.getMessage("ago");
else if (minutes < 24 * 60)
return Math.floor(minutes / 60) + " hours ago";
else if (Math.floor(minutes / 24 / 60) == 1)
return "1 day ago";
return Math.floor(minutes / 60) + " " + chrome.i18n.getMessage("hours") + " " + chrome.i18n.getMessage("ago");
else if (minutes < 7 * 24 * 60)
return Math.floor(minutes / 24 / 60) + " days ago";
else if (Math.floor(minutes / 7 / 24 / 60) == 1)
return "1 week ago";
return Math.floor(minutes / 24 / 60) + " " + chrome.i18n.getMessage("days") + " " + chrome.i18n.getMessage("ago");
else if (minutes < 30 * 24 * 60)
return Math.floor(minutes / 7 / 24 / 60) + " weeks ago";
else if (Math.floor(minutes / 30 / 24 / 60) == 1)
return "1 month ago";
return Math.floor(minutes / 7 / 24 / 60) + " " + chrome.i18n.getMessage("weeks") + " " + chrome.i18n.getMessage("ago");
else if (minutes < 365 * 24 * 60)
return Math.floor(minutes / 30 / 24 / 60) + " months ago";
else if (Math.floor(minutes / 24 / 60) == 365)
return "1 year ago";
return Math.floor(minutes / 30 / 24 / 60) + " " + chrome.i18n.getMessage("months") + " " + chrome.i18n.getMessage("ago");
else
return Math.floor(minutes / 365 / 24 / 60) + "years ago";
return Math.floor(minutes / 365 / 24 / 60) + " " + chrome.i18n.getMessage("years") + " " + chrome.i18n.getMessage("ago");
}
function RemoveElement(el)
+57 -2
View File
@@ -1,4 +1,4 @@
chrome.browserAction.onClicked.addListener((tab) =>
function TogglePane(tab)
{
if (tab.url.startsWith("http")
&& !tab.url.includes("chrome.google.com")
@@ -38,10 +38,59 @@ chrome.browserAction.onClicked.addListener((tab) =>
});
}));
}
}
function ProcessCommand(command)
{
switch(command)
{
case "set-aside":
SaveCollection();
break;
case "toggle-pane":
chrome.tabs.query(
{
active: true,
currentWindow: true
},
(tabs) => TogglePane(tabs[0])
)
break;
}
}
chrome.browserAction.onClicked.addListener((tab) =>
{
chrome.storage.sync.get({ "setAsideOnClick": false }, values =>
{
if (values.setAsideOnClick)
SaveCollection();
else
TogglePane(tab);
});
});
// Adding context menu options
chrome.contextMenus.create(
{
id: "toggle-pane",
contexts: ['all'],
title: chrome.i18n.getMessage("togglePaneContext")
}
);
chrome.contextMenus.create(
{
id: "set-aside",
contexts: ['all'],
title: chrome.i18n.getMessage("setAside")
}
);
var collections = JSON.parse(localStorage.getItem("sets")) || [];
chrome.commands.onCommand.addListener(ProcessCommand);
chrome.contextMenus.onClicked.addListener((info) => ProcessCommand(info.menuItemId));
chrome.runtime.onMessage.addListener((message, sender, sendResponse) =>
{
switch (message.command)
@@ -88,6 +137,12 @@ function UpdateTheme()
"16": basePath + "16.png"
}
});
// Updating badge counter
if (collections.length < 1)
chrome.browserAction.setBadgeText({ });
else
chrome.browserAction.setBadgeText({ text: collections.length.toString() });
}
UpdateTheme();
@@ -104,7 +159,7 @@ function SaveCollection()
if (tabs.length < 1)
{
alert("No tabs available to save");
alert(chrome.i18n.getMessage("noTabsToSave"));
return;
}