2014-07-09 22:03:25 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
2018-09-07 16:43:58 +02:00
|
|
|
Copyright (C) 2014-present Raymond Hill
|
2014-07-09 22:03:25 +02:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
*/
|
|
|
|
|
2018-09-07 16:43:58 +02:00
|
|
|
/* global CodeMirror, uBlockDashboard */
|
2014-07-09 22:03:25 +02:00
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
'use strict';
|
2014-07-09 22:03:25 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
import { dom, qs$ } from './dom.js';
|
2021-07-25 16:55:35 +02:00
|
|
|
import './codemirror/ubo-static-filtering.js';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2019-09-17 21:15:01 +02:00
|
|
|
(async ( ) => {
|
2020-09-13 14:01:53 +02:00
|
|
|
const subscribeURL = new URL(document.location);
|
|
|
|
const subscribeParams = subscribeURL.searchParams;
|
|
|
|
const assetKey = subscribeParams.get('url');
|
2018-09-07 16:43:58 +02:00
|
|
|
if ( assetKey === null ) { return; }
|
2018-02-28 18:31:43 +01:00
|
|
|
|
2020-09-13 14:01:53 +02:00
|
|
|
const subscribeElem = subscribeParams.get('subscribe') !== null
|
2022-11-12 15:51:22 +01:00
|
|
|
? qs$('#subscribe')
|
2020-09-13 14:01:53 +02:00
|
|
|
: null;
|
|
|
|
if ( subscribeElem !== null && subscribeURL.hash !== '#subscribed' ) {
|
|
|
|
const title = subscribeParams.get('title');
|
2022-11-12 15:51:22 +01:00
|
|
|
const promptElem = qs$('#subscribePrompt');
|
|
|
|
dom.text(promptElem.children[0], title);
|
2020-09-13 14:01:53 +02:00
|
|
|
const a = promptElem.children[1];
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.text(a, assetKey);
|
|
|
|
dom.attr(a, 'href', assetKey);
|
|
|
|
dom.cl.remove(subscribeElem, 'hide');
|
2020-09-13 14:01:53 +02:00
|
|
|
}
|
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
const cmEditor = new CodeMirror(qs$('#content'), {
|
2020-06-14 18:05:42 +02:00
|
|
|
autofocus: true,
|
2020-07-10 14:01:39 +02:00
|
|
|
foldGutter: true,
|
2023-04-01 22:42:41 +02:00
|
|
|
gutters: [
|
|
|
|
'CodeMirror-linenumbers',
|
2023-04-06 19:14:42 +02:00
|
|
|
{ className: 'CodeMirror-lintgutter', style: 'width: 11px' },
|
2023-04-01 22:42:41 +02:00
|
|
|
],
|
2020-06-14 18:05:42 +02:00
|
|
|
lineNumbers: true,
|
|
|
|
lineWrapping: true,
|
|
|
|
matchBrackets: true,
|
|
|
|
maxScanLines: 1,
|
|
|
|
readOnly: true,
|
2020-10-14 16:21:30 +02:00
|
|
|
styleActiveLine: {
|
|
|
|
nonEmpty: true,
|
|
|
|
},
|
2020-06-14 18:05:42 +02:00
|
|
|
});
|
2014-07-09 22:03:25 +02:00
|
|
|
|
2018-03-28 15:11:55 +02:00
|
|
|
uBlockDashboard.patchCodeMirrorEditor(cmEditor);
|
2019-09-17 21:15:01 +02:00
|
|
|
|
Add ability to control trusted status of filter lists
Related discussion:
https://github.com/uBlockOrigin/uBlock-issues/discussions/2895
Changes:
The _content of the My filters_ pane is now considered untrusted by
default, and only uBO's own lists are now trusted by default.
It has been observed that too many people will readily copy-paste
filters from random sources. Copy-pasting filters which require trust
represents a security risk to users with no understanding of how the
filters work and their potential abuse.
Using a filter which requires trust in a filter list from an untrusted
source will cause the filter to be invalid, i.e. shown as an error.
A new advanced setting has been added to control which lists are
considered trustworthy: `trustedListPrefixes`, which is a space-
separated list of tokens. Examples of possible values:
- `ublock-`: trust only uBO lists, exclude everything else including
content of _My filters_ (default value)
- `ublock- user-`: trust uBO lists and content of _My filters_
- `-`: trust no list, essentially disabling all filters requiring
trust (admins or people who don't trust us may want to use this)
One can also decide to trust lists maintained elsewhere. For example,
for stock AdGuard lists add ` adguard-`. To trust stock EasyList lists,
add ` easylist-`.
To trust a specific regional stock list, look-up its token in
assets.json and add to `trustedListPrefixes`.
The matching is made with String.startsWith(), hence why `ublock-`
matches all uBO's own filter lists.
This also allows to trust imported lists, for example add
` https://filters.adtidy.org/extension/ublock/filters/` to trust all
non-stock AdGuard lists.
Add the complete URL of a given imported list to trust only that one
list.
URLs not starting with `https://` or `file:///` will be rejected,
i.e. `http://example.org` will be ignored.
Invalid URLs are rejected.
2023-10-22 01:04:12 +02:00
|
|
|
vAPI.messaging.send('dashboard', {
|
2020-07-08 15:52:27 +02:00
|
|
|
what: 'getAutoCompleteDetails'
|
Add ability to control trusted status of filter lists
Related discussion:
https://github.com/uBlockOrigin/uBlock-issues/discussions/2895
Changes:
The _content of the My filters_ pane is now considered untrusted by
default, and only uBO's own lists are now trusted by default.
It has been observed that too many people will readily copy-paste
filters from random sources. Copy-pasting filters which require trust
represents a security risk to users with no understanding of how the
filters work and their potential abuse.
Using a filter which requires trust in a filter list from an untrusted
source will cause the filter to be invalid, i.e. shown as an error.
A new advanced setting has been added to control which lists are
considered trustworthy: `trustedListPrefixes`, which is a space-
separated list of tokens. Examples of possible values:
- `ublock-`: trust only uBO lists, exclude everything else including
content of _My filters_ (default value)
- `ublock- user-`: trust uBO lists and content of _My filters_
- `-`: trust no list, essentially disabling all filters requiring
trust (admins or people who don't trust us may want to use this)
One can also decide to trust lists maintained elsewhere. For example,
for stock AdGuard lists add ` adguard-`. To trust stock EasyList lists,
add ` easylist-`.
To trust a specific regional stock list, look-up its token in
assets.json and add to `trustedListPrefixes`.
The matching is made with String.startsWith(), hence why `ublock-`
matches all uBO's own filter lists.
This also allows to trust imported lists, for example add
` https://filters.adtidy.org/extension/ublock/filters/` to trust all
non-stock AdGuard lists.
Add the complete URL of a given imported list to trust only that one
list.
URLs not starting with `https://` or `file:///` will be rejected,
i.e. `http://example.org` will be ignored.
Invalid URLs are rejected.
2023-10-22 01:04:12 +02:00
|
|
|
}).then(hints => {
|
|
|
|
if ( hints instanceof Object === false ) { return; }
|
2020-07-08 15:52:27 +02:00
|
|
|
const mode = cmEditor.getMode();
|
Add ability to control trusted status of filter lists
Related discussion:
https://github.com/uBlockOrigin/uBlock-issues/discussions/2895
Changes:
The _content of the My filters_ pane is now considered untrusted by
default, and only uBO's own lists are now trusted by default.
It has been observed that too many people will readily copy-paste
filters from random sources. Copy-pasting filters which require trust
represents a security risk to users with no understanding of how the
filters work and their potential abuse.
Using a filter which requires trust in a filter list from an untrusted
source will cause the filter to be invalid, i.e. shown as an error.
A new advanced setting has been added to control which lists are
considered trustworthy: `trustedListPrefixes`, which is a space-
separated list of tokens. Examples of possible values:
- `ublock-`: trust only uBO lists, exclude everything else including
content of _My filters_ (default value)
- `ublock- user-`: trust uBO lists and content of _My filters_
- `-`: trust no list, essentially disabling all filters requiring
trust (admins or people who don't trust us may want to use this)
One can also decide to trust lists maintained elsewhere. For example,
for stock AdGuard lists add ` adguard-`. To trust stock EasyList lists,
add ` easylist-`.
To trust a specific regional stock list, look-up its token in
assets.json and add to `trustedListPrefixes`.
The matching is made with String.startsWith(), hence why `ublock-`
matches all uBO's own filter lists.
This also allows to trust imported lists, for example add
` https://filters.adtidy.org/extension/ublock/filters/` to trust all
non-stock AdGuard lists.
Add the complete URL of a given imported list to trust only that one
list.
URLs not starting with `https://` or `file:///` will be rejected,
i.e. `http://example.org` will be ignored.
Invalid URLs are rejected.
2023-10-22 01:04:12 +02:00
|
|
|
if ( mode.setHints instanceof Function === false ) { return; }
|
|
|
|
mode.setHints(hints);
|
|
|
|
});
|
|
|
|
|
|
|
|
vAPI.messaging.send('dashboard', {
|
|
|
|
what: 'getTrustedScriptletTokens',
|
|
|
|
}).then(tokens => {
|
|
|
|
cmEditor.setOption('trustedScriptletTokens', tokens);
|
|
|
|
});
|
2020-07-08 15:52:27 +02:00
|
|
|
|
2019-09-17 21:15:01 +02:00
|
|
|
const details = await vAPI.messaging.send('default', {
|
|
|
|
what : 'getAssetContent',
|
|
|
|
url: assetKey,
|
|
|
|
});
|
2023-10-16 15:47:29 +02:00
|
|
|
cmEditor.setOption('trustedSource', details.trustedSource === true);
|
2019-09-17 21:15:01 +02:00
|
|
|
cmEditor.setValue(details && details.content || '');
|
2020-09-13 14:01:53 +02:00
|
|
|
|
|
|
|
if ( subscribeElem !== null ) {
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.on('#subscribeButton', 'click', ( ) => {
|
|
|
|
dom.cl.add(subscribeElem, 'hide');
|
|
|
|
vAPI.messaging.send('scriptlets', {
|
|
|
|
what: 'applyFilterListSelection',
|
|
|
|
toImport: assetKey,
|
|
|
|
}).then(( ) => {
|
2020-09-13 14:01:53 +02:00
|
|
|
vAPI.messaging.send('scriptlets', {
|
2022-11-12 15:51:22 +01:00
|
|
|
what: 'reloadAllFilters'
|
2020-09-13 14:01:53 +02:00
|
|
|
});
|
2022-11-12 15:51:22 +01:00
|
|
|
});
|
|
|
|
}, { once: true });
|
2020-09-13 14:01:53 +02:00
|
|
|
}
|
|
|
|
|
2019-09-17 21:15:01 +02:00
|
|
|
if ( details.sourceURL ) {
|
2022-11-12 15:51:22 +01:00
|
|
|
const a = qs$('.cm-search-widget .sourceURL');
|
|
|
|
dom.attr(a, 'href', details.sourceURL);
|
|
|
|
dom.attr(a, 'title', details.sourceURL);
|
2019-09-17 21:15:01 +02:00
|
|
|
}
|
2020-09-13 14:01:53 +02:00
|
|
|
|
2022-11-12 15:51:22 +01:00
|
|
|
dom.cl.remove(dom.body, 'loading');
|
2014-07-09 22:03:25 +02:00
|
|
|
})();
|