Review icon badge color management

Related commit & feedback:
- 7ff750eaf6

The color value for the icon badge is now
"attached" to the blocking profile value.
Additionally, as per feedback, `3p` rules
will be relaxing before master JavaScript
switch rules.
This commit is contained in:
Raymond Hill 2019-08-11 13:55:39 -04:00
parent d5d643869c
commit 07c950f1e5
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 50 additions and 49 deletions

View File

@ -42,8 +42,7 @@ const µBlock = (function() { // jshint ignore:line
autoUpdateAssetFetchPeriod: 120,
autoUpdateDelayAfterLaunch: 180,
autoUpdatePeriod: 7,
blockingProfiles: '11101 11001 00001',
blockingProfileColors: '#666666 #E7552C #F69454 #008DCB',
blockingProfiles: '11111/#F00 11011/#C0F 11001/#00F 00001',
cacheStorageAPI: 'unset',
cacheStorageCompression: true,
cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate',
@ -191,6 +190,8 @@ const µBlock = (function() { // jshint ignore:line
cspNoInlineScript: "script-src 'unsafe-eval' * blob: data:",
cspNoScripting: 'script-src http: https:',
cspNoInlineFont: 'font-src *',
liveBlockingProfiles: [],
};
})();

View File

@ -47,27 +47,21 @@ const relaxBlockingMode = function(tab) {
if ( µb.getNetFilteringSwitch(normalURL) === false ) { return; }
const hn = µb.URI.hostnameFromURI(normalURL);
const currentProfile = µb.blockingModeFromHostname(hn);
const profiles = [];
for ( const s of µb.hiddenSettings.blockingProfiles.split(/\s+/) ) {
const v = parseInt(s, 2);
if ( isNaN(v) ) { continue; }
profiles.push(v);
}
let newProfile;
for ( const profile of profiles ) {
if ( (currentProfile & profile & 0b11111110) !== currentProfile ) {
newProfile = profile;
const curProfileBits = µb.blockingModeFromHostname(hn);
let newProfileBits;
for ( const profile of µb.liveBlockingProfiles ) {
if ( (curProfileBits & profile.bits & ~1) !== curProfileBits ) {
newProfileBits = profile.bits;
break;
}
}
// TODO: Reset to original blocking profile?
if ( newProfile === undefined ) { return; }
if ( newProfileBits === undefined ) { return; }
if (
(currentProfile & 0b00000010) !== 0 &&
(newProfile & 0b00000010) === 0
(curProfileBits & 0b00000010) !== 0 &&
(newProfileBits & 0b00000010) === 0
) {
µb.toggleHostnameSwitch({
name: 'no-scripting',
@ -77,8 +71,8 @@ const relaxBlockingMode = function(tab) {
}
if ( µb.userSettings.advancedUserEnabled ) {
if (
(currentProfile & 0b00000100) !== 0 &&
(newProfile & 0b00000100) === 0
(curProfileBits & 0b00000100) !== 0 &&
(newProfileBits & 0b00000100) === 0
) {
µb.toggleFirewallRule({
srcHostname: hn,
@ -88,8 +82,8 @@ const relaxBlockingMode = function(tab) {
});
}
if (
(currentProfile & 0b00001000) !== 0 &&
(newProfile & 0b00001000) === 0
(curProfileBits & 0b00001000) !== 0 &&
(newProfileBits & 0b00001000) === 0
) {
µb.toggleFirewallRule({
srcHostname: hn,
@ -99,8 +93,8 @@ const relaxBlockingMode = function(tab) {
});
}
if (
(currentProfile & 0b00010000) !== 0 &&
(newProfile & 0b00010000) === 0
(curProfileBits & 0b00010000) !== 0 &&
(newProfileBits & 0b00010000) === 0
) {
µb.toggleFirewallRule({
srcHostname: hn,
@ -111,7 +105,7 @@ const relaxBlockingMode = function(tab) {
}
}
if ( newProfile & 0b00000001 ) {
if ( newProfileBits & 0b00000001 ) {
vAPI.tabs.reload(tab.id);
}
};

View File

@ -954,24 +954,6 @@ vAPI.tabs = new vAPI.Tabs();
µBlock.updateToolbarIcon = (( ) => {
const tabIdToDetails = new Map();
const blockingProfileColors = [
'#666666',
'#E7552C',
'#F69454',
'#008DCB',
];
self.addEventListener(
'hiddenSettingsChanged',
( ) => {
const colors = µBlock.hiddenSettings.blockingProfileColors;
if ( /^#[0-9a-f]{6}(\s#[0-9a-f]{6}){3}$/i.test(colors) === false ) {
return;
}
blockingProfileColors.length = 0;
blockingProfileColors.push(...colors.split(/\s+/));
}
);
const updateBadge = function(tabId) {
const µb = µBlock;
@ -980,7 +962,7 @@ vAPI.tabs = new vAPI.Tabs();
let state = 0;
let badge = '';
let color = blockingProfileColors[0];
let color = '#666';
let pageStore = µb.pageStoreFromTabId(tabId);
if ( pageStore !== null ) {
@ -993,13 +975,13 @@ vAPI.tabs = new vAPI.Tabs();
badge = µb.formatCount(pageStore.perLoadBlockedRequestCount);
}
if ( (parts & 0b100) !== 0 ) {
let profile = µb.blockingModeFromHostname(pageStore.tabHostname);
if ( (profile & 0b00000010) !== 0 ) {
color = blockingProfileColors[3];
} else if ( (profile & 0b00000100) !== 0 ) {
color = blockingProfileColors[2];
} else if ( (profile & 0b00011000) !== 0 ) {
color = blockingProfileColors[1];
const currentBits = µb.blockingModeFromHostname(pageStore.tabHostname);
let max = 0;
for ( const profile of µb.liveBlockingProfiles ) {
const v = currentBits & (profile.bits & ~1);
if ( v < max ) { break; }
color = profile.color;
max = v;
}
}
}

View File

@ -605,6 +605,30 @@ const matchBucket = function(url, hostname, bucket, start) {
return bits;
};
µBlock.parseBlockingProfiles = (( ) => {
const parse = function() {
const s = µBlock.hiddenSettings.blockingProfiles;
const profiles = [];
s.split(/\s+/).forEach(s => {
let pos = s.indexOf('/');
if ( pos === -1 ) {
pos = s.length;
}
const bits = parseInt(s.slice(0, pos), 2);
if ( isNaN(bits) ) { return; }
const color = s.slice(pos + 1);
profiles.push({ bits, color: color !== '' ? color : '#666' });
});
µBlock.liveBlockingProfiles = profiles;
};
parse();
self.addEventListener('hiddenSettingsChanged', ( ) => { parse(); });
return parse;
})();
/******************************************************************************/
// https://github.com/NanoMeow/QuickReports/issues/6#issuecomment-414516623