|
38 | 38 |
|
39 | 39 | if ( µBlock.canUseShortcuts === false ) { return; }
|
40 | 40 |
|
41 |
| -const relaxBlockingMode = function(tab) { |
42 |
| - if ( tab instanceof Object === false || tab.id <= 0 ) { return; } |
| 41 | +const relaxBlockingMode = (( ) => { |
| 42 | + const reloadTimers = new Map(); |
43 | 43 |
|
44 |
| - const µb = µBlock; |
45 |
| - const normalURL = µb.normalizePageURL(tab.id, tab.url); |
| 44 | + return function(tab) { |
| 45 | + if ( tab instanceof Object === false || tab.id <= 0 ) { return; } |
46 | 46 |
|
47 |
| - if ( µb.getNetFilteringSwitch(normalURL) === false ) { return; } |
| 47 | + const µb = µBlock; |
| 48 | + const normalURL = µb.normalizePageURL(tab.id, tab.url); |
48 | 49 |
|
49 |
| - const hn = µb.URI.hostnameFromURI(normalURL); |
50 |
| - const curProfileBits = µb.blockingModeFromHostname(hn); |
51 |
| - let newProfileBits; |
52 |
| - for ( const profile of µb.liveBlockingProfiles ) { |
53 |
| - if ( (curProfileBits & profile.bits & ~1) !== curProfileBits ) { |
54 |
| - newProfileBits = profile.bits; |
55 |
| - break; |
56 |
| - } |
57 |
| - } |
| 50 | + if ( µb.getNetFilteringSwitch(normalURL) === false ) { return; } |
58 | 51 |
|
59 |
| - // TODO: Reset to original blocking profile? |
60 |
| - if ( newProfileBits === undefined ) { return; } |
61 |
| - |
62 |
| - if ( |
63 |
| - (curProfileBits & 0b00000010) !== 0 && |
64 |
| - (newProfileBits & 0b00000010) === 0 |
65 |
| - ) { |
66 |
| - µb.toggleHostnameSwitch({ |
67 |
| - name: 'no-scripting', |
68 |
| - hostname: hn, |
69 |
| - state: false, |
70 |
| - }); |
71 |
| - } |
72 |
| - if ( µb.userSettings.advancedUserEnabled ) { |
73 |
| - if ( |
74 |
| - (curProfileBits & 0b00000100) !== 0 && |
75 |
| - (newProfileBits & 0b00000100) === 0 |
76 |
| - ) { |
77 |
| - µb.toggleFirewallRule({ |
78 |
| - srcHostname: hn, |
79 |
| - desHostname: '*', |
80 |
| - requestType: '3p', |
81 |
| - action: 3, |
82 |
| - }); |
| 52 | + const hn = µb.URI.hostnameFromURI(normalURL); |
| 53 | + const curProfileBits = µb.blockingModeFromHostname(hn); |
| 54 | + let newProfileBits; |
| 55 | + for ( const profile of µb.liveBlockingProfiles ) { |
| 56 | + if ( (curProfileBits & profile.bits & ~1) !== curProfileBits ) { |
| 57 | + newProfileBits = profile.bits; |
| 58 | + break; |
| 59 | + } |
83 | 60 | }
|
| 61 | + |
| 62 | + // TODO: Reset to original blocking profile? |
| 63 | + if ( newProfileBits === undefined ) { return; } |
| 64 | + |
84 | 65 | if (
|
85 |
| - (curProfileBits & 0b00001000) !== 0 && |
86 |
| - (newProfileBits & 0b00001000) === 0 |
| 66 | + (curProfileBits & 0b00000010) !== 0 && |
| 67 | + (newProfileBits & 0b00000010) === 0 |
87 | 68 | ) {
|
88 |
| - µb.toggleFirewallRule({ |
89 |
| - srcHostname: hn, |
90 |
| - desHostname: '*', |
91 |
| - requestType: '3p-script', |
92 |
| - action: 3, |
| 69 | + µb.toggleHostnameSwitch({ |
| 70 | + name: 'no-scripting', |
| 71 | + hostname: hn, |
| 72 | + state: false, |
93 | 73 | });
|
94 | 74 | }
|
95 |
| - if ( |
96 |
| - (curProfileBits & 0b00010000) !== 0 && |
97 |
| - (newProfileBits & 0b00010000) === 0 |
98 |
| - ) { |
99 |
| - µb.toggleFirewallRule({ |
100 |
| - srcHostname: hn, |
101 |
| - desHostname: '*', |
102 |
| - requestType: '3p-frame', |
103 |
| - action: 3, |
104 |
| - }); |
| 75 | + if ( µb.userSettings.advancedUserEnabled ) { |
| 76 | + if ( |
| 77 | + (curProfileBits & 0b00000100) !== 0 && |
| 78 | + (newProfileBits & 0b00000100) === 0 |
| 79 | + ) { |
| 80 | + µb.toggleFirewallRule({ |
| 81 | + srcHostname: hn, |
| 82 | + desHostname: '*', |
| 83 | + requestType: '3p', |
| 84 | + action: 3, |
| 85 | + }); |
| 86 | + } |
| 87 | + if ( |
| 88 | + (curProfileBits & 0b00001000) !== 0 && |
| 89 | + (newProfileBits & 0b00001000) === 0 |
| 90 | + ) { |
| 91 | + µb.toggleFirewallRule({ |
| 92 | + srcHostname: hn, |
| 93 | + desHostname: '*', |
| 94 | + requestType: '3p-script', |
| 95 | + action: 3, |
| 96 | + }); |
| 97 | + } |
| 98 | + if ( |
| 99 | + (curProfileBits & 0b00010000) !== 0 && |
| 100 | + (newProfileBits & 0b00010000) === 0 |
| 101 | + ) { |
| 102 | + µb.toggleFirewallRule({ |
| 103 | + srcHostname: hn, |
| 104 | + desHostname: '*', |
| 105 | + requestType: '3p-frame', |
| 106 | + action: 3, |
| 107 | + }); |
| 108 | + } |
105 | 109 | }
|
106 |
| - } |
107 | 110 |
|
108 |
| - if ( newProfileBits & 0b00000001 ) { |
109 |
| - vAPI.tabs.reload(tab.id); |
110 |
| - } |
111 |
| -}; |
| 111 | + // Reload the target tab? |
| 112 | + if ( (newProfileBits & 0b00000001) === 0 ) { return; } |
| 113 | + |
| 114 | + // Reload: use a timer to coalesce bursts of reload commands. |
| 115 | + let timer = reloadTimers.get(tab.id); |
| 116 | + if ( timer !== undefined ) { |
| 117 | + clearTimeout(timer); |
| 118 | + } |
| 119 | + timer = vAPI.setTimeout( |
| 120 | + tabId => { |
| 121 | + reloadTimers.delete(tabId); |
| 122 | + vAPI.tabs.reload(tabId); |
| 123 | + }, |
| 124 | + 547, |
| 125 | + tab.id |
| 126 | + ); |
| 127 | + reloadTimers.set(tab.id, timer); |
| 128 | + }; |
| 129 | +})(); |
112 | 130 |
|
113 | 131 | vAPI.commands.onCommand.addListener(command => {
|
114 | 132 | const µb = µBlock;
|
|
0 commit comments