mirror of https://github.com/gorhill/uBlock.git
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:
parent
d5d643869c
commit
07c950f1e5
|
@ -42,8 +42,7 @@ const µBlock = (function() { // jshint ignore:line
|
||||||
autoUpdateAssetFetchPeriod: 120,
|
autoUpdateAssetFetchPeriod: 120,
|
||||||
autoUpdateDelayAfterLaunch: 180,
|
autoUpdateDelayAfterLaunch: 180,
|
||||||
autoUpdatePeriod: 7,
|
autoUpdatePeriod: 7,
|
||||||
blockingProfiles: '11101 11001 00001',
|
blockingProfiles: '11111/#F00 11011/#C0F 11001/#00F 00001',
|
||||||
blockingProfileColors: '#666666 #E7552C #F69454 #008DCB',
|
|
||||||
cacheStorageAPI: 'unset',
|
cacheStorageAPI: 'unset',
|
||||||
cacheStorageCompression: true,
|
cacheStorageCompression: true,
|
||||||
cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate',
|
cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate',
|
||||||
|
@ -191,6 +190,8 @@ const µBlock = (function() { // jshint ignore:line
|
||||||
cspNoInlineScript: "script-src 'unsafe-eval' * blob: data:",
|
cspNoInlineScript: "script-src 'unsafe-eval' * blob: data:",
|
||||||
cspNoScripting: 'script-src http: https:',
|
cspNoScripting: 'script-src http: https:',
|
||||||
cspNoInlineFont: 'font-src *',
|
cspNoInlineFont: 'font-src *',
|
||||||
|
|
||||||
|
liveBlockingProfiles: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -47,27 +47,21 @@ const relaxBlockingMode = function(tab) {
|
||||||
if ( µb.getNetFilteringSwitch(normalURL) === false ) { return; }
|
if ( µb.getNetFilteringSwitch(normalURL) === false ) { return; }
|
||||||
|
|
||||||
const hn = µb.URI.hostnameFromURI(normalURL);
|
const hn = µb.URI.hostnameFromURI(normalURL);
|
||||||
const currentProfile = µb.blockingModeFromHostname(hn);
|
const curProfileBits = µb.blockingModeFromHostname(hn);
|
||||||
const profiles = [];
|
let newProfileBits;
|
||||||
for ( const s of µb.hiddenSettings.blockingProfiles.split(/\s+/) ) {
|
for ( const profile of µb.liveBlockingProfiles ) {
|
||||||
const v = parseInt(s, 2);
|
if ( (curProfileBits & profile.bits & ~1) !== curProfileBits ) {
|
||||||
if ( isNaN(v) ) { continue; }
|
newProfileBits = profile.bits;
|
||||||
profiles.push(v);
|
|
||||||
}
|
|
||||||
let newProfile;
|
|
||||||
for ( const profile of profiles ) {
|
|
||||||
if ( (currentProfile & profile & 0b11111110) !== currentProfile ) {
|
|
||||||
newProfile = profile;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Reset to original blocking profile?
|
// TODO: Reset to original blocking profile?
|
||||||
if ( newProfile === undefined ) { return; }
|
if ( newProfileBits === undefined ) { return; }
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(currentProfile & 0b00000010) !== 0 &&
|
(curProfileBits & 0b00000010) !== 0 &&
|
||||||
(newProfile & 0b00000010) === 0
|
(newProfileBits & 0b00000010) === 0
|
||||||
) {
|
) {
|
||||||
µb.toggleHostnameSwitch({
|
µb.toggleHostnameSwitch({
|
||||||
name: 'no-scripting',
|
name: 'no-scripting',
|
||||||
|
@ -77,8 +71,8 @@ const relaxBlockingMode = function(tab) {
|
||||||
}
|
}
|
||||||
if ( µb.userSettings.advancedUserEnabled ) {
|
if ( µb.userSettings.advancedUserEnabled ) {
|
||||||
if (
|
if (
|
||||||
(currentProfile & 0b00000100) !== 0 &&
|
(curProfileBits & 0b00000100) !== 0 &&
|
||||||
(newProfile & 0b00000100) === 0
|
(newProfileBits & 0b00000100) === 0
|
||||||
) {
|
) {
|
||||||
µb.toggleFirewallRule({
|
µb.toggleFirewallRule({
|
||||||
srcHostname: hn,
|
srcHostname: hn,
|
||||||
|
@ -88,8 +82,8 @@ const relaxBlockingMode = function(tab) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(currentProfile & 0b00001000) !== 0 &&
|
(curProfileBits & 0b00001000) !== 0 &&
|
||||||
(newProfile & 0b00001000) === 0
|
(newProfileBits & 0b00001000) === 0
|
||||||
) {
|
) {
|
||||||
µb.toggleFirewallRule({
|
µb.toggleFirewallRule({
|
||||||
srcHostname: hn,
|
srcHostname: hn,
|
||||||
|
@ -99,8 +93,8 @@ const relaxBlockingMode = function(tab) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(currentProfile & 0b00010000) !== 0 &&
|
(curProfileBits & 0b00010000) !== 0 &&
|
||||||
(newProfile & 0b00010000) === 0
|
(newProfileBits & 0b00010000) === 0
|
||||||
) {
|
) {
|
||||||
µb.toggleFirewallRule({
|
µb.toggleFirewallRule({
|
||||||
srcHostname: hn,
|
srcHostname: hn,
|
||||||
|
@ -111,7 +105,7 @@ const relaxBlockingMode = function(tab) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( newProfile & 0b00000001 ) {
|
if ( newProfileBits & 0b00000001 ) {
|
||||||
vAPI.tabs.reload(tab.id);
|
vAPI.tabs.reload(tab.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -954,24 +954,6 @@ vAPI.tabs = new vAPI.Tabs();
|
||||||
|
|
||||||
µBlock.updateToolbarIcon = (( ) => {
|
µBlock.updateToolbarIcon = (( ) => {
|
||||||
const tabIdToDetails = new Map();
|
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 updateBadge = function(tabId) {
|
||||||
const µb = µBlock;
|
const µb = µBlock;
|
||||||
|
@ -980,7 +962,7 @@ vAPI.tabs = new vAPI.Tabs();
|
||||||
|
|
||||||
let state = 0;
|
let state = 0;
|
||||||
let badge = '';
|
let badge = '';
|
||||||
let color = blockingProfileColors[0];
|
let color = '#666';
|
||||||
|
|
||||||
let pageStore = µb.pageStoreFromTabId(tabId);
|
let pageStore = µb.pageStoreFromTabId(tabId);
|
||||||
if ( pageStore !== null ) {
|
if ( pageStore !== null ) {
|
||||||
|
@ -993,13 +975,13 @@ vAPI.tabs = new vAPI.Tabs();
|
||||||
badge = µb.formatCount(pageStore.perLoadBlockedRequestCount);
|
badge = µb.formatCount(pageStore.perLoadBlockedRequestCount);
|
||||||
}
|
}
|
||||||
if ( (parts & 0b100) !== 0 ) {
|
if ( (parts & 0b100) !== 0 ) {
|
||||||
let profile = µb.blockingModeFromHostname(pageStore.tabHostname);
|
const currentBits = µb.blockingModeFromHostname(pageStore.tabHostname);
|
||||||
if ( (profile & 0b00000010) !== 0 ) {
|
let max = 0;
|
||||||
color = blockingProfileColors[3];
|
for ( const profile of µb.liveBlockingProfiles ) {
|
||||||
} else if ( (profile & 0b00000100) !== 0 ) {
|
const v = currentBits & (profile.bits & ~1);
|
||||||
color = blockingProfileColors[2];
|
if ( v < max ) { break; }
|
||||||
} else if ( (profile & 0b00011000) !== 0 ) {
|
color = profile.color;
|
||||||
color = blockingProfileColors[1];
|
max = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -605,6 +605,30 @@ const matchBucket = function(url, hostname, bucket, start) {
|
||||||
return bits;
|
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
|
// https://github.com/NanoMeow/QuickReports/issues/6#issuecomment-414516623
|
||||||
|
|
Loading…
Reference in New Issue