diff --git a/pages/options/options.css b/pages/options/options.css
index 39335a10..ee1bb0ff 100644
--- a/pages/options/options.css
+++ b/pages/options/options.css
@@ -143,6 +143,10 @@ body {
padding: 5px 9px;
}
+#button-copy-rule-set {
+ display: none;
+}
+
/**
* Links
*/
@@ -198,6 +202,10 @@ body {
margin-right: 14px;
}
+#generated-rules {
+ display: none;
+}
+
/**
* Right to Left
*/
diff --git a/pages/options/options.html b/pages/options/options.html
index d55e1043..a1af79a0 100644
--- a/pages/options/options.html
+++ b/pages/options/options.html
@@ -19,6 +19,8 @@
+
+
@@ -124,7 +126,20 @@
+
+
diff --git a/pages/options/options.js b/pages/options/options.js
index cc7ce9ad..0efb0266 100644
--- a/pages/options/options.js
+++ b/pages/options/options.js
@@ -84,6 +84,11 @@ options._registerOptionChangedEventListeners = function (elements) {
elements.disablePrefetch.addEventListener('change', options._onOptionChanged);
elements.stripMetadata.addEventListener('change', options._onOptionChanged);
elements.whitelistedDomains.addEventListener('keyup', options._onOptionChanged);
+ let type = elements.ruleSets;
+ for(let i = 0; i < type.length; i++) {
+ type[i].addEventListener('change', options._openRuleSet);
+ }
+ elements.copyRuleSet.addEventListener('click', options._copyRuleSet);
};
options._registerMiscellaneousEventListeners = function () {
@@ -124,7 +129,9 @@ options._getOptionElements = function () {
[Setting.BLOCK_MISSING]: options._getOptionElement(Setting.BLOCK_MISSING),
[Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH),
[Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA),
- [Setting.WHITELISTED_DOMAINS]: options._getOptionElement(Setting.WHITELISTED_DOMAINS)
+ [Setting.WHITELISTED_DOMAINS]: options._getOptionElement(Setting.WHITELISTED_DOMAINS),
+ ['ruleSets']: document.getElementsByName("rule-sets"),
+ ['copyRuleSet']: document.getElementById("button-copy-rule-set")
};
return optionElements;
@@ -225,6 +232,42 @@ options._onOptionChanged = function ({target}) {
});
};
+options._openRuleSet = function({target}) {
+
+ let urls = mappings;
+ let optionKey = target.getAttribute('data-option');
+ let optionType = target.getAttribute('value');
+
+ let textArea = document.getElementById("generated-rules");
+ let btnCopy = document.getElementById("button-copy-rule-set");
+
+ let content = "";
+ let ruleSyntax = "";
+
+ if (optionKey === "uMatrix") {
+ ruleSyntax = " script allow";
+ } else if (optionKey === "uBlock") {
+ ruleSyntax = " * noop";
+ }
+
+ textArea.style.display = "block";
+ btnCopy.style.display = "block";
+
+ for (var domain in urls) {
+ content += "* " + domain + ruleSyntax + '\n';
+ }
+ textArea.value = content.replace(/\n+$/, "");
+}
+
+options._copyRuleSet = function() {
+ let textArea = document.getElementById("generated-rules");
+ navigator.clipboard.writeText(textArea.value).then(function() {
+ textArea.select();
+ }, function() {
+ alert("Rule set cannot be copied!");
+ });
+}
+
/**
* Initializations
*/