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

Function registerColor

src/inject/dynamic-theme/palette.ts:62–81  ·  view source on GitHub ↗
(type: ColorType, parsed: RGBA, value: string)

Source from the content-addressed store, hash-verified

60}
61
62export function registerColor(type: ColorType, parsed: RGBA, value: string): string {
63 const hex = rgbToHexString(parsed);
64
65 let registered: RegisteredColor;
66 if (registeredColors.has(hex)) {
67 registered = registeredColors.get(hex)!;
68 } else {
69 const parsed = parseColorWithCache(hex)!;
70 registered = {parsed};
71 registeredColors.set(hex, registered);
72 }
73
74 const variable = `--darkreader-${type}-${hex.replace('#', '')}`;
75 registered[type] = {variable, value};
76 if ((variablesSheet?.cssRules[0] as CSSStyleRule)?.style) {
77 (variablesSheet?.cssRules[0] as CSSStyleRule).style.setProperty(variable, value);
78 }
79
80 return getRegisteredVariableValue(type, registered);
81}
82
83export function getColorPalette(): ColorPalette {
84 const background: RGBA[] = [];

Callers 1

modifyAndRegisterColorFunction · 0.90

Calls 6

rgbToHexStringFunction · 0.90
parseColorWithCacheFunction · 0.90
hasMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected