Created
March 17, 2011 17:44
-
-
Save icio/874773 to your computer and use it in GitHub Desktop.
Chrome extension to list all tab locations and copy them to the clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Open URL Collector", | |
"version": "1.0", | |
"description": "Creates a list of the URLs of open tabs.", | |
"browser_action": { | |
"default_icon": "famfamfam_silk_cut_tab.png", | |
"popup": "popup.html" | |
}, | |
"permissions": ["tabs"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
=============================== | |
SCRIPT | |
=============================== | |
--> | |
<script type="text/javascript"> | |
/** | |
* The URLs | |
*/ | |
var urls = []; | |
/** | |
* Gather the information from the open tabs and construct the popup. | |
*/ | |
function generate(tabs) | |
{ | |
/* | |
* The function has been called without an array of tabs, so we much | |
* request them from Chrome, which will call the function again | |
* correctly with an array of the tabs open. | |
*/ | |
if (!(tabs instanceof Array)) | |
{ | |
chrome.tabs.getAllInWindow(null, generate); | |
} | |
/* | |
* The function has been called with an array of tabs. | |
*/ | |
else | |
{ | |
var output = document.getElementById('output'); | |
var counter = document.getElementById('counter'); | |
// Reset the URLs | |
urls = []; | |
for (var i = 0; i < tabs.length; i++) | |
{ | |
// Add the URL to the list | |
urls.push(tabs[i].url); | |
var url = urls[i]; | |
// Add the URL to the output | |
output.appendChild(document.createElement("li")).innerHTML = url; | |
} | |
// Update the counter | |
counter.innerHTML = urls.length; | |
} | |
} | |
/** | |
* Copy the generated content to the clipboard. | |
*/ | |
function copy(text) | |
{ | |
var clip = document.getElementById('clip'); | |
// Default the clipboard text to that of the URLs separated by a \n | |
if (text === undefined) | |
text = urls.join("\n"); | |
// Set the clipboard text | |
clip.value = text; | |
clip.select(); | |
document.execCommand('Copy'); | |
} | |
/** | |
* Entry point | |
*/ | |
window.onload = function() { | |
generate(); | |
}; | |
</script> | |
<!-- | |
=============================== | |
STYLE | |
=============================== | |
--> | |
<style type="text/css"> | |
#clip { | |
position: absolute; | |
width: 10px; | |
left: -20px; | |
} | |
body { | |
font-family: sans-serif; | |
font-size: 0.8em; | |
} | |
h1 { | |
margin: 0; | |
padding: 5px 0 0 0; | |
font-size: 12px; | |
float: left; | |
} | |
button { | |
margin: 0 0 5px 0; | |
float: right; | |
padding: 3px 5px; | |
font-size: 0.8em; | |
} | |
#output { | |
width: 200px; | |
overflow-x: scroll; | |
margin: 0; | |
padding: 5px; | |
list-style-type: none; | |
background-color: #EEE; | |
border: 1px solid #CCC; | |
font-family: sans-serif; | |
font-size: 0.8em; | |
} | |
#output li { | |
margin: 0; | |
padding: 0; | |
overflow-x: visible; | |
white-space: pre; | |
} | |
</style> | |
<!-- | |
=============================== | |
DOCUMENT | |
=============================== | |
--> | |
<textarea id="clip"></textarea> | |
<button onclick="copy();" title="Copy the open tabs' URLs to the clipboard.">Copy</button> | |
<h1><span id="counter">#</span> tabs open</h1> | |
<ul id="output"></ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
famfamfam_silk_cut_tab.png
: