diff options
| author | Teddy Wing | 2014-03-24 18:32:11 -0400 |
|---|---|---|
| committer | Teddy Wing | 2014-03-24 18:32:11 -0400 |
| commit | b5f69d0b3426e86507a88e6f3bda5e758a8fd497 (patch) | |
| tree | 3f6027e712cbfd689432532688fb4c6d325471a7 | |
| download | chrome-copy-urls-from-all-tabs-b5f69d0b3426e86507a88e6f3bda5e758a8fd497.tar.bz2 | |
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.
| -rw-r--r-- | background.js | 36 | ||||
| -rw-r--r-- | chrome-get-urls-from-tabs-in-windows.html | 20 | ||||
| -rw-r--r-- | chrome-get-urls-from-tabs-in-windows.js | 21 | ||||
| -rw-r--r-- | manifest.json | 20 | ||||
| -rw-r--r-- | page.js | 16 |
5 files changed, 113 insertions, 0 deletions
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 diff --git a/chrome-get-urls-from-tabs-in-windows.html b/chrome-get-urls-from-tabs-in-windows.html new file mode 100644 index 0000000..3d2fbf8 --- /dev/null +++ b/chrome-get-urls-from-tabs-in-windows.html @@ -0,0 +1,20 @@ +<!doctype html> +<html> +<head> + <title>Chrome Copy URLs From All Tabs</title> + + <style> + textarea { width: 600px; height: 900px; font-size: 13px; line-height: 1.6; } + + #header { font-weight: bold; } + </style> +</head> +<body> + <p id="header"></p> + + <textarea id="copy-area"></textarea> + + <script src="chrome-get-urls-from-tabs-in-windows.js"></script> + <script src="page.js"></script> +</body> +</html> diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js new file mode 100644 index 0000000..4fdcefb --- /dev/null +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -0,0 +1,21 @@ +var textarea = document.getElementById('copy-area'); + +chrome.windows.getAll({populate:true},function(windows){ + var w_index = 0; + + windows.forEach(function(window){ + textarea.value += "Window " + w_index + ":"; + + window.tabs.forEach(function(tab){ + //collect all of the urls here, I will just log them instead + //console.log(tab.url); + textarea.value += "\n\t"; + textarea.value += '* ' + tab.url + "\n"; + textarea.value += "\t\t" + '<a href="' + tab.url + '">' + tab.title + '</a>'; + }); + + textarea.value += "\n\n"; + + w_index++; + }); +});
\ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..635ea0e --- /dev/null +++ b/manifest.json @@ -0,0 +1,20 @@ +{ + "manifest_version": 2, + + "name": "Chrome Copy URLs From All Tabs", + "description": "What the name says", + "version": "0.0.1", + + "browser_action": { + + }, + + "background": { + "scripts": ["background.js"], + "persistent": false + }, + + "permissions": [ + "tabs" + ] +} @@ -0,0 +1,16 @@ +(function() { + var d = new Date(); + var date_string = + d.getFullYear() + + '' + + ('0' + (d.getMonth() + 1)).slice(-2) + + '' + + ('0' + d.getDate()).slice(-2) + + '-' + + d.getHours() + + 'h' + + d.getMinutes(); + + var header_text = 'chrome-tabs-' + date_string; + document.getElementById('header').innerHTML = header_text; +})();
\ No newline at end of file |
