diff --git a/_locales/en/messages.json b/_locales/en/messages.json index bc2a8c66442f088551487a3321c95cffcdae488a..51cc418b9b414ca2a2d1d430784e229429322289 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -23,12 +23,24 @@ "message": "MetaGer search settings are typically stored in your browser with the help of cookies which leads to problems with settings being deleted when clearing the browser history. If you enable this feature all settings will be stored in this extension instead and Cookies are not required anymore. Allow this extension to run in private browsing sessions in order to also apply your settings there.", "description": "Heading for Setting storage by plugin" }, - "settings_store_settings_sync": { - "message": "Sync settings with browser account", - "description": "Sync settings with browser account" - }, "settings_store_settings_link": { "message": "Open MetaGer Settings", "description": "Link description to the MetaGer settings page" + }, + "settings_anonymous_tokens_heading": { + "message": "Use anonymous Tokens", + "description": "Heading for Setting anonymous token by plugin" + }, + "settings_anonymous_tokens_description1": { + "message": "When enabling this feature you can use a MetaGer key verifiable completely anonymous using", + "description": "Heading for Setting storage by plugin" + }, + "settings_anonymous_tokens_descriptionlinktext": { + "message": "homomorphic encryption", + "description": "Heading for Setting storage by plugin" + }, + "settings_anonymous_tokens_description2": { + "message": "This algorithm makes it impossible for us to connect a MetaGer Key with any search request you make.", + "description": "Heading for Setting storage by plugin" } } \ No newline at end of file diff --git a/web/settings/index.css b/web/settings/index.css index 9126266fcaa148391953e506d3937145ab9e7482..3ffa1191e5768ecd34b9049f9ca0e86fbba28a0c 100644 --- a/web/settings/index.css +++ b/web/settings/index.css @@ -19,18 +19,18 @@ body>h1 { text-align: center; } -#store-settings { +.setting { border: 1px solid; padding: 1rem; display: grid; gap: 1rem; } -#store-settings>.heading>h2 { +.setting>.heading>h2 { margin: 0; } -#store-settings>.heading { +.setting>.heading { display: flex; align-items: center; justify-content: space-between; diff --git a/web/settings/index.html b/web/settings/index.html index 686da5ed1bf7b93d4f66fdcc96217b7736600b01..5e9b55e027b5ffec88e68d405c40800ac24f640e 100644 --- a/web/settings/index.html +++ b/web/settings/index.html @@ -23,6 +23,22 @@ <div class="description" data-text="settings_store_settings_description"></div> <a href="https://metager.org/meta/settings" data-text="settings_store_settings_link"></a> </div> + <div class="setting" id="anonymous-tokens"> + <div class="heading"> + <h2 data-text="settings_anonymous_tokens_heading"></h2> + <label for="anonymous-tokens-switch" class="switch"> + <input type="checkbox" name="anonymous-tokens-switch" id="anonymous-tokens-switch"> + <div class="slider round"></div> + </label> + </div> + <div class="description"> + <span data-text="settings_anonymous_tokens_description1"></span> + <a href="https://metager.org/keys/help/anonymous-token" + data-text="settings_anonymous_tokens_descriptionlinktext"></a> + <span>.</span> + <span data-text="settings_anonymous_tokens_description2"></span> + </div> + </div> <script src="strings.js"></script> <script src="index.js" async></script> </body> diff --git a/web/settings/index.js b/web/settings/index.js index d53ce05a8cc7f0cce904f0e3a74e34c986100428..fe0f7249b383360a3b7c08b0933b82ab04b10e94 100644 --- a/web/settings/index.js +++ b/web/settings/index.js @@ -3,12 +3,17 @@ // Setting change setting storage (async () => { let store_settings = null; - let checkbox = document.querySelector("#store-settings-switch"); + let use_anonymous_tokens = null; + let checkbox_store_settings = document.querySelector("#store-settings-switch"); + let checkbox_anonymous_tokens = document.querySelector("#anonymous-tokens-switch"); await initializeSettingsState(); - checkbox.addEventListener("change", e => { - updateSettingState(checkbox.checked); + checkbox_store_settings.addEventListener("change", e => { + updateSettingState(checkbox_store_settings.checked, use_anonymous_tokens); + }); + checkbox_anonymous_tokens.addEventListener("change", e => { + updateSettingState(store_settings, checkbox_anonymous_tokens.checked); }); async function verifyPermissions(request = false) { @@ -31,42 +36,54 @@ // Initialize stored settings let synced_settings = await browser.storage.sync.get({ settings_store: true, + use_anonymous_tokens: false, }); - if (synced_settings.settings_store == true) { + if (synced_settings.settings_store == true || synced_settings.use_anonymous_tokens == true) { await verifyPermissions().then(granted => { - if (granted) - store_settings = true; - else + if (granted) { + store_settings = synced_settings.settings_store; + use_anonymous_tokens = synced_settings.use_anonymous_tokens; + } else { store_settings = false; + use_anonymous_tokens = false; + } }); } else { store_settings = false; + use_anonymous_tokens = false; } - checkbox.checked = store_settings; + checkbox_store_settings.checked = store_settings; + checkbox_anonymous_tokens.checked = use_anonymous_tokens; browser.storage.onChanged.addListener((changes, areaName) => { if (changes.hasOwnProperty("settings_store")) { let new_value = changes.settings_store.newValue; - checkbox.checked = new_value; + checkbox_store_settings.checked = new_value; store_settings = new_value; } + if (changes.hasOwnProperty("use_anonymous_tokens")) { + let new_value = changes.use_anonymous_tokens.newValue; + checkbox_anonymous_tokens.checked = new_value; + use_anonymous_tokens = new_value; + } }); } - async function updateSettingState(store_settings) { - if (store_settings == true) { + async function updateSettingState(store_settings, use_anonymous_tokens) { + if (store_settings == true || use_anonymous_tokens == true) { return verifyPermissions(true).then(permission_granted => { if (permission_granted) { - return browser.storage.sync.set({ settings_store: store_settings }); + return browser.storage.sync.set({ settings_store: store_settings, use_anonymous_tokens: use_anonymous_tokens }); } else { - checkbox.checked = false; + checkbox_store_settings.checked = false; + checkbox_anonymous_tokens.checked = false; return; } }) } else { - return browser.storage.sync.set({ settings_store: store_settings }); + return browser.storage.sync.set({ settings_store: store_settings, use_anonymous_tokens: use_anonymous_tokens }); } } })();