mirror of
https://github.com/XFox111/TabsAsideExtension.git
synced 2026-04-22 07:58:01 +03:00
Minor 1.7 (#31)
- Complete UI/UX overhaul - Updated default hotkeys (#27) - Added option to disable deletion confirmation (#29) - Added Chinese translation - Fixed font artifacts on Windows Co-authored-by: Dustin-Jiang <56217843+Dustin-Jiang@users.noreply.github.com> Co-Authored-By: Michael Gordeev <michael@xfox111.net>
This commit is contained in:
+65
-53
@@ -71,6 +71,9 @@ function Initialize()
|
||||
}
|
||||
|
||||
document.querySelector(".tabsAside .saveTabs").onclick = SetTabsAside;
|
||||
document.querySelector(".tabsAside header .btn.remove").addEventListener("click", () =>
|
||||
chrome.runtime.sendMessage({ command: "togglePane" })
|
||||
);
|
||||
|
||||
document.querySelector("nav > p > small").textContent = chrome.runtime.getManifest()["version"];
|
||||
|
||||
@@ -114,6 +117,26 @@ function Initialize()
|
||||
})
|
||||
);
|
||||
|
||||
// Deletion confirmation dialog
|
||||
var showDeleteDialog = document.querySelector("#showDeleteDialog");
|
||||
chrome.storage.sync.get(
|
||||
{ "showDeleteDialog": true },
|
||||
values => showDeleteDialog.checked = values.showDeleteDialog
|
||||
);
|
||||
chrome.storage.onChanged.addListener((changes, namespace) =>
|
||||
{
|
||||
if (namespace == 'sync')
|
||||
for (key in changes)
|
||||
if (key === 'showDeleteDialog')
|
||||
showDeleteDialog.checked = changes[key].newValue
|
||||
});
|
||||
showDeleteDialog.addEventListener("click", () =>
|
||||
chrome.storage.sync.set(
|
||||
{
|
||||
"showDeleteDialog": showDeleteDialog.checked
|
||||
})
|
||||
);
|
||||
|
||||
document.querySelectorAll(".tabsAside.pane > header nav button").forEach(i =>
|
||||
i.onclick = () =>
|
||||
{
|
||||
@@ -142,6 +165,9 @@ 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")));
|
||||
|
||||
var swapActionsLabel = document.querySelector("label[loc=swapIconAction]");
|
||||
chrome.commands.getAll((commands) => swapActionsLabel.textContent = swapActionsLabel.textContent.replace("%TOGGLE_SHORTCUT%", commands[2].shortcut));
|
||||
}
|
||||
|
||||
function AddCollection(collection)
|
||||
@@ -159,7 +185,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 loc_alt='name' class='btn remove' title='Remove tab from collection'></button>" +
|
||||
"<button loc_alt='removeTab' class='btn remove' title='Remove tab from collection'></button>" +
|
||||
"</div>" +
|
||||
"</div>";
|
||||
}
|
||||
@@ -167,8 +193,7 @@ function AddCollection(collection)
|
||||
list.innerHTML +=
|
||||
"<div class='collectionSet'>" +
|
||||
"<div class='header'>" +
|
||||
"<span>" + chrome.i18n.getMessage("tabs") + ": " + collection.links.length + "</span>" +
|
||||
"<small>" + GetAgo(collection.timestamp) + "</small>" +
|
||||
"<h4>" + new Date(collection.timestamp).toDateString() + "</h4>" +
|
||||
"<a loc='restoreTabs' class='restoreCollection'>Restore tabs</a>" +
|
||||
"<div>" +
|
||||
"<button loc_alt='more' class='btn more' title='More...'></button>" +
|
||||
@@ -177,6 +202,7 @@ function AddCollection(collection)
|
||||
"</nav>" +
|
||||
"</div>" +
|
||||
"<button loc_alt='removeCollection' class='btn remove' title='Remove collection'></button>" +
|
||||
"<small>" + collection.links.length + " " + chrome.i18n.getMessage("tabs") +"</small>" +
|
||||
"</div>" +
|
||||
|
||||
"<div class='set' class='tabsList'>" + rawTabs + "</div>" +
|
||||
@@ -229,61 +255,47 @@ function RestoreTabs(collectionData, removeCollection = true)
|
||||
|
||||
function RemoveTabs(collectionData)
|
||||
{
|
||||
if (!confirm(chrome.i18n.getMessage("removeCollectionConfirm")))
|
||||
return;
|
||||
chrome.storage.sync.get({ "showDeleteDialog": true }, values =>
|
||||
{
|
||||
if (values.showDeleteDialog && !confirm(chrome.i18n.getMessage("removeCollectionConfirm")))
|
||||
return;
|
||||
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
command: "deleteTabs",
|
||||
collectionIndex: Array.prototype.slice.call(collectionData.parentElement.children).indexOf(collectionData) - 1
|
||||
},
|
||||
() => RemoveCollectionElement(collectionData)
|
||||
);
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
command: "deleteTabs",
|
||||
collectionIndex: Array.prototype.slice.call(collectionData.parentElement.children).indexOf(collectionData) - 1
|
||||
},
|
||||
() => RemoveCollectionElement(collectionData)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function RemoveOneTab(tabData)
|
||||
{
|
||||
if (!confirm(chrome.i18n.getMessage("removeTabConfirm")))
|
||||
return;
|
||||
chrome.storage.sync.get({ "showDeleteDialog": true }, values =>
|
||||
{
|
||||
if (values.showDeleteDialog && !confirm(chrome.i18n.getMessage("removeTabConfirm")))
|
||||
return;
|
||||
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
command: "removeTab",
|
||||
collectionIndex: Array.prototype.slice.call(tabData.parentElement.parentElement.parentElement.children).indexOf(tabData.parentElement.parentElement) - 1,
|
||||
tabIndex: Array.prototype.slice.call(tabData.parentElement.children).indexOf(tabData)
|
||||
},
|
||||
() =>
|
||||
{
|
||||
tabData.parentElement.previousElementSibling.children[0].textContent = chrome.i18n.getMessage("tabs") + ": " + (tabData.parentElement.children.length - 1);
|
||||
if (tabData.parentElement.children.length < 2)
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
RemoveElement(tabData.parentElement.parentElement);
|
||||
if (document.querySelector("tabsAside.pane > section").children.length < 2)
|
||||
setTimeout(() => document.querySelector(".tabsAside.pane > section > h2").removeAttribute("hidden"), 250);
|
||||
}
|
||||
else
|
||||
RemoveElement(tabData);
|
||||
});
|
||||
}
|
||||
|
||||
function GetAgo(timestamp)
|
||||
{
|
||||
var minutes = (Date.now() - timestamp) / 60000;
|
||||
|
||||
if (minutes < 1)
|
||||
return chrome.i18n.getMessage("justNow");
|
||||
else if (minutes < 60)
|
||||
return Math.floor(minutes) + " " + chrome.i18n.getMessage("minutes") + " " + chrome.i18n.getMessage("ago");
|
||||
else if (minutes < 24 * 60)
|
||||
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) + " " + chrome.i18n.getMessage("days") + " " + chrome.i18n.getMessage("ago");
|
||||
else if (minutes < 30 * 24 * 60)
|
||||
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) + " " + chrome.i18n.getMessage("months") + " " + chrome.i18n.getMessage("ago");
|
||||
else
|
||||
return Math.floor(minutes / 365 / 24 / 60) + " " + chrome.i18n.getMessage("years") + " " + chrome.i18n.getMessage("ago");
|
||||
command: "removeTab",
|
||||
collectionIndex: Array.prototype.slice.call(tabData.parentElement.parentElement.parentElement.children).indexOf(tabData.parentElement.parentElement) - 1,
|
||||
tabIndex: Array.prototype.slice.call(tabData.parentElement.children).indexOf(tabData)
|
||||
},
|
||||
() =>
|
||||
{
|
||||
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);
|
||||
if (document.querySelector("tabsAside.pane > section").children.length < 2)
|
||||
setTimeout(() => document.querySelector(".tabsAside.pane > section > h2").removeAttribute("hidden"), 250);
|
||||
}
|
||||
else
|
||||
RemoveElement(tabData);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function RemoveElement(el)
|
||||
@@ -294,7 +306,7 @@ function RemoveElement(el)
|
||||
|
||||
function RemoveCollectionElement(el)
|
||||
{
|
||||
RemoveElement(el);
|
||||
if (el.parentElement.children.length < 2)
|
||||
if (el.parentElement.children.length < 3)
|
||||
setTimeout(() => document.querySelector(".tabsAside.pane > section > h2").removeAttribute("hidden"), 250);
|
||||
RemoveElement(el);
|
||||
}
|
||||
Reference in New Issue
Block a user