MCPcopy Index your code
hub / github.com/darkreader/darkreader / getBgImageValue

Function getBgImageValue

src/inject/dynamic-theme/modify-css.ts:587–630  ·  view source on GitHub ↗
(imageDetails: ImageDetails, theme: Theme)

Source from the content-addressed store, hash-verified

585 };
586
587 const getBgImageValue = (imageDetails: ImageDetails, theme: Theme) => {
588 const {isDark, isLight, isTransparent, isLarge, solidColor, width} = imageDetails;
589 let result: string | null = null;
590 const logSrc = imageDetails.src.startsWith('data:') ? 'data:' : imageDetails.src;
591 if (isLarge && isLight && !isTransparent && theme.mode === 1) {
592 logInfo(`Hiding large light image ${logSrc}`);
593 result = 'none';
594 } else if (isDark && isTransparent && theme.mode === 1 && width > 2) {
595 logInfo(`Inverting dark image ${logSrc}`);
596 if (canFilterImage(imageDetails.src)) {
597 const inverted = getFilteredImageURL(imageDetails, {...theme, sepia: clamp(theme.sepia + 10, 0, 100)});
598 result = `url("${inverted}")`;
599 } else if (isSafeToInvert()) {
600 pushFilter?.('invert');
601 }
602 } else if (isLight && !isTransparent && theme.mode === 1) {
603 if (solidColor) {
604 logInfo(`Replacing image with a solid color ${logSrc}`);
605 const darkColor = modifyBackgroundColor(solidColor, theme, false);
606 const solid = getSolidColorImageURL(imageDetails, darkColor);
607 result = `url("${solid}")`;
608 } else if (canFilterImage(imageDetails.src)) {
609 logInfo(`Inverting light image ${logSrc}`);
610 const inverted = getFilteredImageURL(imageDetails, theme);
611 result = `url("${inverted}")`;
612 } else if (isSafeToInvert()) {
613 pushFilter?.('invert');
614 }
615 } else if (theme.mode === 0 && isLight && imageDetails.dataURL) {
616 logInfo(`Applying filter to image ${logSrc}`);
617 if (canFilterImage(imageDetails.src)) {
618 const filtered = getFilteredImageURL(imageDetails, {...theme, brightness: clamp(theme.brightness - 10, 5, 200), sepia: clamp(theme.sepia + 10, 0, 100)});
619 result = `url("${filtered}")`;
620 } else {
621 pushFilter?.('dim');
622 }
623 } else {
624 if (theme.mode === 1 && !canFilterImage(imageDetails.src)) {
625 pushFilter?.('none');
626 }
627 logInfo(`Not modifying the image ${logSrc}`);
628 }
629 return result;
630 };
631
632 const modifiers: Array<CSSValueModifier | null> = [];
633

Callers 1

getURLModifierFunction · 0.85

Calls 7

logInfoFunction · 0.90
getFilteredImageURLFunction · 0.90
clampFunction · 0.90
modifyBackgroundColorFunction · 0.90
getSolidColorImageURLFunction · 0.90
canFilterImageFunction · 0.85
isSafeToInvertFunction · 0.85

Tested by

no test coverage detected