Last active
April 27, 2025 10:28
-
-
Save alpgul/c9f306dc16640f3f79b808c343d5624f to your computer and use it in GitHub Desktop.
Revisions
-
alpgul revised this gist
Apr 27, 2025 . 1 changed file with 70 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,76 @@ (() => { const proxyCache = new WeakMap(); const get = Reflect.get; const set = Reflect.get; const log = console.log; const windowProxyHandler = { get(target, property) { log(`Getting property: ${String(property)}`); const value = get(target, property); if (typeof value === 'function') { return function (...args) { return value.apply(target, args); }; } if (value !== null && typeof value === 'object') { if (proxyCache.has(value)) return proxyCache.get(value); const proxy = new Proxy(value, windowProxyHandler); proxyCache.set(value, proxy); return proxy; } return value; }, set(target, property, value) { log(`Setting property: ${String(property)} to`, value); return set(target, property, value); } }; // Tüm global property'leri al const globalProps = [ ...Object.getOwnPropertyNames(globalThis), ...Object.getOwnPropertySymbols(globalThis) ]; for (const property of globalProps) { let value; try { value = globalThis[property]; } catch (e) { console.warn(`Cannot access globalThis.${String(property)}: ${e.message}`); continue; } if (value !== null && (typeof value === 'object')) { var proxy = proxyCache.has(value) ? proxyCache.get(value) : new Proxy(value, windowProxyHandler); if (!proxyCache.has(value)) proxyCache.set(value, proxy); const descriptor = Object.getOwnPropertyDescriptor(globalThis, property); if (!descriptor || descriptor.configurable) { Object.defineProperty(globalThis, property, { value: proxy, writable: true, configurable: true, }); console.log(`${String(property)}:`, globalThis[property]); } else { console.warn(`Property ${String(property)} is non-configurable, trying eval...`); try { if (typeof property === 'string' && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(property)) { eval(`var ${property} = proxy;`); eval(`console.log("${property}:", ${property})`); } else { console.warn(`Skipping eval for non-string or invalid property name: ${String(property)}`); } } catch (evalError) { console.error(`Eval failed for ${String(property)}: ${evalError.message}`); } } } } })(); -
alpgul created this gist
Apr 27, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ const proxyCache = new WeakMap(); const windowProxyHandler = { get(target, property) { console.log(`Getting property: ${String(property)}`); const value = Reflect.get(target, property); // Eğer değer bir fonksiyon ise, bağlamı koruyarak döndür if (typeof value === 'function') { return function (...args) { return value.apply(target, args); }; } // Eğer değer bir obje ise ve null değilse, Proxy ile sarmala if (value !== null && typeof value === 'object') { if (proxyCache.has(value)) return proxyCache.get(value); const proxy = new Proxy(value, windowProxyHandler); proxyCache.set(value, proxy); return proxy; } return value; }, set(target, property, value) { console.log(`Setting property: ${String(property)} to`, value); return Reflect.set(target, property, value); } }; const windowProxy = new Proxy(window, windowProxyHandler);