diff --git a/tabs-tabs-tabs/README.md b/tabs-tabs-tabs/README.md new file mode 100644 index 0000000..9bacd34 --- /dev/null +++ b/tabs-tabs-tabs/README.md @@ -0,0 +1,8 @@ +# tabs, tabs, tabs + +This extension includes: + +* a browser action +* a page "tabs.html" with a script "tabs.js" + +It shows a list of tab methods that you can perform on the active tab. diff --git a/tabs-tabs-tabs/manifest.json b/tabs-tabs-tabs/manifest.json new file mode 100644 index 0000000..6877e80 --- /dev/null +++ b/tabs-tabs-tabs/manifest.json @@ -0,0 +1,17 @@ +{ + "applications": { + "gecko": { + "id": "tabs-tabs-tabs@mozilla.org", + "strict_min_version": "47.0a1" + } + }, + "browser_action": { + "default_title": "Tabs, tabs, tabs", + "default_popup": "tabs.html" + }, + "description": "A list of methods you can perform on a tab.", + "homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/tabs-tabs-tabs", + "manifest_version": 2, + "name": "Tabs, tabs, tabs", + "version": "1.0" +} diff --git a/tabs-tabs-tabs/tabs.css b/tabs-tabs-tabs/tabs.css new file mode 100644 index 0000000..8620216 --- /dev/null +++ b/tabs-tabs-tabs/tabs.css @@ -0,0 +1,3 @@ +html, body { + width: 350px; +} diff --git a/tabs-tabs-tabs/tabs.html b/tabs-tabs-tabs/tabs.html new file mode 100644 index 0000000..f398378 --- /dev/null +++ b/tabs-tabs-tabs/tabs.html @@ -0,0 +1,18 @@ + + + + + + + + + + Move active tab to the beginning of the window
+ Move active tab to the end of the window
+ Duplicate active tab
+ Reload active tab
+ Remove active tab
+ + + + diff --git a/tabs-tabs-tabs/tabs.js b/tabs-tabs-tabs/tabs.js new file mode 100644 index 0000000..38919e6 --- /dev/null +++ b/tabs-tabs-tabs/tabs.js @@ -0,0 +1,42 @@ +document.addEventListener("click", function(e) { + function callOnActiveTab(callback) { + chrome.tabs.query({}, function(tabs) { + for (var tab of tabs) { + if (tab.active) { + callback(tab); + } + } + }); + } + + if (e.target.id === "tabs-move-beginning") { + callOnActiveTab((tab) => { + chrome.tabs.move([tab.id], {index: 0}); + }); + } + + if (e.target.id === "tabs-move-end") { + callOnActiveTab((tab) => { + chrome.tabs.move([tab.id], {index: -1}); + }); + } + + else if (e.target.id === "tabs-duplicate") { + callOnActiveTab((tab) => { + chrome.tabs.duplicate(tab.id); + }); + } + + else if (e.target.id === "tabs-reload") { + callOnActiveTab((tab) => { + chrome.tabs.reload(tab.id); + }); + } + + else if (e.target.id === "tabs-remove") { + callOnActiveTab((tab) => { + chrome.tabs.remove(tab.id); + }); + } + +});