Created
May 8, 2023 06:22
-
-
Save Far-Se/da6433fcb603da33fa297587875ecb75 to your computer and use it in GitHub Desktop.
This file contains 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 characters
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') | |
console.log('SEARCHING...') | |
console.log('-----------------------------------------------------------') | |
globalSearch(window, 'prØØf') | |
console.log('>>> D O N E >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') | |
function globalSearch(startObject, value, returnFirstResult = false) { | |
var stack = [[startObject, '']] | |
var ignored = ['CSSStyleRule', 'StylePropertyMap', 'CSSStyleDeclaration', 'HTMLStyleElement'] | |
var searched = [] | |
var ignoredObjects = ['__SENTRY__', 'document'] | |
var getType = test => Object.prototype.toString.call(test) | |
var isArray = test => getType(test) === '[object Array]' | |
var isIgnored = (addr, name) => { | |
addr = addr.split('.') | |
addr = addr[addr.length - 1] | |
if (ignoredObjects.includes(addr)) { | |
return true | |
} | |
name = name.split(' ')[1].split(']')[0] | |
return ignored.includes(name) | |
} | |
while (stack.length) { | |
var fromStack = stack.pop() | |
var obj = fromStack[0] | |
var address = fromStack[1] | |
if (isIgnored(address, getType(obj))) { | |
continue; | |
} | |
if (typeof obj == typeof value && obj.search(value) > -1) { | |
if (returnFirstResult) { | |
return address == '' ? false : address | |
} | |
console.log(address, { obj }) | |
} | |
if (typeof obj == "object" && searched.indexOf(obj) == -1) { | |
if (isArray(obj)) { | |
var prefix = '[' | |
var postfix = ']' | |
} else { | |
var prefix = '.' | |
var postfix = '' | |
} | |
for (i in obj) { | |
stack.push([obj[i], address + prefix + i + postfix]) | |
} | |
searched.push(obj) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment