Skip to content

Commit 5d6add6

Browse files
committed
Allow download as JSON and some UI fixes
- Allow download as JSON. Fixes #13 - Make the title smaller on the popup. Saves space.
1 parent db2b25b commit 5d6add6

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/popup.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
<div id="links-wrap">
3030
<ul id="links"></ul>
3131
</div>
32-
<div id="source">View Source at: <a target="_blank" href="https://github.com/napsternxg/ReadLater">Github</a> |
33-
<a target="_blank" href="http://smexyyweby.wordpress.com/readlater/">FAQ</a></div>
32+
<div id="downloadContainer">
33+
</div>
34+
<div id="source">
35+
<a target="_blank" href="https://github.com/napsternxg/ReadLater" title="View source code">Github</a> |
36+
<a target="_blank" href="http://smexyyweby.wordpress.com/readlater/" title="View frequently asked questions">FAQ</a> |
37+
<a id="downloadAsJSON" title="Click to download all the stored links as a JSON file">Download as JSON</a>
38+
</div>
3439
<script src="core.js"></script>
3540
<script src="popup.js"></script>
3641
</body>

src/popup.js

+18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ var readLaterApp = (function(readLaterObject){
2121
var clearBtn = document.getElementById("clearBtn");
2222
var msg = document.getElementById("message");
2323
var links = document.getElementById("links");
24+
var downloadBtn = document.getElementById("downloadAsJSON");
25+
var downloadContainer = document.getElementById('downloadContainer');
26+
27+
var downloadAsJSON = function(){
28+
readLaterObject.getValidSyncItems(function(syncItems){
29+
console.log("Downloading items");
30+
var downloadDataLink = document.createElement("a");
31+
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(syncItems, 0, 2));
32+
downloadDataLink.setAttribute("style", "display: none");
33+
downloadDataLink.setAttribute("href", dataStr);
34+
downloadDataLink.setAttribute("download", "ReadLater-data.json");
35+
36+
downloadContainer.appendChild(downloadDataLink);
37+
downloadDataLink.click();
38+
downloadDataLink.remove();
39+
});
40+
};
2441

2542
var getTitle = function(title){
2643
if (title.length > 50){
@@ -89,6 +106,7 @@ var readLaterApp = (function(readLaterObject){
89106

90107
addBtn.addEventListener("click", addURLFromTab);
91108
clearBtn.addEventListener("click", clearAll);
109+
downloadBtn.addEventListener("click", downloadAsJSON);
92110

93111
var getIcon = function(url) {
94112
var domain = url.replace('http://', '').replace('https://', '').split(

src/style.css

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ body {
44
}
55
#header h1{
66
color: #555;
7-
font-size: 32px;
7+
font-size: 24px;
88
text-transform: uppercase;
99
padding: 0;
1010
margin: 0;
@@ -30,6 +30,12 @@ body {
3030
clear: left;
3131
}
3232

33+
#downloadAsJSON{
34+
text-decoration: underline;
35+
cursor: pointer;
36+
cursor: hand;
37+
}
38+
3339
#links{
3440
list-style: none;
3541
padding: 0;

0 commit comments

Comments
 (0)