|
43 | 43 | }).filter(a => a !== undefined); |
44 | 44 | })(); |
45 | 45 |
|
| 46 | + isolatedAPI.topHostname = hostnameStack.at(-1)?.hnparts.join('.') ?? ''; |
| 47 | + |
46 | 48 | const forEachHostname = (entry, callback, details) => { |
47 | 49 | const hnparts = entry.hnparts; |
48 | 50 | const hnpartslen = hnparts.length; |
|
81 | 83 | if ( typeof api === 'object' ) { return; } |
82 | 84 |
|
83 | 85 | const cosmeticAPI = self.cosmeticAPI = {}; |
| 86 | + const { isolatedAPI } = self; |
| 87 | + const { topHostname } = isolatedAPI; |
| 88 | + const thisHostname = document.location.hostname || ''; |
84 | 89 |
|
85 | 90 | const sessionRead = async function(key) { |
86 | 91 | try { |
|
145 | 150 | const data = await localRead(`css.${realm}.${rulesetId}`); |
146 | 151 | if ( typeof data !== 'object' || data === null ) { return; } |
147 | 152 | data.result = result; |
148 | | - self.isolatedAPI.forEachHostname(lookupHostname, data); |
| 153 | + isolatedAPI.forEachHostname(lookupHostname, data); |
149 | 154 | }; |
150 | 155 |
|
151 | 156 | const fillCache = async function(realm, rulesetIds) { |
152 | 157 | const selectors = new Set(); |
153 | 158 | const exceptions = new Set(); |
154 | 159 | const result = { selectors, exceptions }; |
155 | | - await Promise.all(rulesetIds.map(a => selectorsFromRuleset(realm, a, result))); |
| 160 | + const [ filteringModeDetails ] = await Promise.all([ |
| 161 | + localRead('filteringModeDetails'), |
| 162 | + ...rulesetIds.map(a => selectorsFromRuleset(realm, a, result)), |
| 163 | + ]); |
| 164 | + const skip = filteringModeDetails?.none.some(a => { |
| 165 | + if ( topHostname.endsWith(a) === false ) { return false; } |
| 166 | + const n = a.length; |
| 167 | + return topHostname.length === n || topHostname.at(-n-1) === '.'; |
| 168 | + }); |
156 | 169 | for ( const selector of exceptions ) { |
157 | 170 | selectors.delete(selector); |
158 | 171 | } |
159 | | - cacheEntry[cacheSlots[realm]] = Array.from(selectors).map(a => |
| 172 | + if ( skip ) { |
| 173 | + selectors.clear(); |
| 174 | + } |
| 175 | + cacheEntry[realm.charAt(0)] = Array.from(selectors).map(a => |
160 | 176 | a.startsWith('{') ? JSON.parse(a) : a |
161 | 177 | ); |
162 | 178 | }; |
|
165 | 181 | cacheEntry = await sessionRead(cacheKey) || {}; |
166 | 182 | }; |
167 | 183 |
|
168 | | - const cacheSlots = { 'specific': 's', 'procedural': 'p' }; |
169 | | - const cacheKey = `cache.css.${document.location.hostname || ''}`; |
| 184 | + const cacheKey = |
| 185 | + `cache.css.${thisHostname || ''}${topHostname !== thisHostname ? `/${topHostname}` : ''}`; |
170 | 186 | let clientCount = 0; |
171 | 187 | let cacheEntry; |
172 | 188 |
|
173 | 189 | cosmeticAPI.getSelectors = async function(realm, rulesetIds) { |
174 | 190 | clientCount += 1; |
175 | | - const slot = cacheSlots[realm]; |
| 191 | + const slot = realm.charAt(0); |
176 | 192 | if ( cacheEntry === undefined ) { |
177 | 193 | cacheEntry = readCache(); |
178 | 194 | } |
|
0 commit comments