aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background.js21
-rw-r--r--chrome-get-urls-from-tabs-in-windows.js4
-rw-r--r--manifest.json2
3 files changed, 23 insertions, 4 deletions
diff --git a/background.js b/background.js
index df2c829..b775258 100644
--- a/background.js
+++ b/background.js
@@ -30,7 +30,26 @@ chrome.extension.onConnect.addListener(function(port) {
});
});
+
+function download_backup_file () {
+ generate_backup_text(function(backup_text) {
+ create_download_link(backup_text, function(download_link) {
+ download_link.click()
+ });
+ });
+}
+
+
// Called when the user clicks on the browser action icon.
chrome.browserAction.onClicked.addListener(function(tab) {
- openOrFocusOptionsPage();
+ chrome.storage.sync.get(function(items) {
+ var behaviour = items.button_click_behaviour;
+
+ if (behaviour === 'download') {
+ download_backup_file();
+ }
+ else { // behaviour === 'window'
+ openOrFocusOptionsPage();
+ }
+ });
}); \ No newline at end of file
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);
});
};
diff --git a/manifest.json b/manifest.json
index 72f46bf..c08a1e6 100644
--- a/manifest.json
+++ b/manifest.json
@@ -12,7 +12,7 @@
"options_page": "options.html",
"background": {
- "scripts": ["background.js"],
+ "scripts": ["chrome-get-urls-from-tabs-in-windows.js", "background.js"],
"persistent": false
},