Navigation Menu

Skip to content

Commit

Permalink
implement copy all tabs as list markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkxin committed Mar 1, 2012
1 parent e9d256b commit 6df82a7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
37 changes: 37 additions & 0 deletions browser-action-popup.html
Expand Up @@ -44,6 +44,13 @@ <h1>Current Tab</h1>
<li id="current-tab-link-with-identifier"><code>[title][<em>identifier</em>]</code></li>
</ul>
</div>

<div id="all-tabs">
<h1>All Tabs as List</h1>
<ul class="menu">
<li id="all-tabs-link-as-list"><code>* [title](url)</code></li>
</ul>
</div>
</div>

<script type="text/javascript">
Expand Down Expand Up @@ -89,5 +96,35 @@ <h1>Current Tab</h1>
});
});
})

document.getElementById("all-tabs-link-as-list").addEventListener("click", function() {
chrome.windows.getCurrent(function (currentWindow) {
chrome.tabs.query({
windowId: currentWindow.id
}, function(tabs) {
var links = [];
for(var i in tabs) {
var tab = tabs[i];
links.push({
title: tab.title,
url: tab.url
});
}

chrome.extension.sendRequest({
action: "copyLinksAsListMarkdown",
params: {
links: links,
options: {
use_identifier: false
}
}
}, function(response) {
resultContainer.value = response.markdown;
console.log(response);
});
});
});
});
})();
</script>
17 changes: 17 additions & 0 deletions copy-as-markdown.js
Expand Up @@ -43,6 +43,19 @@
return markdown;
}

this.copyLinksAsListMarkdown = function(links, options) {
var md_list = [];
for(var i in links) {
var md = linkTo(links[i].title, links[i].url, options);
md_list.push("* " + md);
}

var markdown = md_list.join("\n");
setMarkdownResult(markdown);
copyMarkdownCodeToClipboard(markdown);
return markdown;
};

this.copyImageAsMarkdown = function(title, url) {
var markdown = imageFor(title, url);
setMarkdownResult(markdown);
Expand All @@ -58,6 +71,10 @@
var md = CopyAsMarkdown.copyLinkAsMarkdown(request.params.title, request.params.url, request.params.options);
sendResponse({markdown: md});
break;
case "copyLinksAsListMarkdown":
var md = CopyAsMarkdown.copyLinksAsListMarkdown(request.params.links, request.params.options);
sendResponse({markdown: md});
break;
default:
sendResponse({error: "Unknown Action " + request.action });
break;
Expand Down

0 comments on commit 6df82a7

Please sign in to comment.