MCPcopy
hub / github.com/darkreader/darkreader / getColorModifier

Function getColorModifier

src/inject/dynamic-theme/modify-css.ts:308–341  ·  view source on GitHub ↗
(prop: string, value: string, rule: CSSStyleRule)

Source from the content-addressed store, hash-verified

306]);
307
308function getColorModifier(prop: string, value: string, rule: CSSStyleRule): string | CSSValueModifier | null {
309 if (
310 unparsableColors.has(value.toLowerCase()) &&
311 !(prop === 'color' && value === 'initial')
312 ) {
313 return value;
314 }
315 let rgb: RGBA | null = null;
316 if (prop === 'color' && value === 'initial') {
317 rgb = {r: 0, g: 0, b: 0, a: 1};
318 } else {
319 rgb = parseColorWithCache(value);
320 }
321 if (!rgb) {
322 logWarn("Couldn't parse color", value);
323 return null;
324 }
325
326 if (prop.includes('background')) {
327 const maskImageValue = rule.style.maskImage ?? rule.style.mask;
328 if (
329 maskImageValue &&
330 !maskImageValue.startsWith('none') &&
331 !maskImageValue.startsWith('linear-gradient')
332 ) {
333 return (theme) => modifyForegroundColor(rgb, theme);
334 }
335 return (theme) => modifyBackgroundColor(rgb, theme);
336 }
337 if (prop.includes('border') || prop.includes('outline')) {
338 return (theme) => modifyBorderColor(rgb, theme);
339 }
340 return (theme) => modifyForegroundColor(rgb, theme);
341}
342
343const imageDetailsCache = new Map<string, ImageDetails>();
344const awaitingForImageLoading = new Map<string, Array<(imageDetails: ImageDetails | null) => void>>();

Callers 1

Calls 6

parseColorWithCacheFunction · 0.90
logWarnFunction · 0.90
modifyForegroundColorFunction · 0.90
modifyBackgroundColorFunction · 0.90
modifyBorderColorFunction · 0.90
hasMethod · 0.65

Tested by

no test coverage detected