aboutsummaryrefslogtreecommitdiffstats
path: root/data/settings/js
diff options
context:
space:
mode:
Diffstat (limited to 'data/settings/js')
-rw-r--r--data/settings/js/form-row.js118
-rw-r--r--data/settings/js/form-types.js145
-rw-r--r--data/settings/js/pagescript-emitter.js14
-rw-r--r--data/settings/js/pagescript-listener.js51
-rw-r--r--data/settings/js/permafrost-info-box.js21
5 files changed, 349 insertions, 0 deletions
diff --git a/data/settings/js/form-row.js b/data/settings/js/form-row.js
new file mode 100644
index 0000000..35ac85e
--- /dev/null
+++ b/data/settings/js/form-row.js
@@ -0,0 +1,118 @@
+/**
+ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
+ * *
+ * Copyright (C) 2011, 2012, 2014 Loic J. Duros
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+var GenerateForm = {
+ $trContainer: null, // will jQuery element for rules table tboby
+ le: 0,
+ init: function () {
+ var that = this;
+ $(document).ready(function (e) {
+ that.$trContainer = $("#whitelist").children('tbody');
+
+ // listen for when data is ready to populate form.
+ document.documentElement.addEventListener(
+ "populate-form",
+ function (event) {
+ that.populateForm(event.detail.data);
+ }, false);
+ that.$trContainer.on("click", ".delete", function (event) {
+ that.deleteRow($(this));
+ });
+ $('.librejs-whitelist-reset').click(function (e) {
+ that.deleteAll();
+ });
+ });
+ },
+
+ deleteAll: function () {
+ var event = document.createEvent("CustomEvent");
+ event.initCustomEvent(
+ "librejs-settings-change", true, true, {
+ event: 'rules-form-delete-all'
+ });
+ document.documentElement.dispatchEvent(event);
+ location.reload();
+ },
+
+ deleteRow: function ($button) {
+ var hash = $button.parents('tr').children('.hash').text();
+ this.le--;
+ this.changeTitle();
+ $button.parents('tr').remove();
+ var event = document.createEvent("CustomEvent");
+ event.initCustomEvent(
+ "librejs-settings-change", true, true, {
+ event: 'rules-form-delete', value: hash
+ });
+ document.documentElement.dispatchEvent(event);
+ },
+
+ createRow: function (key, url, reason) {
+
+ var $tr = $("<tr/>");
+ var $td = $('<td/>').addClass('hash').text(key);
+ var $delete, $button;
+ $tr.append($td);
+ $td = $('<td/>').append($('<a/>').attr({
+ "href": url,
+ "target": "_blank"
+ }).text(url));
+ $tr.append($td);
+ $td = $('<td/>').text(reason);
+ $tr.append($td);
+
+ $delete = $("<td/>");
+ $button = $('<button/>');
+ $button.addClass("delete btn btn-danger")
+ .attr({'value': 'delete'}).text("Delete");
+ $delete.append($button);
+ $tr.append($delete);
+ return $tr;
+ },
+
+ appendNewRow: function (key, rowData) {
+ if (key && rowData !== undefined) {
+ this.$trContainer.append(
+ this.createRow(
+ key,
+ (rowData.filename || rowData.url),
+ (rowData.result.reason || "no reason recorded")));
+ }
+ },
+ clearForm: function () {
+ $('#whitelist').children('tbody').empty();
+ },
+ changeTitle: function () {
+ var tt = this.le + " scripts whitelisted";
+ $('div.page-header h1').text(tt);
+ $('title').text(tt + ' | LibreJS');
+ },
+ populateForm: function (data) {
+ var key;
+ this.le = Object.keys(data).length;
+ this.changeTitle();
+ this.clearForm();
+ for (key in data) {
+ this.appendNewRow(key, data[key]);
+ }
+ }
+};
+
+GenerateForm.init();
diff --git a/data/settings/js/form-types.js b/data/settings/js/form-types.js
new file mode 100644
index 0000000..588cec0
--- /dev/null
+++ b/data/settings/js/form-types.js
@@ -0,0 +1,145 @@
+/**
+ * Permafrost - Protect your privacy!
+ * *
+ * Copyright (C) 2012 2013 Loic J. Duros
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+var FORM_TYPES;
+
+/* constructor for form types options */
+function FormType(options) {
+ "use strict";
+ var item;
+ for (item in options) {
+ this[item] = options[item];
+ }
+}
+
+FormType.prototype = {
+ onblur: 'submit',
+ showbuttons: true,
+ pk: null,
+ name: null,
+ value: null,
+ url: function (params) {
+ "use strict";
+ // see https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Using%20Custom%20DOM%20Events for information on this.
+ FORM_TYPES.triggerEvent({'event': 'rules-form-update', 'value': params});
+
+ }
+};
+
+
+FORM_TYPES = {
+
+ patternPlaceholder: 'Enter wildcard patterns or regular expression ' +
+ 'patterns, one per line',
+
+ ruleType: null,
+
+ requestOrigin: null,
+
+ visitingSite: null,
+
+ contentType: null,
+
+ blockUI: function () {
+ "use strict";
+ $.blockUI({
+ message: null,
+ overlayCSS: { backgroundColor: 'none' }});
+ },
+
+ unblockUI: function () {
+ "use strict";
+ window.setTimeout($.unblockUI, 500);
+ },
+
+ triggerEvent: function (msg) {
+ "use strict";
+ var event = document.createEvent("CustomEvent");
+ var that = this;
+ event.initCustomEvent("permafrost-settings-change", true, true, msg);
+ document.documentElement.dispatchEvent(event);
+ this.blockUI();
+
+ var success = function (event) {
+ that.unblockUI();
+ document.documentElement.removeListener("rules-form-data-written", success, false);
+ };
+
+ document.documentElement.addEventListener("rules-form-data-written", success, false);
+
+ },
+
+ init: function () {
+ "use strict";
+
+ var formTypesHelper = this;
+
+ // these four objects will be used to represent all the
+ // form items in the table, and will hold different values
+ // depending on the last active html form object.
+
+ this.ruleType = new FormType({
+ type: 'select',
+ name: 'rule',
+ source: [
+ {value: 'block', text: 'Block'},
+ {value: 'allow', text: 'Allow'}
+ ]
+ });
+
+ this.requestOrigin = new FormType({
+ type: 'textarea',
+ name: 'content-location',
+ title: 'Requests originating from',
+ placeholder: formTypesHelper.patternPlaceholder
+ });
+
+ this.visitingSite = new FormType({
+ type: 'textarea',
+ name: 'request-origin',
+ title: 'when visiting (referrer)',
+ placeholder: formTypesHelper.patternPlaceholder
+ });
+
+ this.contentType = new FormType({
+ type: 'checklist',
+ name: 'content-type',
+ title: 'and are of type',
+ separator: ',',
+ source: [
+ { value: 'script', text: 'scripts' },
+ { value: 'image', text: 'images' },
+ { value: 'stylesheet', text: 'stylesheets' },
+ { value: 'object', text: 'objects and plugin contents' },
+ { value: 'object-request', text: 'requests made by plugins' },
+ { value: 'subdocument', text: 'subdocuments (iframes, frames, and objects)' },
+ { value: 'font', text: 'web font (@font-face)' },
+ { value: 'media', text: 'video or audio content' },
+ { value: 'xbl', text: 'XBL binding request' },
+ { value: 'dtd', text: 'DTD loaded by an XML document' },
+ { value: 'xrh', text: 'Ajax requests (XMLHttpRequests)' },
+ { value: 'others', text: 'miscellaneous content' }
+ ]
+ });
+
+
+ }
+
+};
diff --git a/data/settings/js/pagescript-emitter.js b/data/settings/js/pagescript-emitter.js
new file mode 100644
index 0000000..105c1ab
--- /dev/null
+++ b/data/settings/js/pagescript-emitter.js
@@ -0,0 +1,14 @@
+// listen for addon script emit and pass on the object to the page script.
+self.port.on("populate-form", function (data) {
+ // custom DOM event
+ var event = document.createEvent('CustomEvent');
+ event.initCustomEvent("populate-form", true, true, { data: data });
+ document.documentElement.dispatchEvent(event);
+});
+
+/*self.port.on("rules-form-data-written", function (data) {
+ // custom DOM event
+ var event = document.createEvent('CustomEvent');
+ event.initCustomEvent("rules-form-data-written", true, true, {});
+ document.documentElement.dispatchEvent(event);
+});*/
diff --git a/data/settings/js/pagescript-listener.js b/data/settings/js/pagescript-listener.js
new file mode 100644
index 0000000..48cd629
--- /dev/null
+++ b/data/settings/js/pagescript-listener.js
@@ -0,0 +1,51 @@
+/**
+ * Permafrost - Protect your privacy!
+ * *
+ * Copyright (C) 2012, 2013, 2014 Loic J. Duros
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+// listen for a message from the pagescript
+document.documentElement.addEventListener("librejs-settings-change", function (event) {
+ "use strict";
+
+ switch (event.detail.event) {
+
+ case 'rules-form-update':
+ self.port.emit('rules-form-update', event.detail.value);
+ break;
+
+ case 'rules-form-delete':
+ self.port.emit('rules-form-delete', event.detail.value);
+ break;
+
+ case 'rules-form-delete-all':
+ self.port.emit('rules-form-delete-all');
+ break;
+
+ case 'rules-form-reorder':
+ self.port.emit('rules-form-reorder', event.detail.value);
+ break;
+
+ case 'rules-form-add-empty-row':
+ self.port.emit('rules-form-add-empty-row', event.detail.value);
+ break;
+
+ }
+
+}, false);
+
+
diff --git a/data/settings/js/permafrost-info-box.js b/data/settings/js/permafrost-info-box.js
new file mode 100644
index 0000000..51c33cb
--- /dev/null
+++ b/data/settings/js/permafrost-info-box.js
@@ -0,0 +1,21 @@
+/**
+ * Permafrost - Protect your privacy!
+ * *
+ * Copyright (C) 2012 2013 Loic J. Duros
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+var box = '<div id="permafrost-info-panel" style="width: 250px; height: auto; padding: 20px; background-color: rgba(255, 255, 255, 0.9); box-shadow: 0px 0px 50px rgb(255, 255, 255); margin: 2%; border-radius: 15px 15px 0 0; font-family: Droid Sans,Helvetica,Arial,Sans; font-size: 12px; z-index: 20000; position: fixed; right: 3%; bottom: -10px; margin-bottom:0;;"> <ul> <li>test 1</li> <li>test 2</li> <li>test 3</li> <li>test 4</li><li>blah</li><li>blobl</li> </ul></div>';