From e8fef6a40d15345d09c1a4ae2f497c09b7eec6d4 Mon Sep 17 00:00:00 2001 From: Robbendebiene Date: Sun, 5 Jun 2022 20:59:40 +0200 Subject: [PATCH 01/21] Remove entire exclusion functionality Firefox will provide global user controls for site access per add-on. See: - https://bugzilla.mozilla.org/show_bug.cgi?id=1497075 - https://bugzilla.mozilla.org/show_bug.cgi?id=1711787 Removing this option from Gesturefy reduces the amount of code that needs to be maintained. It's also more performant to exclude the entire content script from running than doing content script side checks. Last but not least exclusions have always been a power feature that never really fit into Gesturefy from a design/UI standpoint. Also resolves #542 --- src/_locales/en/messages.json | 29 ---- src/core/bundle/content.bundle.js | 48 ++---- src/core/content.mjs | 48 ++---- src/resources/json/defaults.json | 3 +- src/views/options/exclusions.mjs | 162 --------------------- src/views/options/fragments/exclusions.inc | 14 -- src/views/options/index.html | 8 - src/views/options/layout.css | 132 ----------------- 8 files changed, 25 insertions(+), 419 deletions(-) delete mode 100644 src/views/options/exclusions.mjs delete mode 100644 src/views/options/fragments/exclusions.inc diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 28299ecff..e103309d5 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -37,10 +37,6 @@ "message": "Extras", "description": "Extras" }, - "navigationExclusions": { - "message": "Exclusions", - "description": "Exclusions" - }, "navigationAbout": { "message": "About", "description": "About" @@ -289,31 +285,6 @@ "description": "The minimal amount the mouse wheel must be scrolled until the gesture is triggered." }, - "exclusionsLabelInformation": { - "message": "Information:", - "description": "Information:" - }, - "exclusionsTextInformation": { - "message": "Add URL match patterns to disable Gesturefy for certain websites. The match pattern allows \"*\" wildcards and must be in the form of ://.", - "description": "Add URL match patterns to disable Gesturefy for certain websites. The match pattern allows \"*\" wildcards and must be in the form of ://." - }, - "exclusionsPlaceholderURL": { - "message": "Enter URL match pattern", - "description": "Enter URL match pattern" - }, - "exclusionsAddButton": { - "message": "Add", - "description": "Add" - }, - "exclusionsNotificationAlreadyExists": { - "message": "URL pattern already exists.", - "description": "URL pattern already exists." - }, - "exclusionsHintNoEntries": { - "message": "No entries available", - "description": "No entries available" - }, - "aboutBackup": { "message": "Backup", "description": "Backup" diff --git a/src/core/bundle/content.bundle.js b/src/core/bundle/content.bundle.js index 1c9ae1a46..fb044b1d7 100644 --- a/src/core/bundle/content.bundle.js +++ b/src/core/bundle/content.bundle.js @@ -2315,46 +2315,22 @@ async function main () { PopupCommandView.theme = Config.get("Settings.General.theme"); - // check if current url is not listed in the exclusions - if (!Config.get("Exclusions").some(matchesCurrentURL)) { - // enable mouse gesture controller - MouseGestureController.enable(); - - // enable/disable rocker gesture - if (Config.get("Settings.Rocker.active")) { - RockerGestureController.enable(); - } - else { - RockerGestureController.disable(); - } + // enable mouse gesture controller + MouseGestureController.enable(); - // enable/disable wheel gesture - if (Config.get("Settings.Wheel.active")) { - WheelGestureController.enable(); - } - else { - WheelGestureController.disable(); - } + // enable/disable rocker gesture + if (Config.get("Settings.Rocker.active")) { + RockerGestureController.enable(); } - // if url is excluded disable everything else { - MouseGestureController.disable(); RockerGestureController.disable(); - WheelGestureController.disable(); } -} - -/** - * checks if the given url is a subset of the current url or equal - * NOTE: window.location.href is returning the frame URL for frames and not the tab URL - **/ -function matchesCurrentURL (urlPattern) { - // match special regex characters - const pattern = urlPattern.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, (match) => { - // replace * with .* -> matches anything 0 or more times, else escape character - return match === '*' ? '.*' : '\\'+match; - }); - // ^ matches beginning of input and $ matches ending of input - return new RegExp('^'+pattern+'$').test(window.location.href); + // enable/disable wheel gesture + if (Config.get("Settings.Wheel.active")) { + WheelGestureController.enable(); + } + else { + WheelGestureController.disable(); + } } diff --git a/src/core/content.mjs b/src/core/content.mjs index 92a4a852b..e17a697a6 100644 --- a/src/core/content.mjs +++ b/src/core/content.mjs @@ -278,46 +278,22 @@ async function main () { PopupCommandView.theme = Config.get("Settings.General.theme"); - // check if current url is not listed in the exclusions - if (!Config.get("Exclusions").some(matchesCurrentURL)) { - // enable mouse gesture controller - MouseGestureController.enable(); - - // enable/disable rocker gesture - if (Config.get("Settings.Rocker.active")) { - RockerGestureController.enable(); - } - else { - RockerGestureController.disable(); - } + // enable mouse gesture controller + MouseGestureController.enable(); - // enable/disable wheel gesture - if (Config.get("Settings.Wheel.active")) { - WheelGestureController.enable(); - } - else { - WheelGestureController.disable(); - } + // enable/disable rocker gesture + if (Config.get("Settings.Rocker.active")) { + RockerGestureController.enable(); } - // if url is excluded disable everything else { - MouseGestureController.disable(); RockerGestureController.disable(); - WheelGestureController.disable(); } -} - -/** - * checks if the given url is a subset of the current url or equal - * NOTE: window.location.href is returning the frame URL for frames and not the tab URL - **/ -function matchesCurrentURL (urlPattern) { - // match special regex characters - const pattern = urlPattern.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, (match) => { - // replace * with .* -> matches anything 0 or more times, else escape character - return match === '*' ? '.*' : '\\'+match; - }); - // ^ matches beginning of input and $ matches ending of input - return new RegExp('^'+pattern+'$').test(window.location.href); + // enable/disable wheel gesture + if (Config.get("Settings.Wheel.active")) { + WheelGestureController.enable(); + } + else { + WheelGestureController.disable(); + } } diff --git a/src/resources/json/defaults.json b/src/resources/json/defaults.json index 9e7aceaa7..88b038513 100644 --- a/src/resources/json/defaults.json +++ b/src/resources/json/defaults.json @@ -298,6 +298,5 @@ } } } - ], - "Exclusions": [] + ] } diff --git a/src/views/options/exclusions.mjs b/src/views/options/exclusions.mjs deleted file mode 100644 index afff2de2d..000000000 --- a/src/views/options/exclusions.mjs +++ /dev/null @@ -1,162 +0,0 @@ -import { ContentLoaded, Config } from "/views/options/main.mjs"; - -ContentLoaded.then(main); - -/** - * main function - * run code that depends on async resources - **/ -function main () { - const exclusionsContainer = document.getElementById('exclusionsContainer'); - exclusionsContainer.dataset.noEntriesHint = browser.i18n.getMessage('exclusionsHintNoEntries'); - const exclusionsForm = document.getElementById('exclusionsForm'); - exclusionsForm.onsubmit = onFormSubmit; - exclusionsForm.elements.urlPattern.placeholder = browser.i18n.getMessage('exclusionsPlaceholderURL'); - exclusionsForm.elements.urlPattern.title = browser.i18n.getMessage('exclusionsPlaceholderURL'); - exclusionsForm.elements.urlPattern.onchange = onInputChange; - // add existing exclusions entries - for (const urlPattern of Config.get("Exclusions")) { - const exclusionsEntry = createExclusionsEntry(urlPattern); - exclusionsContainer.appendChild(exclusionsEntry); - } -} - - -/** - * Creates a exclusions entry html element by a given url pattern and returns it - **/ -function createExclusionsEntry (urlPattern) { - const exclusionsEntry = document.createElement('li'); - exclusionsEntry.classList.add('excl-entry'); - exclusionsEntry.dataset.urlPattern = urlPattern; - exclusionsEntry.onclick = onEntryClick; - const inputURLEntry = document.createElement('div'); - inputURLEntry.classList.add('excl-url-pattern'); - inputURLEntry.textContent = urlPattern; - const deleteButton = document.createElement('button'); - deleteButton.type = "button"; - deleteButton.classList.add('excl-remove-button', 'icon-delete'); - exclusionsEntry.append(inputURLEntry, deleteButton); - return exclusionsEntry; -} - - -/** - * Adds a given exclusions entry element to the exclusions ui - **/ -function addExclusionsEntry (exclusionsEntry) { - const exclusionsContainer = document.getElementById('exclusionsContainer'); - // append entry, hide it and move it out of flow to calculate its dimensions - exclusionsContainer.prepend(exclusionsEntry); - exclusionsEntry.style.setProperty('visibility', 'hidden'); - exclusionsEntry.style.setProperty('position', 'absolute'); - // calculate total entry height - const computedStyle = window.getComputedStyle(exclusionsEntry); - const outerHeight = parseInt(computedStyle.marginTop) + exclusionsEntry.offsetHeight + parseInt(computedStyle.marginBottom); - - // move all entries up by one entry including the new one - for (const node of exclusionsContainer.children) { - node.style.setProperty('transform', `translateY(-${outerHeight}px)`); - // remove ongoing transitions if existing - node.style.removeProperty('transition'); - } - // show new entry and bring it back to flow, which pushes all elements down by the height of one entry - exclusionsEntry.style.removeProperty('visibility', 'hidden'); - exclusionsEntry.style.removeProperty('position', 'absolute'); - - // trigger reflow - exclusionsContainer.offsetHeight; - - exclusionsEntry.addEventListener('animationend', (event) => { - event.currentTarget.classList.remove('excl-entry-animate-add'); - }, {once: true }); - exclusionsEntry.classList.add('excl-entry-animate-add'); - - // move all entries down including the new one - for (const node of exclusionsContainer.children) { - node.addEventListener('transitionend', (event) => event.currentTarget.style.removeProperty('transition'), {once: true }); - node.style.setProperty('transition', 'transform 0.3s'); - node.style.removeProperty('transform'); - } -} - - -/** - * Removes a given exclusions entry element from the exclusions ui - **/ -function removeExclusionsEntry (exclusionsEntry) { - // calculate total entry height - const computedStyle = window.getComputedStyle(exclusionsEntry); - const outerHeight = parseInt(computedStyle.marginTop) + exclusionsEntry.offsetHeight + parseInt(computedStyle.marginBottom); - - let node = exclusionsEntry.nextElementSibling; - while (node) { - node.addEventListener('transitionend', (event) => { - event.currentTarget.style.removeProperty('transition'); - event.currentTarget.style.removeProperty('transform'); - }, {once: true }); - node.style.setProperty('transition', 'transform 0.3s'); - node.style.setProperty('transform', `translateY(-${outerHeight}px)`); - node = node.nextElementSibling; - } - exclusionsEntry.addEventListener('animationend', (event) => event.currentTarget.remove(), {once: true }); - exclusionsEntry.classList.add('excl-entry-animate-remove'); -} - - -/** - * Handles the url pattern submit event - * Adds the new url pattern to the config and calls the exclusions entry create function - **/ -function onFormSubmit (event) { - event.preventDefault(); - // remove spaces and cancel the function if the value is empty - const urlPattern = this.elements.urlPattern.value.trim(); - if (!urlPattern) return; - // create and add entry to the exclusions - const exclusionsEntry = createExclusionsEntry(urlPattern); - addExclusionsEntry(exclusionsEntry); - // add new url pattern to the beginning of the array - const exclusionsArray = Config.get("Exclusions"); - exclusionsArray.unshift(urlPattern); - Config.set("Exclusions", exclusionsArray); - // clear input field - this.elements.urlPattern.value = ''; -} - - -/** - * Handles the url pattern input changes - * Marks the field as invalide if the entry already exists - **/ -function onInputChange () { - if (Config.get("Exclusions").indexOf(this.value.trim()) !== -1) { - this.setCustomValidity(browser.i18n.getMessage('exclusionsNotificationAlreadyExists')); - } - else if (this.validity.customError) this.setCustomValidity(''); -} - - -/** - * Handles the exclusions entry click - * Calls the remove exclusions entry function on remove button click and removes it from the config - **/ -function onEntryClick (event) { - // if delete button received the click - if (event.target.classList.contains('excl-remove-button')) { - removeExclusionsEntry(this); - - const exclusionsForm = document.getElementById('exclusionsForm'); - // remove input field invaldility if it was previously a duplicate - if (this.dataset.urlPattern === exclusionsForm.elements.urlPattern.value.trim()) { - exclusionsForm.elements.urlPattern.setCustomValidity(''); - } - const exclusionsArray = Config.get("Exclusions"); - // remove url pattern from array - const index = exclusionsArray.indexOf(this.dataset.urlPattern); - if (index !== -1) { - exclusionsArray.splice(index, 1); - Config.set("Exclusions", exclusionsArray); - } - } -} diff --git a/src/views/options/fragments/exclusions.inc b/src/views/options/fragments/exclusions.inc deleted file mode 100644 index 3bf1a55aa..000000000 --- a/src/views/options/fragments/exclusions.inc +++ /dev/null @@ -1,14 +0,0 @@ -
-

-
-

- - - -

-
-
- - -
-
    diff --git a/src/views/options/index.html b/src/views/options/index.html index cbd98eead..c8d1d3e99 100644 --- a/src/views/options/index.html +++ b/src/views/options/index.html @@ -14,7 +14,6 @@ - @@ -40,12 +39,6 @@ - +