Skip to content

Instantly share code, notes, and snippets.

@Far-Se
Created May 8, 2023 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Far-Se/da6433fcb603da33fa297587875ecb75 to your computer and use it in GitHub Desktop.
Save Far-Se/da6433fcb603da33fa297587875ecb75 to your computer and use it in GitHub Desktop.
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