Skip to content

Instantly share code, notes, and snippets.

@sclark39
Created June 29, 2023 00:36
Show Gist options
  • Save sclark39/c10b1de38084ab82e76bd07fe829fb40 to your computer and use it in GitHub Desktop.
Save sclark39/c10b1de38084ab82e76bd07fe829fb40 to your computer and use it in GitHub Desktop.
let prev_tab_id = {}
async function onClick(tab)
{
try {
let current_tab = tab.id;
let current_window = tab.windowId;
// Find all the gmail tabs
var tabs = await browser.tabs.query({ windowId: current_window, url: "*://mail.google.com/*" });
if ( tabs.length == 0 )
{
prev_tab_id = current_tab;
browser.tabs.create(
{
url: "https://mail.google.com",
pinned: true,
active: true
}
)
}
else
{
tabs.sort((a, b) => a.index - b.index);
for ( let tab of tabs )
{
if ( !tab.pinned )
browser.tabs.update(tab.id, {pinned:true})
}
var currentIdx = tabs.findIndex( tab => tab.id == current_tab )
if ( currentIdx == -1 )
{
prev_tab_id[current_window] = current_tab
}
try {
var prev_tab = await browser.tabs.get( prev_tab_id[current_window] )
tabs.push( prev_tab )
} catch (e) {}
var nextTabIdx = ( currentIdx + 1 ) % tabs.length
browser.tabs.update(tabs[nextTabIdx].id, { active: true, });
}
}
catch (e) { console.log(e) }
}
browser.browserAction.onClicked.addListener(onClick);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment