@@ -21,6 +21,23 @@ var readLaterApp = (function(readLaterObject){
21
21
var clearBtn = document . getElementById ( "clearBtn" ) ;
22
22
var msg = document . getElementById ( "message" ) ;
23
23
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
+ } ;
24
41
25
42
var getTitle = function ( title ) {
26
43
if ( title . length > 50 ) {
@@ -89,6 +106,7 @@ var readLaterApp = (function(readLaterObject){
89
106
90
107
addBtn . addEventListener ( "click" , addURLFromTab ) ;
91
108
clearBtn . addEventListener ( "click" , clearAll ) ;
109
+ downloadBtn . addEventListener ( "click" , downloadAsJSON ) ;
92
110
93
111
var getIcon = function ( url ) {
94
112
var domain = url . replace ( 'http://' , '' ) . replace ( 'https://' , '' ) . split (
0 commit comments