Open Ashark opened 1 year ago
I’ve never been a fan of stacks. And they are a an outlier from a coding standpoint, because they aren’t proper tabs anymore. Had to deal with them in the “activate tab on hover” mod in the past and had to give up on supporting them. From the top of my head I don’t know a solution to this.
Thanks for comment. It's sad. This is one of major vivaldi frustrations.
I have an idea on how to implement this.
Getting the current tab (its id and its stack id):
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var activeTab = tabs[0];
var activeTabvivExtData = activeTab.vivExtData;
var jr = JSON.parse(activeTabvivExtData);
var activeTabStackId = jr["group"];
console.log(activeTabStackId);
});
Getting the dictionary of stack ids with list of their tabs:
chrome.tabs.query({ currentWindow: true }, function (tabs) {
var groups = {};
for (const tab of tabs) {
tab_group = JSON.parse(tab.vivExtData)["group"];
if (!groups[tab_group]) {
groups[tab_group] = [];
}
groups[tab_group].push(tab);
}
console.log(groups);
});
Switching to another tab:
chrome.tabs.update(tabId_here, {active: true});
Now I want my mod.js
to catch the tab close event. I tried this two functions in console, and they worked:
chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) {
myFunction(tabId);
});
function myFunction(tabId) {
console.log("Tab closed: " + tabId);
}
But how to run that in a mod.js? I tried surrounding that with
(function () {
...
})();
as I saw in your other mods. But it does not logs tab closing in console. What I am doing wrong?
Could be this only works from an extension. Put a console log after the mod has loaded, then you know whether your mod loads, surrounding with a function is not enough, you have to initiate somehow.
You were right that the mod was not activated. I tried your mod “activate tab on hover” on Arch Linux with the vivaldi-autoinject-custom-js-ui, and it is not currently updated to modify window.html instead of browser.html.
So I moved the <script src="activate-tab-on-hover.js"></script>
to window.html and it worked.
Also, I placed my <script src="keep-in-stack-at-tab-close.js"></script>
there. It is loaded now.
Put a console log after the mod has loaded, then you know whether your mod loads
I put the following to the keep-in-stack-at-tab-close.js
file:
(function () {
console.log("I am loaded");
chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) {
myFunction(tabId);
});
function myFunction(tabId) {
console.log("Tab closed: " + tabId);
}
})();
And now I can see that "I am loaded" in log messages. But I cannot see the logs at tab closings.
Then it probably doesn’t work.
Is it possible to access Looks like no.
Looks like the only solution is the browser extension.chrome.tabs
from ViolentMonkey script?
just wanted to say that vivaldi-autoinject-custom-js-ui has been updated.
Hi. Is it possible to manually keep the activated tab from the list of current tab stack when closing a tab? The problem is reported in this forum thread. Maybe this can be done with some mod? Is there a way to list/switch tabs in javascript based on a stack it belongs?