Skip to content

Commit

Permalink
starter code for chrome tab api
Browse files Browse the repository at this point in the history
  • Loading branch information
felixs8696 committed Dec 25, 2016
1 parent 7de7458 commit e1afe88
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
key/*
node_modules/*
Binary file added favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<!--
This page is shown when the extension button is clicked, because the
"browser_action" field in manifest.json contains the "default_popup" key with
value "popup.html".
-->
<html>
<head>
<title>Voice Web by Launchpad</title>
<style>
body {
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
font-size: 100%;
}
#status {
/* avoid an excessively wide status text */
white-space: pre;
text-overflow: ellipsis;
overflow: hidden;
max-width: 400px;
}
</style>
<script src="index.js"></script>
<script src="tabs.js"></script>
</head>
<body>
<div id="status"></div>
<img id="image-result" hidden>
</body>
</html>
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var debug = true;

function renderStatus(statusText) {
document.getElementById('status').textContent = statusText;
}

function log(obj) {
if (debug) console.log(obj);
}
18 changes: 18 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"manifest_version": 2,

"name": "Voice Web",
"description": "A Launchpad app that browses the web using your voice",
"version": "1.0",

"browser_action": {
"default_icon": "favicon-16x16.png",
"default_popup": "index.html"
},
"permissions": [
"activeTab",
"tabs",
"extension",
"https://ajax.googleapis.com/"
]
}
40 changes: 40 additions & 0 deletions tabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function getCurrentTabUrl(callback) {
var queryInfo = { active: true, currentWindow: true };

chrome.tabs.query(queryInfo, function(tabs) {
// get active tab
var tab = tabs[0];
var url = tab.url;
log(tab);
console.assert(typeof url == 'string', 'tab.url should be a string');
callback(url);
});
}

function openNewTab(props, callback) {
// var props = {
// windowId: 'windowToBeOpenedIn',
// index: 'intendedTabPosition',
// url: url,
// active: true,
// selected: true,
// pinned: false,
// openerTabId: null
// };

chrome.tabs.create(props, function(tab) {
callback(tab);
});
}

document.addEventListener('DOMContentLoaded', function() {
getCurrentTabUrl(function(url) {
renderStatus('Current Tab URL: ' + url);
});

// API Examples
// openNewTab({url:"http://www.google.com"}, function(tab) {
// log(tab);
// });

});

0 comments on commit e1afe88

Please sign in to comment.