From 1f15bb8c46a7c5f936aa52355d341e22d1d88e08 Mon Sep 17 00:00:00 2001 From: beu Date: Wed, 4 Jul 2018 18:20:40 +0200 Subject: [PATCH] Add settings page --- manifest.json | 6 +++++- popup/{dnssec.js => checks.js} | 18 +++++++++++++++--- popup/index.html | 4 ++-- popup/style.css | 2 +- settings/options.html | 27 +++++++++++++++++++++++++++ settings/options.js | 23 +++++++++++++++++++++++ 6 files changed, 73 insertions(+), 7 deletions(-) rename popup/{dnssec.js => checks.js} (78%) create mode 100644 settings/options.html create mode 100644 settings/options.js diff --git a/manifest.json b/manifest.json index bd49500..72a38f1 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,11 @@ { "manifest_version": 2, "name": "HTTPS+ Checker", - "version": "0.0.2", + "version": "0.0.3", "description": "Verification of security mechanisms complementary to HTTPS", "permissions": [ "tabs", + "storage", "webRequest", "" ], @@ -20,5 +21,8 @@ "icons": { "48": "icon_x48.png", "96": "icon_x96.png" + }, + "options_ui": { + "page": "settings/options.html" } } diff --git a/popup/dnssec.js b/popup/checks.js similarity index 78% rename from popup/dnssec.js rename to popup/checks.js index e9ec513..5b96b11 100644 --- a/popup/dnssec.js +++ b/popup/checks.js @@ -1,15 +1,21 @@ var xhr = new XMLHttpRequest(); +function onGot(item) { + var API = "http://httpspluschecker.virtit.fr/?domain="; + if (item.API) { + API = item.API; + } + + browser.tabs.query({ active: true, lastFocusedWindow: true }).then(function(tab) { const url = new URL(tab[0].url); if (url.protocol === "http:" || url.protocol === "https:" ) { + console.log("onGot : " + API) var host = url.hostname ; - - xhr.open('GET', 'https://httpspluschecker.virtit.fr/?domain=' + host, false); + xhr.open('GET', API + host, false); xhr.send(); - value = JSON.parse(xhr.responseText); if (value['DNSSEC'] === true ) { @@ -35,3 +41,9 @@ browser.tabs.query({ active: true, lastFocusedWindow: true }).then(function(tab) } }); + + +} +var getting = browser.storage.local.get("API"); +getting.then(onGot); + diff --git a/popup/index.html b/popup/index.html index 797f488..0612cd7 100644 --- a/popup/index.html +++ b/popup/index.html @@ -2,7 +2,7 @@ - + @@ -18,4 +18,4 @@ - \ No newline at end of file + diff --git a/popup/style.css b/popup/style.css index 7b0d258..6a66f39 100644 --- a/popup/style.css +++ b/popup/style.css @@ -28,4 +28,4 @@ td { text-align: center; font-weight: bold; font-size: 18px; -} \ No newline at end of file +} diff --git a/settings/options.html b/settings/options.html new file mode 100644 index 0000000..95a0497 --- /dev/null +++ b/settings/options.html @@ -0,0 +1,27 @@ + + + + + + +
+ +
+ +
+ + + + + + diff --git a/settings/options.js b/settings/options.js new file mode 100644 index 0000000..fd6f6d5 --- /dev/null +++ b/settings/options.js @@ -0,0 +1,23 @@ +function saveOptions(e) { + e.preventDefault(); + browser.storage.local.set({ + API: document.querySelector("#API").value + }); +} + +function restoreOptions() { + + function setCurrentChoice(result) { + document.querySelector("#API").value = result.API || "http://httpspluschecker.virtit.fr/?domain=" ; + } + + function onError(error) { + console.log(`Error: ${error}`); + } + + var getting = browser.storage.local.get("API"); + getting.then(setCurrentChoice, onError); +} + +document.addEventListener("DOMContentLoaded", restoreOptions); +document.querySelector("form").addEventListener("submit", saveOptions);