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

[v1.7.3] Firefox compability patch (#32)

- Added Firefox support (#28)
- Updated settings defaults
- Updated `about:` protocol behavior
- Fixed collections header becoming the old one on a tab removing
- Added VS Code debugging config
- Removed trailing whitespaces
This commit is contained in:
Michael Gordeev
2020-08-10 23:46:37 +03:00
committed by GitHub
parent 80c9dbe1a5
commit f74eeb5759
12 changed files with 160 additions and 86 deletions
+19 -17
View File
@@ -1,4 +1,4 @@
if (window.location === window.parent.location && window.location.protocol != "chrome-extension:") // For open/close call
if (window.location === window.parent.location && !window.location.protocol.includes("-extension:")) // For open/close call
{
var iframe = document.querySelector("iframe.tabsAsideIframe");
if (!iframe)
@@ -52,14 +52,14 @@ function Initialize()
if (window.location !== window.parent.location)
{
pane.setAttribute("embedded", "");
window.addEventListener('message', event =>
window.addEventListener('message', event =>
{
if (event.data.target == "TabsAside")
{
pane.parentElement.style.opacity = 0;
pane.removeAttribute("opened");
}
});
});
}
UpdateLocale();
@@ -80,8 +80,8 @@ function Initialize()
// Tabs dismiss option
var loadOnRestoreCheckbox = document.querySelector("#loadOnRestore");
chrome.storage.sync.get(
{ "loadOnRestore": false },
values => loadOnRestoreCheckbox.checked = values.loadOnRestore
{ "loadOnRestore": true },
values => loadOnRestoreCheckbox.checked = values?.loadOnRestore ?? true
);
chrome.storage.onChanged.addListener((changes, namespace) =>
{
@@ -101,7 +101,7 @@ function Initialize()
var swapIconAction = document.querySelector("#swapIconAction");
chrome.storage.sync.get(
{ "setAsideOnClick": false },
values => swapIconAction.checked = values.setAsideOnClick
values => swapIconAction.checked = values?.setAsideOnClick ?? false
);
chrome.storage.onChanged.addListener((changes, namespace) =>
{
@@ -137,7 +137,7 @@ function Initialize()
})
);
document.querySelectorAll(".tabsAside.pane > header nav button").forEach(i =>
document.querySelectorAll(".tabsAside.pane > header nav button").forEach(i =>
i.onclick = () =>
{
if (i.hasAttribute("feedback-button"))
@@ -154,7 +154,7 @@ function Initialize()
chrome.runtime.sendMessage({ command: "loadData" }, (collections) =>
{
if (document.querySelector(".tabsAside.pane section div") == null)
collections.forEach(i =>
collections.forEach(i =>
AddCollection(i));
});
@@ -165,9 +165,11 @@ 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));
chrome.runtime.sendMessage({ command: "getShortcuts" }, (shortcuts) =>
swapActionsLabel.textContent = swapActionsLabel.textContent.replace("%TOGGLE_SHORTCUT%", shortcuts.filter(i => i.name == "toggle-pane")[0].shortcut)
);
}
function AddCollection(collection)
@@ -207,13 +209,13 @@ function AddCollection(collection)
"<div class='set' class='tabsList'>" + rawTabs + "</div>" +
"</div>";
UpdateLocale();
list.querySelectorAll(".restoreCollection").forEach(i =>
list.querySelectorAll(".restoreCollection").forEach(i =>
i.onclick = () => RestoreTabs(i.parentElement.parentElement));
list.querySelectorAll(".restoreCollection.noDelete").forEach(i =>
list.querySelectorAll(".restoreCollection.noDelete").forEach(i =>
i.onclick = () => RestoreTabs(i.parentElement.parentElement.parentElement.parentElement, false));
list.querySelectorAll(".openTab").forEach(i =>
@@ -255,7 +257,7 @@ function RestoreTabs(collectionData, removeCollection = true)
function RemoveTabs(collectionData)
{
chrome.storage.sync.get({ "showDeleteDialog": true }, values =>
chrome.storage.sync.get({ "showDeleteDialog": true }, values =>
{
if (values.showDeleteDialog && !confirm(chrome.i18n.getMessage("removeCollectionConfirm")))
return;
@@ -272,7 +274,7 @@ function RemoveTabs(collectionData)
function RemoveOneTab(tabData)
{
chrome.storage.sync.get({ "showDeleteDialog": true }, values =>
chrome.storage.sync.get({ "showDeleteDialog": true }, values =>
{
if (values.showDeleteDialog && !confirm(chrome.i18n.getMessage("removeTabConfirm")))
return;
@@ -285,7 +287,7 @@ function RemoveOneTab(tabData)
},
() =>
{
tabData.parentElement.previousElementSibling.children[0].textContent = chrome.i18n.getMessage("tabs") + ": " + (tabData.parentElement.children.length - 1);
tabData.parentElement.previousElementSibling.querySelector("small").textContent = (tabData.parentElement.children.length - 1) + " " + chrome.i18n.getMessage("tabs");
if (tabData.parentElement.children.length < 2)
{
RemoveElement(tabData.parentElement.parentElement);
@@ -307,6 +309,6 @@ function RemoveElement(el)
function RemoveCollectionElement(el)
{
if (el.parentElement.children.length < 3)
setTimeout(() => document.querySelector(".tabsAside.pane > section > h2").removeAttribute("hidden"), 250);
setTimeout(() => document.querySelector(".tabsAside.pane > section > h2").removeAttribute("hidden"), 250);
RemoveElement(el);
}
+22 -16
View File
@@ -2,6 +2,7 @@ function TogglePane(tab)
{
if (tab.url.startsWith("http")
&& !tab.url.includes("chrome.google.com")
&& !tab.url.includes("addons.mozilla.org")
&& !tab.url.includes("microsoftedge.microsoft.com"))
{
chrome.tabs.executeScript(tab.id,
@@ -21,14 +22,14 @@ function TogglePane(tab)
active: true
},
(activeTab) =>
chrome.tabs.onActivated.addListener(function TabsAsideCloser(activeInfo)
chrome.tabs.onActivated.addListener(function TabsAsideCloser(activeInfo)
{
chrome.tabs.query({ url: chrome.extension.getURL("TabsAside.html") }, (result) =>
{
if (result.length)
setTimeout(() =>
{
result.forEach(i =>
result.forEach(i =>
{
if (activeInfo.tabId != i.id)
chrome.tabs.remove(i.id);
@@ -61,9 +62,9 @@ function ProcessCommand(command)
chrome.browserAction.onClicked.addListener((tab) =>
{
chrome.storage.sync.get({ "setAsideOnClick": false }, values =>
chrome.storage.sync.get({ "setAsideOnClick": false }, values =>
{
if (values.setAsideOnClick)
if (values?.setAsideOnClick)
SaveCollection();
else
TogglePane(tab);
@@ -87,6 +88,8 @@ chrome.contextMenus.create(
);
var collections = JSON.parse(localStorage.getItem("sets")) || [];
var shortcuts;
chrome.commands.getAll((commands) => shortcuts = commands);
chrome.commands.onCommand.addListener(ProcessCommand);
chrome.contextMenus.onClicked.addListener((info) => ProcessCommand(info.menuItemId));
@@ -125,12 +128,21 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) =>
(tabs) => TogglePane(tabs[0])
)
break;
case "getShortcuts":
sendResponse(shortcuts);
break;
}
});
// This function updates the extension's toolbar icon
function UpdateTheme()
{
// Updating badge counter
chrome.browserAction.setBadgeText({ text: collections.length < 1 ? "" : collections.length.toString() });
if (chrome.theme) // Firefox sets theme automatically
return;
var theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
var iconStatus = collections.length ? "full" : "empty";
@@ -146,12 +158,6 @@ 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();
@@ -164,7 +170,7 @@ function SaveCollection()
{
chrome.tabs.query({ currentWindow: true }, (rawTabs) =>
{
var tabs = rawTabs.filter(i => i.url != chrome.runtime.getURL("TabsAside.html") && !i.pinned && !i.url.includes("//newtab"));
var tabs = rawTabs.filter(i => i.url != chrome.runtime.getURL("TabsAside.html") && !i.pinned && !i.url.includes("//newtab") && !i.url.includes("about:blank") && !i.url.includes("about:home"));
if (tabs.length < 1)
{
@@ -196,7 +202,7 @@ function SaveCollection()
collections = JSON.parse(localStorage.getItem("sets"));
var newTabId;
chrome.tabs.create({}, (tab) =>
chrome.tabs.create({}, (tab) =>
{
newTabId = tab.id;
chrome.tabs.remove(rawTabs.filter(i => !i.pinned && i.id != newTabId).map(tab => tab.id));
@@ -216,7 +222,7 @@ function DeleteCollection(collectionIndex)
function RestoreCollection(collectionIndex, removeCollection)
{
collections[collectionIndex].links.forEach(i =>
collections[collectionIndex].links.forEach(i =>
{
chrome.tabs.create(
{
@@ -225,10 +231,10 @@ function RestoreCollection(collectionIndex, removeCollection)
},
(createdTab) =>
{
chrome.storage.sync.get({ "loadOnRestore" : false }, values =>
chrome.storage.sync.get({ "loadOnRestore" : true }, values =>
{
if (!values.loadOnRestore)
chrome.tabs.onUpdated.addListener(function DiscardTab(updatedTabId, changeInfo, updatedTab)
if (!(values?.loadOnRestore))
chrome.tabs.onUpdated.addListener(function DiscardTab(updatedTabId, changeInfo, updatedTab)
{
if (updatedTabId === createdTab.id) {
chrome.tabs.onUpdated.removeListener(DiscardTab);