Created
March 7, 2021 19:45
-
-
Save nthitz/b1395c277f0fcf9ec978bde8ffebfa02 to your computer and use it in GitHub Desktop.
Search window for something
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
// stringifies an object avoiding circular references | |
let mySearch = (variable) => { | |
var cache = []; | |
let a = JSON.stringify(variable, (key, value) => { | |
if (typeof value === 'object' && value !== null) { | |
// Duplicate reference found, discard key | |
if (cache.includes(value)) return; | |
// Store value in our collection | |
cache.push(value); | |
} | |
return value; | |
}); | |
cache = null; // Enable garbage collection | |
return a | |
} | |
// searches through a string for all occurances of a substr printing characters on either side | |
let searchFuller = (obj, find) => { | |
let results = mySearch(obj); | |
let spot = 0; | |
let escape = 0; | |
while (spot !== -1 && escape++ < 100) { | |
spot = results.indexOf(find, spot + 1); | |
if (spot !== -1) { | |
console.log(results.substr(spot - 100, 200)) | |
} | |
} | |
} | |
// searches through window objects for a string | |
Object.keys(window).forEach(key => { | |
try { | |
console.log(key); | |
searchFuller(window[key], 'presence') // change presence to whatever you actually want to search for | |
} catch(e) { | |
console.log(key, 'failed'); console.log(e.message) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment