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

Function getModifiableCSSDeclaration

src/inject/dynamic-theme/modify-css.ts:67–123  ·  view source on GitHub ↗
(
    property: string,
    value: string,
    rule: CSSStyleRule,
    variablesStore: VariablesStore,
    ignoreImageSelectors: string[],
    isCancelled: () => boolean,
)

Source from the content-addressed store, hash-verified

65];
66
67export function getModifiableCSSDeclaration(
68 property: string,
69 value: string,
70 rule: CSSStyleRule,
71 variablesStore: VariablesStore,
72 ignoreImageSelectors: string[],
73 isCancelled: () => boolean,
74): ModifiableCSSDeclaration | null {
75 let modifier: ModifiableCSSDeclaration['value'] | null = null;
76 if (property.startsWith('--')) {
77 modifier = getVariableModifier(variablesStore, property, value, rule, ignoreImageSelectors, isCancelled);
78 } else if (value.includes('var(')) {
79 modifier = getVariableDependantModifier(variablesStore, property, value, rule);
80 } else if (property === 'color-scheme') {
81 modifier = getColorSchemeModifier();
82 } else if (property === 'scrollbar-color') {
83 modifier = getScrollbarColorModifier(value);
84 } else if (
85 (
86 property.includes('color') &&
87 property !== '-webkit-print-color-adjust'
88 ) ||
89 property === 'fill' ||
90 property === 'stroke' ||
91 property === 'stop-color'
92 ) {
93 if (property.startsWith('border') && property !== 'border-color' && (value === 'initial' || value === 'currentcolor')) {
94 const borderSideProp = property.substring(0, property.length - 6);
95 const borderSideVal = rule.style.getPropertyValue(borderSideProp);
96 const borderStyleVal = rule.style.getPropertyValue('border-style');
97 if (borderSideVal.startsWith('0px') || borderSideVal === 'none' || borderStyleVal === 'none') {
98 property = borderSideProp;
99 modifier = borderSideVal;
100 } else {
101 modifier = value;
102 }
103 } else {
104 modifier = getColorModifier(property, value, rule);
105 }
106 } else if (property === 'background-image' || property === 'list-style-image') {
107 const selectorText = rule.selectorText;
108 const pushFilter = selectorText
109 ? (type: FilterType) => pushFilterSelector(selectorText, type)
110 : null;
111 modifier = getBgImageModifier(value, rule, ignoreImageSelectors, isCancelled, pushFilter);
112 } else if (property.includes('shadow')) {
113 modifier = getShadowModifier(value);
114 } else if (bgPropsToCopy.includes(property) && value !== 'initial') {
115 modifier = value;
116 }
117
118 if (!modifier) {
119 return null;
120 }
121
122 return {property, value: modifier, important: getPriority(rule.style, property), sourceValue: value};
123}
124

Callers 2

modifySheetFunction · 0.90
setCustomPropFunction · 0.90

Calls 9

getVariableModifierFunction · 0.85
getColorSchemeModifierFunction · 0.85
getColorModifierFunction · 0.85
pushFilterSelectorFunction · 0.85
getBgImageModifierFunction · 0.85
getShadowModifierFunction · 0.85
getPriorityFunction · 0.85

Tested by

no test coverage detected