Skip to content

Commit

Permalink
tabutils: add support for single-tab copying & inline pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Jan 18, 2024
1 parent 947826c commit 9a2b7ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
28 changes: 27 additions & 1 deletion src/js/firefox/tabutils/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ chrome.commands.onCommand.addListener(function(command) {
copyTabs();
} else if (command === "pasteTabs") {
pasteTabs();
} else if (command === "copyCurrentTab") {
copyCurrentTab();
} else if (command === "pasteNextTab") {
pasteNextTab();
}
});

Expand All @@ -20,7 +24,29 @@ function pasteTabs()
let urls = clipboardData.split('\n');
urls.forEach(url => {
if (url.trim() !== '') {
chrome.tabs.create({ url: url });
chrome.tabs.create({ url: url, active: true });
}
});
});
}

function copyCurrentTab()
{
chrome.tabs.query({ currentWindow: true, active: true }, function(tabs) {
let tabInfo = `${tabs[0].title}: ${tabs[0].url}`;
writeToClipboard(tabInfo);
});
}

function pasteNextTab()
{
readFromClipboard(function(clipboardData) {
let urls = clipboardData.split('\n');
chrome.tabs.query({ currentWindow: true, active: true }, function(currentTabs) {
let currentTab = currentTabs[0];
let currentIndex = currentTab.index;
for (let i = 0; i < urls.length; i++) {
chrome.tabs.create({ url: urls[i], index: currentIndex + i + 1, active: true });
}
});
});
Expand Down
18 changes: 15 additions & 3 deletions src/js/firefox/tabutils/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "TabUtils",
"version": "1.0",
"version": "1.1.0",
"description": "Copy and paste tabs",
"permissions": ["tabs", "clipboardWrite", "clipboardRead"],
"background": {
Expand All @@ -16,15 +16,27 @@
"commands": {
"copyTabs": {
"suggested_key": {
"default": "Alt+C"
"default": "Alt+Z"
},
"description": "Copy titles and URLs of all tabs in the current window."
},
"pasteTabs": {
"suggested_key": {
"default": "Alt+X"
},
"description": "Paste URLs in clipboard as new tabs at the end."
},
"copyCurrentTab": {
"suggested_key": {
"default": "Alt+C"
},
"description": "Copy the current tab's title and URL."
},
"pasteNextTab": {
"suggested_key": {
"default": "Alt+V"
},
"description": "Paste URLs in clipboard as new tabs."
"description": "Paste URLs in clipboard as new tabs next to current."
}
}
}

0 comments on commit 9a2b7ba

Please sign in to comment.