2014-06-24 00:42:43 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2016-06-29 04:01:15 +02:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
2018-08-06 18:34:41 +02:00
|
|
|
Copyright (C) 2014-present Raymond Hill
|
2014-06-24 00:42:43 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
'use strict';
|
2014-08-21 05:19:27 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-04-05 13:29:15 +02:00
|
|
|
// Not all platforms may have properly declared vAPI.webextFlavor.
|
|
|
|
|
|
|
|
if ( vAPI.webextFlavor === undefined ) {
|
2018-04-18 13:11:13 +02:00
|
|
|
vAPI.webextFlavor = { major: 0, soup: new Set([ 'ublock' ]) };
|
2018-04-05 13:29:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 13:11:13 +02:00
|
|
|
|
2018-04-05 13:29:15 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-11-03 12:58:46 +01:00
|
|
|
const µBlock = (function() { // jshint ignore:line
|
2014-09-26 03:21:55 +02:00
|
|
|
|
2018-11-03 12:58:46 +01:00
|
|
|
const hiddenSettingsDefault = {
|
2017-01-18 19:17:47 +01:00
|
|
|
assetFetchTimeout: 30,
|
2019-01-08 13:37:50 +01:00
|
|
|
autoCommentFilterTemplate: '{{date}} {{origin}}',
|
2017-01-18 19:17:47 +01:00
|
|
|
autoUpdateAssetFetchPeriod: 120,
|
|
|
|
autoUpdatePeriod: 7,
|
2019-01-26 00:49:30 +01:00
|
|
|
cacheStorageAPI: 'unset',
|
2018-08-21 18:59:35 +02:00
|
|
|
cacheStorageCompression: true,
|
2018-09-21 15:16:46 +02:00
|
|
|
cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate',
|
2019-02-14 19:33:55 +01:00
|
|
|
consoleLogLevel: 'unset',
|
2018-11-16 16:19:06 +01:00
|
|
|
debugScriptlets: false,
|
|
|
|
disableWebAssembly: false,
|
2016-11-03 16:20:47 +01:00
|
|
|
ignoreRedirectFilters: false,
|
|
|
|
ignoreScriptInjectFilters: false,
|
2018-04-09 14:26:14 +02:00
|
|
|
manualUpdateAssetFetchPeriod: 500,
|
2016-11-06 22:27:21 +01:00
|
|
|
popupFontSize: 'unset',
|
2018-09-01 00:47:02 +02:00
|
|
|
requestJournalProcessPeriod: 1000,
|
2019-02-14 19:33:55 +01:00
|
|
|
selfieAfter: 11,
|
2018-10-29 13:56:51 +01:00
|
|
|
strictBlockingBypassDuration: 120,
|
2019-02-19 18:30:37 +01:00
|
|
|
suspendTabsUntilReady: 'unset',
|
2017-03-05 18:54:47 +01:00
|
|
|
userResourcesLocation: 'unset'
|
2017-03-05 14:25:55 +01:00
|
|
|
};
|
|
|
|
|
2018-11-03 12:58:46 +01:00
|
|
|
const whitelistDefault = [
|
2018-04-20 17:26:11 +02:00
|
|
|
'about-scheme',
|
|
|
|
'chrome-extension-scheme',
|
|
|
|
'chrome-scheme',
|
|
|
|
'moz-extension-scheme',
|
|
|
|
'opera-scheme',
|
|
|
|
'vivaldi-scheme',
|
|
|
|
'wyciwyg-scheme', // Firefox's "What-You-Cache-Is-What-You-Get"
|
|
|
|
];
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
return {
|
|
|
|
firstInstall: false,
|
|
|
|
|
|
|
|
userSettings: {
|
|
|
|
advancedUserEnabled: false,
|
2018-05-27 14:31:17 +02:00
|
|
|
alwaysDetachLogger: true,
|
2017-03-05 14:25:55 +01:00
|
|
|
autoUpdate: true,
|
|
|
|
cloudStorageEnabled: false,
|
|
|
|
collapseBlocked: true,
|
|
|
|
colorBlindFriendly: false,
|
|
|
|
contextMenuEnabled: true,
|
|
|
|
dynamicFilteringEnabled: false,
|
|
|
|
externalLists: [],
|
|
|
|
firewallPaneMinimized: true,
|
|
|
|
hyperlinkAuditingDisabled: true,
|
|
|
|
ignoreGenericCosmeticFilters: false,
|
|
|
|
largeMediaSize: 50,
|
|
|
|
parseAllABPHideFilters: true,
|
|
|
|
prefetchingDisabled: true,
|
|
|
|
requestLogMaxEntries: 1000,
|
|
|
|
showIconBadge: true,
|
|
|
|
tooltipsDisabled: false,
|
|
|
|
webrtcIPAddressHidden: false
|
|
|
|
},
|
|
|
|
|
|
|
|
hiddenSettingsDefault: hiddenSettingsDefault,
|
|
|
|
hiddenSettings: (function() {
|
2019-02-18 20:41:04 +01:00
|
|
|
const out = Object.assign({}, hiddenSettingsDefault);
|
|
|
|
const json = vAPI.localStorage.getItem('immediateHiddenSettings');
|
|
|
|
if ( typeof json !== 'string' ) { return out; }
|
|
|
|
try {
|
|
|
|
const o = JSON.parse(json);
|
|
|
|
if ( o instanceof Object ) {
|
|
|
|
for ( const k in o ) {
|
|
|
|
if ( out.hasOwnProperty(k) ) { out[k] = o[k]; }
|
2017-03-05 14:25:55 +01:00
|
|
|
}
|
2019-02-18 20:41:04 +01:00
|
|
|
self.log.verbosity = out.consoleLogLevel;
|
2019-02-19 18:30:37 +01:00
|
|
|
if ( typeof out.suspendTabsUntilReady === 'boolean' ) {
|
|
|
|
out.suspendTabsUntilReady = out.suspendTabsUntilReady
|
|
|
|
? 'yes'
|
|
|
|
: 'unset';
|
|
|
|
}
|
2017-03-05 14:25:55 +01:00
|
|
|
}
|
2019-02-18 20:41:04 +01:00
|
|
|
}
|
|
|
|
catch(ex) {
|
2017-03-05 14:25:55 +01:00
|
|
|
}
|
|
|
|
return out;
|
|
|
|
})(),
|
|
|
|
|
|
|
|
// Features detection.
|
|
|
|
privacySettingsSupported: vAPI.browserSettings instanceof Object,
|
|
|
|
cloudStorageSupported: vAPI.cloud instanceof Object,
|
2018-10-28 14:58:25 +01:00
|
|
|
canFilterResponseData: typeof browser.webRequest.filterResponseData === 'function',
|
2018-05-18 16:19:14 +02:00
|
|
|
canInjectScriptletsNow: vAPI.webextFlavor.soup.has('chromium'),
|
2017-03-05 14:25:55 +01:00
|
|
|
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/180
|
|
|
|
// Whitelist directives need to be loaded once the PSL is available
|
|
|
|
netWhitelist: {},
|
|
|
|
netWhitelistModifyTime: 0,
|
2018-04-20 17:26:11 +02:00
|
|
|
netWhitelistDefault: whitelistDefault.join('\n'),
|
2017-03-05 14:25:55 +01:00
|
|
|
|
|
|
|
localSettings: {
|
|
|
|
blockedRequestCount: 0,
|
|
|
|
allowedRequestCount: 0
|
|
|
|
},
|
|
|
|
localSettingsLastModified: 0,
|
|
|
|
localSettingsLastSaved: 0,
|
|
|
|
|
2018-05-31 16:41:03 +02:00
|
|
|
// Read-only
|
2017-03-05 14:25:55 +01:00
|
|
|
systemSettings: {
|
Add HNTrie-based filter classes to store origin-only filters
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/528#issuecomment-484408622
Following STrie-related work in above issue, I noticed that a large
number of filters in EasyList were filters which only had to match
against the document origin. For instance, among just the top 10
most populous buckets, there were four such buckets with over
hundreds of entries each:
- bits: 72, token: "http", 146 entries
- bits: 72, token: "https", 139 entries
- bits: 88, token: "http", 122 entries
- bits: 88, token: "https", 118 entries
These filters in these buckets have to be matched against all
the network requests.
In order to leverage HNTrie for these filters[1], they are now handled
in a special way so as to ensure they all end up in a single HNTrie
(per bucket), which means that instead of scanning hundreds of entries
per URL, there is now a single scan per bucket per URL for these
apply-everywhere filters.
Now, any filter which fulfill ALL the following condition will be
processed in a special manner internally:
- Is of the form `|https://` or `|http://` or `*`; and
- Does have a `domain=` option; and
- Does not have a negated domain in its `domain=` option; and
- Does not have `csp=` option; and
- Does not have a `redirect=` option
If a filter does not fulfill ALL the conditions above, no change
in behavior.
A filter which matches ALL of the above will be processed in a special
manner:
- The `domain=` option will be decomposed so as to create as many
distinct filter as there is distinct value in the `domain=` option
- This also apply to the `badfilter` version of the filter, which
means it now become possible to `badfilter` only one of the
distinct filter without having to `badfilter` all of them.
- The logger will always report these special filters with only a
single hostname in the `domain=` option.
***
[1] HNTrie is currently WASM-ed on Firefox.
2019-04-19 22:33:46 +02:00
|
|
|
compiledMagic: 10, // Increase when compiled format changes
|
|
|
|
selfieMagic: 10 // Increase when selfie format changes
|
2017-03-05 14:25:55 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
restoreBackupSettings: {
|
|
|
|
lastRestoreFile: '',
|
|
|
|
lastRestoreTime: 0,
|
|
|
|
lastBackupFile: '',
|
|
|
|
lastBackupTime: 0
|
|
|
|
},
|
|
|
|
|
2018-07-19 00:00:55 +02:00
|
|
|
commandShortcuts: new Map(),
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
// Allows to fully customize uBO's assets, typically set through admin
|
|
|
|
// settings. The content of 'assets.json' will also tell which filter
|
|
|
|
// lists to enable by default when uBO is first installed.
|
|
|
|
assetsBootstrapLocation: 'assets/assets.json',
|
|
|
|
|
|
|
|
userFiltersPath: 'user-filters',
|
|
|
|
pslAssetKey: 'public_suffix_list.dat',
|
|
|
|
|
|
|
|
selectedFilterLists: [],
|
|
|
|
availableFilterLists: {},
|
|
|
|
|
2018-02-26 19:59:16 +01:00
|
|
|
pageStores: new Map(),
|
2017-03-05 14:25:55 +01:00
|
|
|
pageStoresToken: 0,
|
|
|
|
|
|
|
|
storageQuota: vAPI.storage.QUOTA_BYTES,
|
|
|
|
storageUsed: 0,
|
|
|
|
|
|
|
|
noopFunc: function(){},
|
|
|
|
|
|
|
|
apiErrorCount: 0,
|
2017-09-06 01:49:48 +02:00
|
|
|
|
|
|
|
mouseEventRegister: {
|
|
|
|
tabId: '',
|
|
|
|
x: -1,
|
|
|
|
y: -1,
|
|
|
|
url: ''
|
|
|
|
},
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
epickerTarget: '',
|
2017-05-27 17:51:24 +02:00
|
|
|
epickerZap: false,
|
2017-03-05 14:25:55 +01:00
|
|
|
epickerEprom: null,
|
|
|
|
|
2018-04-06 22:02:35 +02:00
|
|
|
scriptlets: {},
|
2017-03-05 14:25:55 +01:00
|
|
|
};
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|