Skip to content

Instantly share code, notes, and snippets.

@icio icio/manifest.json

Created Mar 17, 2011
Embed
What would you like to do?
Chrome extension to list all tab locations and copy them to the clipboard
{
"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"]
}
<!--
===============================
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>
@icio

This comment has been minimized.

Copy link
Owner Author

icio commented Mar 17, 2011

famfamfam_silk_cut_tab.png: Icon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.