aboutsummaryrefslogtreecommitdiff
path: root/html/DOM_helpers.js
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-08-06 17:17:45 +0200
committerWojtek Kosior <koszko@koszko.org>2021-08-06 17:17:45 +0200
commit792fbe187bdffca4a748e88d66ea29f8936ae5c8 (patch)
tree5ccc504bd06cbae6bba12bc4f2e060fa2ad96ec3 /html/DOM_helpers.js
parent90896bcfeb4e55c78d9a15700a6a4580f0df6365 (diff)
downloadbrowser-extension-792fbe187bdffca4a748e88d66ea29f8936ae5c8.tar.gz
browser-extension-792fbe187bdffca4a748e88d66ea29f8936ae5c8.zip
Facilitate installation of scripts from the repository
This commit includes: * removal of page_info_server * running of storage client in popup context * extraction of some common CSS to a separate file * extraction of scripts import view to a separate file * addition of a facility to conveniently clone complex structures from DOM (in DOM_helpers.js) * addition of hydrilla repo url to default settings * other minor changes and of course changes related to the actual installation of scripts from the repo
Diffstat (limited to 'html/DOM_helpers.js')
-rw-r--r--html/DOM_helpers.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/html/DOM_helpers.js b/html/DOM_helpers.js
new file mode 100644
index 0000000..2bff966
--- /dev/null
+++ b/html/DOM_helpers.js
@@ -0,0 +1,41 @@
+/**
+ * Hachette operations on DOM elements
+ *
+ * Copyright (C) 2021 Wojtek Kosior
+ * Redistribution terms are gathered in the `copyright' file.
+ */
+
+function by_id(id)
+{
+ return document.getElementById(id);
+}
+
+function clone_template(template_id)
+{
+ const clone = document.getElementById(template_id).cloneNode(true);
+ const result_object = {};
+ const to_process = [clone];
+
+ while (to_process.length > 0) {
+ const element = to_process.pop();
+ const template_key = element.getAttribute("data-template");
+
+ if (template_key)
+ result_object[template_key] = element;
+
+ element.removeAttribute("id");
+ element.removeAttribute("template_key");
+
+ for (const child of element.children)
+ to_process.push(child);
+ }
+
+ return result_object;
+}
+
+/*
+ * EXPORTS_START
+ * EXPORT by_id
+ * EXPORT clone_template
+ * EXPORTS_END
+ */