From 4662fa06b4f13d52ad33cfa5fe793e75d01e10b2 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 25 Mar 2014 01:28:53 -0400 Subject: Generate a file download link to easily save the data --- chrome-get-urls-from-tabs-in-windows.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 4fdcefb..6f957cd 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -1,4 +1,6 @@ var textarea = document.getElementById('copy-area'); +var create_download_link; +var generate_filename; chrome.windows.getAll({populate:true},function(windows){ var w_index = 0; @@ -18,4 +20,33 @@ chrome.windows.getAll({populate:true},function(windows){ w_index++; }); -}); \ No newline at end of file + + create_download_link(textarea.value); +}); + + +create_download_link = function(text) { + var download_link = document.createElement('a'); + download_link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); + download_link.setAttribute('download', generate_filename()); + download_link.innerHTML = 'Download file'; + + document.querySelector('body').appendChild(download_link); +}; + + +generate_filename = function() { + var d = new Date(); + var date_string = + d.getFullYear() + + '' + + ('0' + (d.getMonth() + 1)).slice(-2) + + '' + + ('0' + d.getDate()).slice(-2) + + '-' + + ('0' + d.getHours()).slice(-2) + + 'h' + + d.getMinutes(); + + return 'chrome-tabs-' + date_string + '.txt'; +}; \ No newline at end of file -- cgit v1.2.3 From 8a6cae6d16075a2198177d1c678de17d7eed6f45 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 12:51:07 -0400 Subject: Add comment: where the file download code came from --- chrome-get-urls-from-tabs-in-windows.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 6f957cd..a689b0c 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -25,6 +25,8 @@ chrome.windows.getAll({populate:true},function(windows){ }); +// Adapted from: +// http://stackoverflow.com/a/18197511 create_download_link = function(text) { var download_link = document.createElement('a'); download_link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); -- cgit v1.2.3 From 9195a855b9f4a02440b70fe83addd37ff60b41ad Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 15:22:43 -0400 Subject: Page: update 'text' format output * Remove tags * Show page title and URL for each entry --- chrome-get-urls-from-tabs-in-windows.js | 41 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index a689b0c..0717a01 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -2,26 +2,39 @@ var textarea = document.getElementById('copy-area'); var create_download_link; var generate_filename; -chrome.windows.getAll({populate:true},function(windows){ + +chrome.windows.getAll({populate:true}, function(windows){ var w_index = 0; - windows.forEach(function(window){ - textarea.value += "Window " + w_index + ":"; + chrome.storage.sync.get(function(items) { + var format = items.file_format; + console.log(format); + + if (format === 'yaml') { + + } + else if (format === 'html') { + + } + else { // format === 'text' + windows.forEach(function(window){ + textarea.value += "Window " + w_index + ":"; + + window.tabs.forEach(function(tab){ + textarea.value += "\n"; + textarea.value += "\t* " + tab.title + "\n"; + textarea.value += "\t " + tab.url + "\n"; + }); - window.tabs.forEach(function(tab){ - //collect all of the urls here, I will just log them instead - //console.log(tab.url); - textarea.value += "\n\t"; - textarea.value += '* ' + tab.url + "\n"; - textarea.value += "\t\t" + '' + tab.title + ''; - }); + textarea.value += "\n\n"; - textarea.value += "\n\n"; + w_index++; + }); + } - w_index++; + + create_download_link(textarea.value); }); - - create_download_link(textarea.value); }); -- cgit v1.2.3 From b8aa3166e3ff74c93a97b02c204924f85b69d6be Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 16:10:01 -0400 Subject: Add YAML output --- chrome-get-urls-from-tabs-in-windows.js | 46 +++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 0717a01..eb2f3c1 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -8,13 +8,55 @@ chrome.windows.getAll({populate:true}, function(windows){ chrome.storage.sync.get(function(items) { var format = items.file_format; - console.log(format); if (format === 'yaml') { + var chrome_tabs = []; + windows.forEach(function(window){ + // var window_name = 'Window ' + w_index; + // + // window.tabs.forEach(function(tab){ + // var window_output = {}; + // window_output[window_name] = [ + // { + // page_title: tab.title, + // url: tab.url + // } + // ]; + // + // chrome_tabs.push(window_output); + // }); + + textarea.value += "- Window " + w_index + ":\n"; + + window.tabs.forEach(function(tab){ + textarea.value += " - page_title: '" + tab.title.replace('\'', '\'\'') + "'\n"; + textarea.value += " url: '" + tab.url + "'\n"; + }); + + textarea.value += "\n"; + + // console.log(chrome_tabs); + // console.log(YAML.stringify(chrome_tabs)); + //textarea.value = YAML.stringify(chrome_tabs); + + w_index++; + }); } else if (format === 'html') { - + windows.forEach(function(window){ + textarea.value += "Window " + w_index + ":"; + + window.tabs.forEach(function(tab){ + textarea.value += "\n"; + textarea.value += "\t* " + tab.title + "\n"; + textarea.value += "\t " + tab.url + "\n"; + }); + + textarea.value += "\n\n"; + + w_index++; + }); } else { // format === 'text' windows.forEach(function(window){ -- cgit v1.2.3 From 55f440c98dad4a4d5e1ab7c879c008c54a71555c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 16:10:46 -0400 Subject: Remove YAML library Since I'm now outputting YAML manually for better looks, get rid of the YAML serialiser I included previously. --- chrome-get-urls-from-tabs-in-windows.js | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index eb2f3c1..5516edd 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -13,20 +13,6 @@ chrome.windows.getAll({populate:true}, function(windows){ var chrome_tabs = []; windows.forEach(function(window){ - // var window_name = 'Window ' + w_index; - // - // window.tabs.forEach(function(tab){ - // var window_output = {}; - // window_output[window_name] = [ - // { - // page_title: tab.title, - // url: tab.url - // } - // ]; - // - // chrome_tabs.push(window_output); - // }); - textarea.value += "- Window " + w_index + ":\n"; window.tabs.forEach(function(tab){ @@ -36,10 +22,6 @@ chrome.windows.getAll({populate:true}, function(windows){ textarea.value += "\n"; - // console.log(chrome_tabs); - // console.log(YAML.stringify(chrome_tabs)); - //textarea.value = YAML.stringify(chrome_tabs); - w_index++; }); } -- cgit v1.2.3 From 3910c9f07a529924b3c157894f5d511ea5c6ac0b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 18:07:34 -0400 Subject: Append correct file extension depending on format For the download link, append a file extension appropriate to the type of file being downloaded. --- chrome-get-urls-from-tabs-in-windows.js | 58 +++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 5516edd..100c784 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -65,27 +65,45 @@ chrome.windows.getAll({populate:true}, function(windows){ // Adapted from: // http://stackoverflow.com/a/18197511 create_download_link = function(text) { - var download_link = document.createElement('a'); - download_link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); - download_link.setAttribute('download', generate_filename()); - download_link.innerHTML = 'Download file'; - - document.querySelector('body').appendChild(download_link); + generate_filename(function(filename) { + var download_link = document.createElement('a'); + download_link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); + download_link.setAttribute('download', filename); + download_link.innerHTML = 'Download file'; + + document.querySelector('body').appendChild(download_link); + }); }; -generate_filename = function() { - var d = new Date(); - var date_string = - d.getFullYear() - + '' - + ('0' + (d.getMonth() + 1)).slice(-2) - + '' - + ('0' + d.getDate()).slice(-2) - + '-' - + ('0' + d.getHours()).slice(-2) - + 'h' - + d.getMinutes(); - - return 'chrome-tabs-' + date_string + '.txt'; +generate_filename = function(callback) { + chrome.storage.sync.get(function(items) { + var format = items.file_format; + + var d = new Date(); + var date_string = + d.getFullYear() + + '' + + ('0' + (d.getMonth() + 1)).slice(-2) + + '' + + ('0' + d.getDate()).slice(-2) + + '-' + + ('0' + d.getHours()).slice(-2) + + 'h' + + d.getMinutes(); + + + var file_extension = ''; + if (format === 'yaml') { + file_extension = 'yml'; + } + else if (format === 'html') { + file_extension = 'html'; + } + else { + file_extension = 'txt'; + } + + callback('chrome-tabs-' + date_string + '.' + file_extension); + }); }; \ No newline at end of file -- cgit v1.2.3 From 2795d431059557d84cd0898b2eb6ab806a895fbf Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 18:09:06 -0400 Subject: Fix minute format of downloaded filename Add leading zero to minute. --- chrome-get-urls-from-tabs-in-windows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 100c784..7d0faad 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -90,7 +90,7 @@ generate_filename = function(callback) { + '-' + ('0' + d.getHours()).slice(-2) + 'h' - + d.getMinutes(); + + ('0' + d.getMinutes()).slice(-2); var file_extension = ''; -- cgit v1.2.3 From c1d8d6c29f885978fdb5f4adac3515606d100434 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 18:22:47 -0400 Subject: Generate HTML output --- chrome-get-urls-from-tabs-in-windows.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 7d0faad..aefab19 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -26,19 +26,35 @@ chrome.windows.getAll({populate:true}, function(windows){ }); } else if (format === 'html') { + textarea.value += '\n\ +\n\ +\n\ + \n'; + + textarea.value += ' Chrome Copy URLs From All Tabs\n'; + + textarea.value += '\n\ +\n\ +
\n'; + windows.forEach(function(window){ - textarea.value += "Window " + w_index + ":"; + textarea.value += "

Window " + w_index + ":

\n\n"; + textarea.value += " \n"; w_index++; }); + + textarea.value += '
\n\ +\n\ +'; } else { // format === 'text' windows.forEach(function(window){ -- cgit v1.2.3 From d239f03dcef8afe7f727b758e7c55c2f99c9c6a7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 18:35:28 -0400 Subject: Page: move download link to top Move the download link to the top of the page and style it. --- chrome-get-urls-from-tabs-in-windows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index aefab19..46a9e8a 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -87,7 +87,7 @@ create_download_link = function(text) { download_link.setAttribute('download', filename); download_link.innerHTML = 'Download file'; - document.querySelector('body').appendChild(download_link); + document.getElementById('download-link').appendChild(download_link); }); }; -- cgit v1.2.3 From 3cdd7ca2de7f9f4eb0fa134310b524d6c96debca Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 19:13:47 -0400 Subject: Refactor backup text Instead of updating the textarea directly, add the backup text to a string and assign that string to the textarea later. This allows us to add the text to a file for download on click of the extension button and outside the context of the extension's main page. --- chrome-get-urls-from-tabs-in-windows.js | 136 ++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 61 deletions(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 46a9e8a..0ed0d8f 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -1,79 +1,93 @@ var textarea = document.getElementById('copy-area'); +var generate_backup_text; var create_download_link; var generate_filename; -chrome.windows.getAll({populate:true}, function(windows){ - var w_index = 0; +generate_backup_text = function(callback) { + var backup_text = ''; - chrome.storage.sync.get(function(items) { - var format = items.file_format; + chrome.windows.getAll({populate:true}, function(windows){ + var w_index = 0; - if (format === 'yaml') { - var chrome_tabs = []; + chrome.storage.sync.get(function(items) { + var format = items.file_format; - windows.forEach(function(window){ - textarea.value += "- Window " + w_index + ":\n"; + if (format === 'yaml') { + var chrome_tabs = []; - window.tabs.forEach(function(tab){ - textarea.value += " - page_title: '" + tab.title.replace('\'', '\'\'') + "'\n"; - textarea.value += " url: '" + tab.url + "'\n"; - }); + windows.forEach(function(window){ + backup_text += "- Window " + w_index + ":\n"; + + window.tabs.forEach(function(tab){ + backup_text += " - page_title: '" + tab.title.replace('\'', '\'\'') + "'\n"; + backup_text += " url: '" + tab.url + "'\n"; + }); - textarea.value += "\n"; + backup_text += "\n"; + + w_index++; + }); + } + else if (format === 'html') { + backup_text += '\n\ + \n\ + \n\ + \n'; + + backup_text += ' Chrome Copy URLs From All Tabs\n'; - w_index++; - }); - } - else if (format === 'html') { - textarea.value += '\n\ -\n\ -\n\ - \n'; - - textarea.value += ' Chrome Copy URLs From All Tabs\n'; - - textarea.value += '\n\ -\n\ -
\n'; - - windows.forEach(function(window){ - textarea.value += "

Window " + w_index + ":

\n\n"; - textarea.value += " \n"; - - w_index++; - }); - - textarea.value += '
\n\ -\n\ -'; - } - else { // format === 'text' - windows.forEach(function(window){ - textarea.value += "Window " + w_index + ":"; - window.tabs.forEach(function(tab){ - textarea.value += "\n"; - textarea.value += "\t* " + tab.title + "\n"; - textarea.value += "\t " + tab.url + "\n"; + backup_text += ' \n\ + \n\ + '; + } + else { // format === 'text' + windows.forEach(function(window){ + backup_text += "Window " + w_index + ":"; + + window.tabs.forEach(function(tab){ + backup_text += "\n"; + backup_text += "\t* " + tab.title + "\n"; + backup_text += "\t " + tab.url + "\n"; + }); + + backup_text += "\n\n"; + + w_index++; }); - - textarea.value += "\n\n"; - - w_index++; - }); - } - - - create_download_link(textarea.value); + } + + + callback(backup_text); + }); + }); +}; + + +generate_backup_text(function(backup_text) { + textarea.value = backup_text; + + create_download_link(textarea.value, function(download_link) { + document.getElementById('download-link').appendChild(download_link); }); }); -- cgit v1.2.3 From 08781bc28dfa2bd517a0806eab65e6fa2f30974a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 19:19:12 -0400 Subject: Add functionality for downloading backup on icon click If the download option is set, a backup file is now downloaded when the extension button is clicked. --- chrome-get-urls-from-tabs-in-windows.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 0ed0d8f..fc27d1f 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -94,14 +94,14 @@ generate_backup_text(function(backup_text) { // Adapted from: // http://stackoverflow.com/a/18197511 -create_download_link = function(text) { +create_download_link = function(text, callback) { generate_filename(function(filename) { var download_link = document.createElement('a'); download_link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); download_link.setAttribute('download', filename); download_link.innerHTML = 'Download file'; - document.getElementById('download-link').appendChild(download_link); + callback(download_link); }); }; -- cgit v1.2.3 From 01fc18879850e420989a72dba24dc70bf621dc29 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 19:42:20 -0400 Subject: Move filename generation code Move code that generates the filename (without the extension) to a separate function so that we can get it in the header of the main page. --- chrome-get-urls-from-tabs-in-windows.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'chrome-get-urls-from-tabs-in-windows.js') diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index fc27d1f..c46fbf5 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -1,6 +1,7 @@ var textarea = document.getElementById('copy-area'); var generate_backup_text; var create_download_link; +var generate_file_string; var generate_filename; @@ -106,23 +107,27 @@ create_download_link = function(text, callback) { }; +generate_file_string = function() { + var d = new Date(); + var date_string = + d.getFullYear() + + '' + + ('0' + (d.getMonth() + 1)).slice(-2) + + '' + + ('0' + d.getDate()).slice(-2) + + '-' + + ('0' + d.getHours()).slice(-2) + + 'h' + + ('0' + d.getMinutes()).slice(-2); + + return 'chrome-tabs-' + date_string; +}; + + generate_filename = function(callback) { chrome.storage.sync.get(function(items) { var format = items.file_format; - var d = new Date(); - var date_string = - d.getFullYear() - + '' - + ('0' + (d.getMonth() + 1)).slice(-2) - + '' - + ('0' + d.getDate()).slice(-2) - + '-' - + ('0' + d.getHours()).slice(-2) - + 'h' - + ('0' + d.getMinutes()).slice(-2); - - var file_extension = ''; if (format === 'yaml') { file_extension = 'yml'; @@ -134,6 +139,6 @@ generate_filename = function(callback) { file_extension = 'txt'; } - callback('chrome-tabs-' + date_string + '.' + file_extension); + callback(generate_file_string() + '.' + file_extension); }); }; \ No newline at end of file -- cgit v1.2.3