1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-29 14:17:11 +02:00
uBlock/src/js/asset-viewer.js

115 lines
3.8 KiB
JavaScript
Raw Normal View History

2014-07-09 22:03:25 +02:00
/*******************************************************************************
2016-03-06 16:51:06 +01:00
uBlock Origin - a browser extension to block requests.
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
*/
/* 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
/******************************************************************************/
import { dom, qs$ } from './dom.js';
import './codemirror/ubo-static-filtering.js';
/******************************************************************************/
(async ( ) => {
const subscribeURL = new URL(document.location);
const subscribeParams = subscribeURL.searchParams;
const assetKey = subscribeParams.get('url');
if ( assetKey === null ) { return; }
const subscribeElem = subscribeParams.get('subscribe') !== null
? qs$('#subscribe')
: null;
if ( subscribeElem !== null && subscribeURL.hash !== '#subscribed' ) {
const title = subscribeParams.get('title');
const promptElem = qs$('#subscribePrompt');
dom.text(promptElem.children[0], title);
const a = promptElem.children[1];
dom.text(a, assetKey);
dom.attr(a, 'href', assetKey);
dom.cl.remove(subscribeElem, 'hide');
}
const cmEditor = new CodeMirror(qs$('#content'), {
autofocus: true,
foldGutter: true,
gutters: [
'CodeMirror-linenumbers',
{ className: 'CodeMirror-lintgutter', style: 'width: 11px' },
],
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
maxScanLines: 1,
readOnly: true,
styleActiveLine: {
nonEmpty: true,
},
});
2014-07-09 22:03:25 +02:00
uBlockDashboard.patchCodeMirrorEditor(cmEditor);
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', {
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; }
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);
});
const details = await vAPI.messaging.send('default', {
what : 'getAssetContent',
url: assetKey,
});
cmEditor.setOption('trustedSource', details.trustedSource === true);
cmEditor.setValue(details && details.content || '');
if ( subscribeElem !== null ) {
dom.on('#subscribeButton', 'click', ( ) => {
dom.cl.add(subscribeElem, 'hide');
vAPI.messaging.send('scriptlets', {
what: 'applyFilterListSelection',
toImport: assetKey,
}).then(( ) => {
vAPI.messaging.send('scriptlets', {
what: 'reloadAllFilters'
});
});
}, { once: true });
}
if ( details.sourceURL ) {
const a = qs$('.cm-search-widget .sourceURL');
dom.attr(a, 'href', details.sourceURL);
dom.attr(a, 'title', details.sourceURL);
}
dom.cl.remove(dom.body, 'loading');
2014-07-09 22:03:25 +02:00
})();