From b5f69d0b3426e86507a88e6f3bda5e758a8fd497 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 24 Mar 2014 18:32:11 -0400 Subject: Initial commit: initial working version From 2014.03.17. Clicking on the extension's icon button opens a new tab containing a textarea with all URLs in open tabs collected by window. --- background.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 background.js (limited to 'background.js') diff --git a/background.js b/background.js new file mode 100644 index 0000000..df2c829 --- /dev/null +++ b/background.js @@ -0,0 +1,36 @@ +// Taken from: +// http://adamfeuer.com/notes/2013/01/26/chrome-extension-making-browser-action-icon-open-options-page/ + +function openOrFocusOptionsPage() { + var optionsUrl = chrome.extension.getURL('options.html'); + chrome.tabs.query({}, function(extensionTabs) { + var found = false; + for (var i=0; i < extensionTabs.length; i++) { + if (optionsUrl == extensionTabs[i].url) { + found = true; + console.log("tab id: " + extensionTabs[i].id); + chrome.tabs.update(extensionTabs[i].id, {"selected": true}); + } + } + if (found == false) { + chrome.tabs.create({url: "chrome-get-urls-from-tabs-in-windows.html"}); + } + }); +} + +chrome.extension.onConnect.addListener(function(port) { + var tab = port.sender.tab; + // This will get called by the content script we execute in + // the tab as a result of the user pressing the browser action. + port.onMessage.addListener(function(info) { + var max_length = 1024; + if (info.selection.length > max_length) + info.selection = info.selection.substring(0, max_length); + openOrFocusOptionsPage(); + }); +}); + +// Called when the user clicks on the browser action icon. +chrome.browserAction.onClicked.addListener(function(tab) { + openOrFocusOptionsPage(); +}); \ No newline at end of file -- cgit v1.2.3