From e23077a7ea72fad895ebfba87b8ecbaa6c8b7690 Mon Sep 17 00:00:00 2001 From: eight Date: Wed, 8 Dec 2021 18:30:16 +0800 Subject: [PATCH] Add: support inclusions (#1359) * Add: support inclusions * Fix: refresh settings page after configuring in popup --- background/style-manager.js | 22 +++++++++++++++++++--- edit/settings.js | 2 +- popup/popup.js | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index b8243d03..b7c2b8df 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -193,6 +193,7 @@ const styleMan = (() => { for (const style of styles) { let excluded = false; let excludedScheme = false; + let included = false; let sloppy = false; let sectionMatched = false; const match = urlMatchStyle(query, style); @@ -200,6 +201,9 @@ const styleMan = (() => { // if (match === false) { // continue; // } + if (match === 'included') { + included = true; + } if (match === 'excluded') { excluded = true; } @@ -219,8 +223,9 @@ const styleMan = (() => { break; } } - if (sectionMatched) { - result.push(/** @namespace StylesByUrlResult */ {style, excluded, sloppy, excludedScheme}); + if (sectionMatched || included) { + result.push(/** @namespace StylesByUrlResult */ { + style, excluded, sloppy, excludedScheme, sectionMatched, included}); } } return result; @@ -472,7 +477,12 @@ const styleMan = (() => { // get styles matching a URL, including sloppy regexps and excluded items. function getAppliedCode(query, data) { - if (urlMatchStyle(query, data) !== true) { + const result = urlMatchStyle(query, data); + if (result === 'included') { + // return all sections + return data.sections.map(s => s.code); + } + if (result !== true) { return; } const code = []; @@ -568,6 +578,12 @@ const styleMan = (() => { if (!colorScheme.shouldIncludeStyle(style)) { return 'excludedScheme'; } + if ( + style.inclusions && + style.inclusions.some(r => compileExclusion(r).test(query.urlWithoutParams)) + ) { + return 'included'; + } return true; } diff --git a/edit/settings.js b/edit/settings.js index 7628bdd0..b54d28fe 100644 --- a/edit/settings.js +++ b/edit/settings.js @@ -28,7 +28,7 @@ function StyleSettings(editor) { function update(newStyle, reason) { if (!newStyle.id) return; - if (reason === 'editSave' || reason === 'config') return; + if (reason === 'editSave') return; style = newStyle; $('.style-settings').disabled = false; inputs.forEach(i => i.update()); diff --git a/popup/popup.js b/popup/popup.js index a7872a38..76959094 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -380,6 +380,7 @@ function createStyleElement(style) { ''; }); + entry.classList.toggle('force-applied', style.included); entry.classList.toggle('not-applied', style.excluded || style.sloppy || style.excludedScheme); entry.classList.toggle('regexp-partial', style.sloppy);