mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
[mv3] Use CodeMirror editor for list of no-filtering websites
This is a first step to integrate CodeMirror6 into the project. As a side effect, this should take care of: https://github.com/uBlockOrigin/uBOL-home/issues/297 Though most likely the list of no-filtering websites will probably move to its own pane as in uBO in some future.
This commit is contained in:
parent
d12e7817d2
commit
fd5da3fcd2
6 changed files with 42 additions and 15 deletions
|
|
@ -78,10 +78,9 @@ h3[data-i18n="filteringMode0Name"]::first-letter {
|
||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
#trustedSites {
|
#trustedSites {
|
||||||
box-sizing: border-box;
|
background-color: var(--surface-0);
|
||||||
height: 6rem;
|
border: 1px solid var(--surface-3);
|
||||||
resize: vertical;
|
min-height: 8rem;
|
||||||
width: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
section[data-pane="rulesets"] > div:first-of-type {
|
section[data-pane="rulesets"] > div:first-of-type {
|
||||||
|
|
|
||||||
|
|
@ -91,8 +91,7 @@
|
||||||
<div>
|
<div>
|
||||||
<h3 data-i18n="filteringMode0Name"></h3>
|
<h3 data-i18n="filteringMode0Name"></h3>
|
||||||
<p data-i18n="noFilteringModeDescription">_</p>
|
<p data-i18n="noFilteringModeDescription">_</p>
|
||||||
<p><textarea id="trustedSites" spellcheck="false" placeholder="noFilteringModePlaceholder"></textarea>
|
<div id="trustedSites"></div>
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<!-- -------- -->
|
<!-- -------- -->
|
||||||
|
|
@ -156,6 +155,7 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="lib/codemirror/cm6.bundle.ubol.min.js"></script>
|
||||||
<script src="js/theme.js" type="module"></script>
|
<script src="js/theme.js" type="module"></script>
|
||||||
<script src="js/fa-icons.js" type="module"></script>
|
<script src="js/fa-icons.js" type="module"></script>
|
||||||
<script src="js/i18n.js" type="module"></script>
|
<script src="js/i18n.js" type="module"></script>
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,24 @@
|
||||||
import { browser, sendMessage } from './ext.js';
|
import { browser, sendMessage } from './ext.js';
|
||||||
import { dom, qs$ } from './dom.js';
|
import { dom, qs$ } from './dom.js';
|
||||||
import { hashFromIterable } from './dashboard.js';
|
import { hashFromIterable } from './dashboard.js';
|
||||||
|
import { i18n$ } from './i18n.js';
|
||||||
import punycode from './punycode.js';
|
import punycode from './punycode.js';
|
||||||
import { renderFilterLists } from './filter-lists.js';
|
import { renderFilterLists } from './filter-lists.js';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
const cm6 = self.cm6;
|
||||||
|
const cmView = (( ) => {
|
||||||
|
const options = {};
|
||||||
|
if ( dom.cl.has(':root', 'dark') ) {
|
||||||
|
options.oneDark = true;
|
||||||
|
}
|
||||||
|
options.placeholder = i18n$('noFilteringModePlaceholder');
|
||||||
|
return cm6.createEditorView(
|
||||||
|
cm6.createEditorState('', options),
|
||||||
|
qs$('#trustedSites')
|
||||||
|
);
|
||||||
|
})();
|
||||||
let cachedRulesetData = {};
|
let cachedRulesetData = {};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
@ -167,12 +180,15 @@ dom.on('#developerMode input[type="checkbox"]', 'change', ev => {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
function renderTrustedSites() {
|
function renderTrustedSites() {
|
||||||
const textarea = qs$('#trustedSites');
|
|
||||||
const hostnames = cachedRulesetData.trustedSites || [];
|
const hostnames = cachedRulesetData.trustedSites || [];
|
||||||
textarea.value = hostnames.map(hn => punycode.toUnicode(hn)).join('\n');
|
let text = hostnames.map(hn => punycode.toUnicode(hn)).join('\n');
|
||||||
if ( textarea.value !== '' ) {
|
if ( text !== '' ) { text += '\n'; }
|
||||||
textarea.value += '\n';
|
cmView.dispatch({
|
||||||
}
|
changes: {
|
||||||
|
from: 0, to: cmView.state.doc.length,
|
||||||
|
insert: text
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeTrustedSites() {
|
function changeTrustedSites() {
|
||||||
|
|
@ -186,8 +202,8 @@ function changeTrustedSites() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStagedTrustedSites() {
|
function getStagedTrustedSites() {
|
||||||
const textarea = qs$('#trustedSites');
|
const text = cmView.state.doc.toString();
|
||||||
return textarea.value.split(/\s/).map(hn => {
|
return text.split(/\s/).map(hn => {
|
||||||
try {
|
try {
|
||||||
return punycode.toASCII(
|
return punycode.toASCII(
|
||||||
(new URL(`https://${hn}/`)).hostname
|
(new URL(`https://${hn}/`)).hostname
|
||||||
|
|
@ -198,7 +214,7 @@ function getStagedTrustedSites() {
|
||||||
}).filter(hn => hn !== '');
|
}).filter(hn => hn !== '');
|
||||||
}
|
}
|
||||||
|
|
||||||
dom.on('#trustedSites', 'blur', changeTrustedSites);
|
dom.on(cmView.contentDOM, 'blur', changeTrustedSites);
|
||||||
|
|
||||||
self.addEventListener('beforeunload', changeTrustedSites);
|
self.addEventListener('beforeunload', changeTrustedSites);
|
||||||
|
|
||||||
|
|
@ -296,7 +312,8 @@ sendMessage({
|
||||||
renderFilterLists(cachedRulesetData);
|
renderFilterLists(cachedRulesetData);
|
||||||
renderWidgets();
|
renderWidgets();
|
||||||
dom.cl.remove(dom.body, 'loading');
|
dom.cl.remove(dom.body, 'loading');
|
||||||
} catch {
|
} catch(reason) {
|
||||||
|
console.error(reason);
|
||||||
}
|
}
|
||||||
listen();
|
listen();
|
||||||
}).catch(reason => {
|
}).catch(reason => {
|
||||||
|
|
|
||||||
9
platform/mv3/extension/lib/codemirror/README.md
Normal file
9
platform/mv3/extension/lib/codemirror/README.md
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
Steps to build `cm6.bundle.ubol.min.js` -- command line:
|
||||||
|
|
||||||
|
- `git clone https://github.com/gorhill/codemirror-quickstart.git`
|
||||||
|
- This is a customized repo forked from <https://github.com/RPGillespie6/codemirror-quickstart>
|
||||||
|
- `cd codemirror-quickstart`
|
||||||
|
- `npm install`
|
||||||
|
- `npm build`
|
||||||
|
- `cm6.bundle.ubol.min.js` should be in `dist` directory
|
||||||
|
- This is the origin of the `cm6.bundle.ubol.min.js` in the current directory
|
||||||
1
platform/mv3/extension/lib/codemirror/cm6.bundle.ubol.min.js
vendored
Normal file
1
platform/mv3/extension/lib/codemirror/cm6.bundle.ubol.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -96,6 +96,7 @@ cp platform/mv3/extension/*.html "$UBOL_DIR"/
|
||||||
cp platform/mv3/extension/*.json "$UBOL_DIR"/
|
cp platform/mv3/extension/*.json "$UBOL_DIR"/
|
||||||
cp platform/mv3/extension/css/* "$UBOL_DIR"/css/
|
cp platform/mv3/extension/css/* "$UBOL_DIR"/css/
|
||||||
cp -R platform/mv3/extension/js/* "$UBOL_DIR"/js/
|
cp -R platform/mv3/extension/js/* "$UBOL_DIR"/js/
|
||||||
|
cp -R platform/mv3/extension/lib "$UBOL_DIR"/
|
||||||
cp platform/mv3/"$PLATFORM"/ext-compat.js "$UBOL_DIR"/js/ 2>/dev/null || :
|
cp platform/mv3/"$PLATFORM"/ext-compat.js "$UBOL_DIR"/js/ 2>/dev/null || :
|
||||||
cp platform/mv3/extension/img/* "$UBOL_DIR"/img/
|
cp platform/mv3/extension/img/* "$UBOL_DIR"/img/
|
||||||
cp -R platform/mv3/extension/_locales "$UBOL_DIR"/
|
cp -R platform/mv3/extension/_locales "$UBOL_DIR"/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue