Merge remote-tracking branch 'origin/master'

* origin/master:
  update version
  feedback from wil
  a tabs example
This commit is contained in:
Will Bamberg
2016-02-19 13:05:45 -08:00
5 changed files with 88 additions and 0 deletions

8
tabs-tabs-tabs/README.md Normal file
View 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.

View File

@@ -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"
}

3
tabs-tabs-tabs/tabs.css Normal file
View File

@@ -0,0 +1,3 @@
html, body {
width: 350px;
}

18
tabs-tabs-tabs/tabs.html Normal file
View File

@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="tabs.css"/>
</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
View 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);
});
}
});