MCPcopy Create free account
hub / github.com/darkreader/darkreader / overrideProperty

Function overrideProperty

src/inject/dynamic-theme/stylesheet-proxy.ts:33–46  ·  view source on GitHub ↗
(cls: {prototype: T}, prop: P, overrides: Record<string, OverrideFactory<T, P>>)

Source from the content-addressed store, hash-verified

31 documentEventListener('__darkreader__disableConflictingPlugins', disableConflictingPlugins);
32
33 function overrideProperty<T, P extends keyof T>(cls: {prototype: T}, prop: P, overrides: Record<string, OverrideFactory<T, P>>) {
34 const proto = cls.prototype;
35 const oldDescriptor = Object.getOwnPropertyDescriptor(proto, prop);
36 if (!oldDescriptor) {
37 return;
38 }
39 const newDescriptor: PropertyDescriptor = {...oldDescriptor};
40 (Object.keys(overrides) as Array<keyof PropertyDescriptor>).forEach((key) => {
41 const factory = overrides[key];
42 newDescriptor[key] = factory(oldDescriptor[key]);
43 });
44 Object.defineProperty(proto, prop, newDescriptor);
45 cleaners.push(() => Object.defineProperty(proto, prop, oldDescriptor));
46 }
47
48 function override<T, P extends keyof T>(cls: {prototype: T}, prop: P, factory: OverrideFactory<T, P>) {
49 overrideProperty(cls, prop, {value: factory});

Callers 2

overrideFunction · 0.85
injectProxyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…