From 7e286495065bf1970fad1c0478a5b39cbf58af8e Mon Sep 17 00:00:00 2001
From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com>
Date: Sun, 8 Mar 2020 19:45:19 +0100
Subject: [PATCH] Update custom sites UI (export/import)
Import custom sites only works from add-ons screen (via icon/popup gives CSP-error).
Plus some cosmetic updates in options.
---
options.html | 6 ++---
options_custom.html | 3 +++
options_custom.js | 56 +++++++++++++++++++++++++++++++++++++++------
popup.html | 4 +++-
version.js | 2 +-
5 files changed, 59 insertions(+), 12 deletions(-)
diff --git a/options.html b/options.html
index 79167b3..03422c0 100644
--- a/options.html
+++ b/options.html
@@ -14,7 +14,7 @@
- Options | |
+ Options |
Selected sites will have their cookies cleared and referer set to Google. You should
uncheck sites you have an account with or else you will be logged out at every visit.
@@ -27,10 +27,10 @@
-
+
-
+
diff --git a/options_custom.html b/options_custom.html
index fb62b1e..973a5f7 100644
--- a/options_custom.html
+++ b/options_custom.html
@@ -51,6 +51,9 @@
+
+
+
diff --git a/options_custom.js b/options_custom.js
index 3247cb0..0efe906 100644
--- a/options_custom.js
+++ b/options_custom.js
@@ -20,6 +20,46 @@ function save_options() {
});
}
+// Export custom sites to file
+function export_options() {
+ browser.storage.sync.get({
+ sites_custom: {}
+ }, function (items) {
+ var result = JSON.stringify(items.sites_custom);
+ var a = document.createElement("a");
+ var file = new Blob([result], {type: "text/plain"});
+ a.href = window.URL.createObjectURL(file);
+ let date = new Date();
+ let dateStr = new Date(date.getTime() - (date.getTimezoneOffset() * 60000 )).toISOString().split("T")[0];
+ a.download = 'bypass_paywalls_clean_custom_' + dateStr + '.txt';
+ a.click();
+ });
+}
+
+// Import custom sites from file
+function import_options(e) {
+ var files = e.target.files;
+ var reader = new FileReader();
+ reader.onload = _imp;
+ reader.readAsText(files[0]);
+}
+
+function _imp() {
+ let sites_custom = JSON.parse(this.result);
+ browser.storage.sync.set({
+ sites_custom: sites_custom
+ }, function () {
+ // Update status to let user know custom sites were imported.
+ var status = document.getElementById('status');
+ status.textContent = 'Custom sites imported.';
+ setTimeout(function () {
+ //status.textContent = '';
+ importInput.value = '';
+ renderOptions();
+ }, 800);
+ });
+}
+
// Add custom site to browser.storage
function add_options() {
var gh_url = document.getElementById('add_site').value;
@@ -62,16 +102,14 @@ function add_options() {
var status = document.getElementById('status');
status.textContent = 'Site added.';
setTimeout(function () {
- status.textContent = '';
+ //status.textContent = '';
renderOptions();
- //location.href = 'options.html';
- //window.close();
}, 800);
});
});
}
-// Delete custom site to browser.storage
+// Delete custom site from browser.storage
function delete_options() {
var gh_url = document.getElementById('custom_sites').value;
var selectEl = document.querySelector('#custom_sites select');
@@ -94,8 +132,6 @@ function delete_options() {
setTimeout(function () {
status.textContent = '';
renderOptions();
- //location.href = 'options.html';
- //window.close();
}, 800);
});
});
@@ -135,7 +171,10 @@ function renderOptions() {
if (add_checkboxes[key]) {
inputEl.type = 'checkbox';
inputEl.dataset.value = 1;
- }
+ } else if (key === 'title') {
+ inputEl.placeholder = 'Example';
+ } else if (key === 'domain')
+ inputEl.placeholder = 'example.com';
labelEl.appendChild(document.createTextNode(' ' + key));
add_sitesEl.appendChild(labelEl);
}
@@ -164,5 +203,8 @@ function renderOptions() {
document.addEventListener('DOMContentLoaded', renderOptions);
document.getElementById('save').addEventListener('click', save_options);
+document.getElementById('export').addEventListener('click', export_options);
+document.getElementById('import').onclick = function () {importInput.click()}
+document.getElementById('importInput').addEventListener("change", import_options, false);
document.getElementById('add').addEventListener('click', add_options);
document.getElementById('delete').addEventListener('click', delete_options);
\ No newline at end of file
diff --git a/popup.html b/popup.html
index ff2bfd9..b5d437f 100644
--- a/popup.html
+++ b/popup.html
@@ -5,7 +5,9 @@
+
Options |
+GitHub
+