[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Add the capability of creating and restoring backups of the user
From: |
Autumn64 |
Subject: |
[PATCH] Add the capability of creating and restoring backups of the user's whitelisted and blacklisted websites |
Date: |
Tue, 23 Jan 2024 11:33:11 -0600 |
---
NEWS | 4 ++
html/preferences_panel/pref.js | 51 ++++++++++++++++++-
html/preferences_panel/preferences_panel.html | 8 +++
html/preferences_panel/prefs.css | 12 +++++
manifest.json | 2 +-
package.json | 7 +++
6 files changed, 82 insertions(+), 2 deletions(-)
create mode 100644 package.json
diff --git a/NEWS b/NEWS
index d4b730c..27b130f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+New in 7.21.2
+ * Add the capability of creating and restoring backups of the user's
+ whitelisted and blacklisted websites
+
New in 7.21.1
* Fix eval loophole with Function constructor
diff --git a/html/preferences_panel/pref.js b/html/preferences_panel/pref.js
index d90e72e..5c52447 100644
--- a/html/preferences_panel/pref.js
+++ b/html/preferences_panel/pref.js
@@ -215,6 +215,53 @@
options.appendChild(option);
}
widget.appendChild(options);
+ },
+
+ createBackup(){
+ this.syncAll();
+ browser.storage.local.get(["pref_whitelist",
"pref_blacklist"]).then((result) =>{
+ const whitelisted = result.pref_whitelist || "";
+ const blacklisted = result.pref_blacklist || "";
+
+ const backup_data = JSON.stringify({
+ pref_whitelist: whitelisted,
+ pref_blacklist: blacklisted
+ });
+ const blob = new Blob([backup_data], {type: "application/json"});
+ const link = document.createElement("a");
+ link.href = URL.createObjectURL(blob);
+ link.download = "librejs_backup.json";
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ });
+ },
+
+ restoreBackup(){
+ const input = document.getElementById("fileInput");
+ input.click();
+
+ input.addEventListener("change", (event) =>{
+ const file = event.target.files[0];
+
+ if (!file) return;
+
+ const reader = new FileReader();
+ reader.onload = (e) =>{
+ const content = e.target.result;
+ const data = JSON.parse(content);
+ if (data.pref_whitelist === undefined || data.pref_blacklist ===
undefined) return;
+
+ const realData = {
+ pref_whitelist: data.pref_whitelist,
+ pref_blacklist: data.pref_blacklist
+ }
+ browser.storage.local.set(realData);
+ this.syncAll();
+ };
+
+ reader.readAsText(file);
+ });
}
};
@@ -257,10 +304,12 @@
click(e) {
const { target } = e;
- const match = /^cmd-(white|black|delete)(list-site)?/.exec(target.id);
+ const match = /^cmd-(white|black|delete)(list-site)?/.exec(target.id) ||
/^cmd-(create|restore)(backup)?/.exec(target.id);
if (!match) return;
e.preventDefault();
const cmd = match[1];
+ if (cmd === "create") Controller.createBackup();
+ if (cmd === "restore") Controller.restoreBackup();
if (cmd === "delete") {
Controller.deleteSelection();
return;
diff --git a/html/preferences_panel/preferences_panel.html
b/html/preferences_panel/preferences_panel.html
index 081ae07..98458ed 100644
--- a/html/preferences_panel/preferences_panel.html
+++ b/html/preferences_panel/preferences_panel.html
@@ -76,6 +76,14 @@
<label for="pref_body">Body</label>
<textarea id="pref_body" rows="5"></textarea>
</fieldset>
+
+ <fieldset id="backup"><legend>Create or restore a backup of your allowed
and blocked websites</legend>
+ <div id="backup-buttons">
+ <button id="cmd-create-backup" title="Create a backup">Create a
backup</button>
+ <input type="file" id="fileInput" accept=".json" style="display:
none;">
+ <button id="cmd-restore-backup" title="Restore a backup">Restore a
backup</button>
+ </div>
+ </fieldset>
</div>
</body>
</html>
diff --git a/html/preferences_panel/prefs.css b/html/preferences_panel/prefs.css
index 6e2d206..1472ff6 100644
--- a/html/preferences_panel/prefs.css
+++ b/html/preferences_panel/prefs.css
@@ -75,6 +75,18 @@ input[type="text"] {
display: flex;
flex: 2;
}
+
+#backup-buttons{
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+#backup-buttons button{
+ margin-left: 8px;
+ margin-right: 8px;
+}
+
.error-msg {
color: red;
}
diff --git a/manifest.json b/manifest.json
index 73bc918..c522893 100644
--- a/manifest.json
+++ b/manifest.json
@@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "GNU LibreJS",
"short_name": "LibreJS",
- "version": "7.21.1",
+ "version": "7.21.2",
"author": "various",
"description": "Only allows free and/or trivial Javascript to run.",
"applications": {
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..a36060e
--- /dev/null
+++ b/package.json
@@ -0,0 +1,7 @@
+{
+ "dependencies": {
+ "acorn-loose": "^8.4.0",
+ "browserify": "^17.0.0",
+ "jssha": "^3.3.1"
+ }
+}
--
2.43.0
- [PATCH] Add the capability of creating and restoring backups of the user's whitelisted and blacklisted websites,
Autumn64 <=