Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions browser-extensions/chromium/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@

const BtProtoPrefix = "x-bt://";

async function openInBT(url) {
async function openInBT(tabId, url) {
const destUrl = BtProtoPrefix + url;
await chrome.tabs.create({ url: destUrl });
await chrome.tabs.update(tabId, { url: destUrl });
}

chrome.action.onClicked.addListener((activeTab) => {
const url = activeTab.url;
// as we are sending the url to BT, we can close the current tab
chrome.tabs.remove(activeTab.id);

openInBT(url);
openInBT(activeTab.id, url).then(() => {
// using a timeout because I can't find a reliable way to wait for the custom protocol to be handled
setTimeout(() => {
chrome.tabs.remove(activeTab.id);
}, 250);
});
});

// context menu item click handler
chrome.contextMenus.onClicked.addListener((info, tab) => {
const url = info.linkUrl;
openInBT(url);
openInBT(tab.id, url);
});

// add context menu item for a hyperlink (contexts: link)
Expand Down