mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-05-05 21:03:17 +12:00
Fix odds and ends from mega commit 9b292304d3
Related commit: - https://github.com/gorhill/uMatrix/commit/9b292304d33a
This commit is contained in:
parent
df4a403473
commit
2936d73911
|
@ -385,6 +385,7 @@ body.tabless .needtab {
|
|||
justify-content: flex-end;
|
||||
unicode-bidi: embed;
|
||||
width: 16em;
|
||||
word-break: keep-all;
|
||||
}
|
||||
.matrix .matGroup.g4 .matRow.ro > .matCell:first-child {
|
||||
direction: inherit;
|
||||
|
|
|
@ -166,7 +166,7 @@ return {
|
|||
}
|
||||
},
|
||||
|
||||
rawSettingsDefault: rawSettingsDefault,
|
||||
rawSettingsDefault,
|
||||
rawSettings: (( ) => {
|
||||
const out = Object.assign({}, rawSettingsDefault);
|
||||
const json = vAPI.localStorage.getItem('immediateRawSettings');
|
||||
|
|
|
@ -27,10 +27,22 @@
|
|||
const µm = µMatrix;
|
||||
|
||||
await Promise.all([
|
||||
µm.loadPublicSuffixList(),
|
||||
µm.loadRawSettings(),
|
||||
µm.loadUserSettings(),
|
||||
]);
|
||||
log.info(`PSL and user settings ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
log.info(`User settings ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
|
||||
const shouldWASM = µm.rawSettings.disableWebAssembly !== true;
|
||||
if ( shouldWASM ) {
|
||||
await Promise.all([
|
||||
µm.HNTrieContainer.enableWASM(),
|
||||
self.publicSuffixList.enableWASM(),
|
||||
]);
|
||||
log.info(`WASM modules ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
}
|
||||
|
||||
await µm.loadPublicSuffixList(),
|
||||
log.info(`PSL ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
|
||||
{
|
||||
let trieDetails;
|
||||
|
@ -41,16 +53,17 @@
|
|||
} catch(ex) {
|
||||
}
|
||||
µm.ubiquitousBlacklist = new µm.HNTrieContainer(trieDetails);
|
||||
µm.ubiquitousBlacklist.initWASM();
|
||||
if ( shouldWASM ) {
|
||||
µm.ubiquitousBlacklist.initWASM();
|
||||
}
|
||||
}
|
||||
log.info(`Ubiquitous block container ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
log.info(`Ubiquitous block rules container ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
|
||||
await Promise.all([
|
||||
µm.loadRawSettings(),
|
||||
µm.loadMatrix(),
|
||||
µm.loadHostsFiles(),
|
||||
]);
|
||||
log.info(`Ubiquitous block rules ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
log.info(`All rules ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
|
||||
{
|
||||
const pageStore =
|
||||
|
|
|
@ -158,7 +158,7 @@
|
|||
this.rawSettings.suspendTabsUntilReady ? 'yes' : 'unset';
|
||||
}
|
||||
}
|
||||
this.fireDOMEvent('hiddenSettingsChanged');
|
||||
this.fireDOMEvent('rawSettingsChanged');
|
||||
};
|
||||
|
||||
// Note: Save only the settings which values differ from the default ones.
|
||||
|
@ -175,11 +175,11 @@
|
|||
bin.rawSettings[prop] = this.rawSettings[prop];
|
||||
}
|
||||
}
|
||||
vAPI.storage.set(bin);
|
||||
this.saveImmediateHiddenSettings();
|
||||
return vAPI.storage.set(bin);
|
||||
};
|
||||
|
||||
self.addEventListener('hiddenSettingsChanged', ( ) => {
|
||||
self.addEventListener('rawSettingsChanged', ( ) => {
|
||||
const µm = µMatrix;
|
||||
self.log.verbosity = µm.rawSettings.consoleLogLevel;
|
||||
vAPI.net.setOptions({
|
||||
|
@ -192,13 +192,74 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
});
|
||||
});
|
||||
|
||||
self.addEventListener('rawSettingsChanged', ( ) => {
|
||||
const µm = µMatrix;
|
||||
self.log.verbosity = µm.rawSettings.consoleLogLevel;
|
||||
vAPI.net.setOptions({
|
||||
cnameIgnoreList: µm.rawSettings.cnameIgnoreList,
|
||||
cnameIgnore1stParty: µm.rawSettings.cnameIgnore1stParty,
|
||||
cnameIgnoreExceptions: µm.rawSettings.cnameIgnoreExceptions,
|
||||
cnameIgnoreRootDocument: µm.rawSettings.cnameIgnoreRootDocument,
|
||||
cnameMaxTTL: µm.rawSettings.cnameMaxTTL,
|
||||
cnameReplayFullURL: µm.rawSettings.cnameReplayFullURL,
|
||||
});
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.rawSettingsFromString = function(raw) {
|
||||
const out = Object.assign({}, this.rawSettingsDefault);
|
||||
const lineIter = new this.LineIterator(raw);
|
||||
while ( lineIter.eot() === false ) {
|
||||
const line = lineIter.next();
|
||||
const matches = /^\s*(\S+)\s+(.+)$/.exec(line);
|
||||
if ( matches === null || matches.length !== 3 ) { continue; }
|
||||
const name = matches[1];
|
||||
if ( out.hasOwnProperty(name) === false ) { continue; }
|
||||
const value = matches[2].trim();
|
||||
switch ( typeof out[name] ) {
|
||||
case 'boolean':
|
||||
if ( value === 'true' ) {
|
||||
out[name] = true;
|
||||
} else if ( value === 'false' ) {
|
||||
out[name] = false;
|
||||
}
|
||||
break;
|
||||
case 'string':
|
||||
out[name] = value;
|
||||
break;
|
||||
case 'number': {
|
||||
const i = parseInt(value, 10);
|
||||
if ( isNaN(i) === false ) {
|
||||
out[name] = i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.rawSettings = out;
|
||||
this.saveRawSettings();
|
||||
this.fireDOMEvent('rawSettingsChanged');
|
||||
};
|
||||
|
||||
µMatrix.stringFromRawSettings = function() {
|
||||
const out = [];
|
||||
for ( const key of Object.keys(this.rawSettings).sort() ) {
|
||||
out.push(key + ' ' + this.rawSettings[key]);
|
||||
}
|
||||
return out.join('\n');
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// These settings must be available immediately on startup, without delay
|
||||
// through the vAPI.localStorage. Add/remove settings as needed.
|
||||
|
||||
µMatrix.saveImmediateHiddenSettings = function() {
|
||||
const props = [
|
||||
'consoleLogLevel',
|
||||
'disableWebAssembly',
|
||||
'suspendTabsUntilReady',
|
||||
];
|
||||
const toSave = {};
|
||||
|
@ -217,110 +278,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
µMatrix.loadRawSettings = async function() {
|
||||
const bin = await vAPI.storage.get('rawSettings');
|
||||
if (
|
||||
bin instanceof Object === false ||
|
||||
bin.rawSettings instanceof Object === false
|
||||
) {
|
||||
return;
|
||||
}
|
||||
for ( const key of Object.keys(bin.rawSettings) ) {
|
||||
if (
|
||||
this.rawSettings.hasOwnProperty(key) === false ||
|
||||
typeof bin.rawSettings[key] !== typeof this.rawSettings[key]
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
this.rawSettings[key] = bin.rawSettings[key];
|
||||
}
|
||||
this.rawSettingsWriteTime = Date.now();
|
||||
};
|
||||
|
||||
µMatrix.saveRawSettings = async function(rawSettings) {
|
||||
const keys = Object.keys(rawSettings);
|
||||
if ( keys.length === 0 ) { return; }
|
||||
|
||||
for ( const key of keys ) {
|
||||
if (
|
||||
this.rawSettingsDefault.hasOwnProperty(key) &&
|
||||
typeof rawSettings[key] === typeof this.rawSettingsDefault[key]
|
||||
) {
|
||||
this.rawSettings[key] = rawSettings[key];
|
||||
}
|
||||
}
|
||||
this.saveImmediateHiddenSettings();
|
||||
this.rawSettingsWriteTime = Date.now();
|
||||
|
||||
await vAPI.storage.set({ rawSettings: this.rawSettings });
|
||||
};
|
||||
|
||||
µMatrix.rawSettingsFromString = function(raw) {
|
||||
const result = {};
|
||||
const lineIter = new this.LineIterator(raw);
|
||||
while ( lineIter.eot() === false ) {
|
||||
const line = lineIter.next().trim();
|
||||
const matches = /^(\S+)(\s+(.+))?$/.exec(line);
|
||||
if ( matches === null ) { continue; }
|
||||
const name = matches[1];
|
||||
if ( this.rawSettingsDefault.hasOwnProperty(name) === false ) {
|
||||
continue;
|
||||
}
|
||||
let value = (matches[2] || '').trim();
|
||||
switch ( typeof this.rawSettingsDefault[name] ) {
|
||||
case 'boolean':
|
||||
if ( value === 'true' ) {
|
||||
value = true;
|
||||
} else if ( value === 'false' ) {
|
||||
value = false;
|
||||
} else {
|
||||
value = this.rawSettingsDefault[name];
|
||||
}
|
||||
break;
|
||||
case 'string':
|
||||
if ( value === '' ) {
|
||||
value = this.rawSettingsDefault[name];
|
||||
}
|
||||
break;
|
||||
case 'number':
|
||||
value = parseInt(value, 10);
|
||||
if ( isNaN(value) ) {
|
||||
value = this.rawSettingsDefault[name];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ( this.rawSettings[name] !== value ) {
|
||||
result[name] = value;
|
||||
}
|
||||
}
|
||||
this.saveRawSettings(result);
|
||||
};
|
||||
|
||||
µMatrix.stringFromRawSettings = function() {
|
||||
const out = [];
|
||||
for ( const key of Object.keys(this.rawSettings).sort() ) {
|
||||
out.push(key + ' ' + this.rawSettings[key]);
|
||||
}
|
||||
return out.join('\n');
|
||||
};
|
||||
|
||||
// These settings must be available immediately on startup, without delay
|
||||
// through the vAPI.localStorage. Add/remove settings as needed.
|
||||
|
||||
µMatrix.saveImmediateHiddenSettings = function() {
|
||||
vAPI.localStorage.setItem(
|
||||
'immediateRawSettings',
|
||||
JSON.stringify({
|
||||
suspendTabsUntilReady: this.rawSettings.suspendTabsUntilReady,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.saveMatrix = function() {
|
||||
|
@ -816,6 +773,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
);
|
||||
µm.ubiquitousBlacklistRef =
|
||||
µm.ubiquitousBlacklist.createOne(bin.hostsFilesSelfie.trieref);
|
||||
return true;
|
||||
},
|
||||
cancel: function() {
|
||||
if ( timer !== undefined ) {
|
||||
|
@ -832,10 +790,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
// TODO: remove once all users are way past 1.4.0.
|
||||
this.cacheStorage.remove('publicSuffixListSelfie');
|
||||
|
||||
if ( this.rawSettings.disableWebAssembly === false ) {
|
||||
publicSuffixList.enableWASM();
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.assets.get(`compiled/${this.pslAssetKey}`);
|
||||
if ( publicSuffixList.fromSelfie(result.content, this.base64) ) {
|
||||
|
|
|
@ -227,3 +227,15 @@
|
|||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.fireDOMEvent = function(name) {
|
||||
if (
|
||||
window instanceof Object &&
|
||||
window.dispatchEvent instanceof Function &&
|
||||
window.CustomEvent instanceof Function
|
||||
) {
|
||||
window.dispatchEvent(new CustomEvent(name));
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
<li id="mtxSwitch_no-workers" class="dropdown-menu-entry exists"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchNoWorker"></span> <a class="fa-icon" href="https://developer.mozilla.org/docs/Web/API/Web_Workers_API" target="_blank">info-circle</a>
|
||||
<li id="mtxSwitch_referrer-spoof" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchReferrerSpoof"></span> <a class="fa-icon" href="https://developer.mozilla.org/docs/Web/HTTP/Headers/Referer" target="_blank">info-circle</a>
|
||||
<li id="mtxSwitch_noscript-spoof" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchNoscriptSpoof"></span> <a class="fa-icon" href="https://developer.mozilla.org/docs/Web/HTML/Element/noscript" target="_blank">info-circle</a>
|
||||
<li id="mtxSwitch_cname-reveal" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchRevealCname"></span> <a class="fa-icon" href="https://en.wikipedia.org/wiki/CNAME_record" target="_blank">info-circle</a>
|
||||
<li id="mtxSwitch_cname-reveal" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchRevealCname"></span> <a class="fa-icon" href="https://wikipedia.org/wiki/CNAME_record" target="_blank">info-circle</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue