mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 23:08:33 +02:00
a tabs example
This commit is contained in:
8
tabs-tabs-tabs/README.md
Normal file
8
tabs-tabs-tabs/README.md
Normal file
@@ -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.
|
||||
17
tabs-tabs-tabs/manifest.json
Normal file
17
tabs-tabs-tabs/manifest.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Tabs, tabs, tabs",
|
||||
"version": "0.1",
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "tabs-tabs-tabs@mozilla.org"
|
||||
}
|
||||
},
|
||||
"browser_action": {
|
||||
"default_title": "Tabs, tabs, tabs",
|
||||
"default_popup": "tabs.html"
|
||||
},
|
||||
"permissions": [
|
||||
"tabs"
|
||||
]
|
||||
}
|
||||
17
tabs-tabs-tabs/tabs.html
Normal file
17
tabs-tabs-tabs/tabs.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<a href="#" id="tabs-move-beginning">Move active tab to the beginning of the window</a><br>
|
||||
<a href="#" id="tabs-move-end">Move active tab to the end of the window</a><br>
|
||||
<a href="#" id="tabs-duplicate">Duplicate active tab</a><br>
|
||||
<a href="#" id="tabs-reload">Reload active tab</a><br>
|
||||
<a href="#" id="tabs-remove">Remove active tab</a><br>
|
||||
<script src="tabs.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
42
tabs-tabs-tabs/tabs.js
Normal file
42
tabs-tabs-tabs/tabs.js
Normal file
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user