()
| 179 | }; |
| 180 | |
| 181 | let update = () => { |
| 182 | debugLog('Starting update...'); |
| 183 | chrome.devtools.inspectedWindow.eval('$0.getAttribute("class")', className => { |
| 184 | debugLog('Got className:', className); |
| 185 | |
| 186 | // Handle the async operations outside the eval callback |
| 187 | (async () => { |
| 188 | if (typeof className !== 'string') { |
| 189 | sidebar.setObject({}); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | let staticMacroHashes = [...className.matchAll(/-macro-static-([^\s]+)/g)].map(m => m[1]); |
| 194 | let dynamicMacroHashes = [...className.matchAll(/-macro-dynamic-([^\s]+)/g)].map(m => m[1]); |
| 195 | debugLog('Static macro hashes:', staticMacroHashes); |
| 196 | debugLog('Dynamic macro hashes:', dynamicMacroHashes); |
| 197 | |
| 198 | // Get macro data: static from CSS custom properties on $0, dynamic from element's window.__styleMacroDynamic__.map |
| 199 | debugLog( |
| 200 | 'Waiting for', |
| 201 | staticMacroHashes.length, |
| 202 | 'static +', |
| 203 | dynamicMacroHashes.length, |
| 204 | 'dynamic macros...' |
| 205 | ); |
| 206 | let [staticResults, dynamicResults] = await Promise.all([ |
| 207 | getMacroDataStaticBatch(staticMacroHashes), |
| 208 | getMacroDataDynamicBatch(dynamicMacroHashes) |
| 209 | ]); |
| 210 | let results = [...staticResults, ...dynamicResults]; |
| 211 | debugLog('Results:', results); |
| 212 | |
| 213 | // Filter out null results (missing data) |
| 214 | results = results.filter(r => r != null); |
| 215 | debugLog('Filtered results:', results); |
| 216 | |
| 217 | if (results.length === 0) { |
| 218 | sidebar.setObject({}); |
| 219 | } else if (results.length === 1) { |
| 220 | sidebar.setObject(results[0].style ?? {}, results[0].loc); |
| 221 | } else { |
| 222 | let seenProperties = new Set(); |
| 223 | for (let i = results.length - 1; i >= 0; i--) { |
| 224 | for (let key in results[i].style) { |
| 225 | if (seenProperties.has(key)) { |
| 226 | delete results[i].style[key]; |
| 227 | } else { |
| 228 | seenProperties.add(key); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | let res = {}; |
| 234 | for (let result of results) { |
| 235 | res[result.loc] = result.style; |
| 236 | } |
| 237 | sidebar.setObject(res); |
| 238 | } |
no test coverage detected