-
-
Save hughker/dbae7db0615eda5d59c9 to your computer and use it in GitHub Desktop.
Console script - Search breakpoint model for value. SYNTAX: scanScope($scope.model, 'Fred');
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("Usage Syntax: scanScope(objectToScan, 'scanFor', 'whatToIgnore'); (whatToIgnore is optional)"); | |
var callStack = 0, | |
errArray = [], | |
funArray = []; | |
function scanLoop(whatToScan, scanValue, whatToIgnore, parentTree) { | |
scanValue = scanValue.toLowerCase(); | |
whatToIgnore = (whatToIgnore !== undefined) ? whatToIgnore.toLowerCase() : undefined; | |
var yesCheck = false, | |
insertString = ''; | |
if (parentTree === undefined) { | |
callStack = 0; | |
} | |
callStack ++; | |
if (callStack > 1500) { | |
return; | |
} | |
for (var key in whatToScan) { | |
try { | |
yesCheck = (exists(whatToScan[key]) && (whatToScan[key].toString().indexOf !== undefined) && whatToScan[key].toString().toLowerCase !== undefined) | |
if ((yesCheck && whatToScan[key].toString().toLowerCase().indexOf(scanValue) > -1) || key.toLowerCase().indexOf(scanValue) >= 0) { | |
if (whatToScan[key].toString().toLowerCase().indexOf(whatToIgnore) === -1 && key.toLowerCase().indexOf(whatToIgnore) === -1) { | |
if (exists(parentTree)) { | |
insertString = parentTree + '.'; | |
} else { | |
insertString = ''; | |
} | |
if (key.substr(0,2) != '$$' && insertString.substr(0,2) != '$$') { | |
if (exists(whatToScan[key]) && whatToScan[key].toString().indexOf('function') > -1) { | |
funArray.push(insertString + key + ' = ' + whatToScan[key]); | |
} else { | |
console.log(insertString + key + ' = ' + whatToScan[key]); | |
} | |
} | |
} | |
} else { | |
if( (typeof whatToScan[key] === 'object') && (key !== null) ) { | |
if (exists(whatToScan[key]) && exists(whatToScan[key].toString()) && whatToScan[key].toString().indexOf('$$') < 0) { | |
if (exists(parentTree)) { | |
insertString = parentTree + '.' + key; | |
} else { | |
insertString = '' + key; | |
} | |
if (whatToScan[key].toString().toLowerCase().indexOf(whatToIgnore) === -1 && insertString.toLowerCase().indexOf(whatToIgnore) === -1) { | |
scanLoop(whatToScan[key], scanValue, whatToIgnore, insertString); | |
} | |
} | |
} | |
} | |
} catch (err) { | |
errArray.push('>> ' + err + ' while scanning ' + key); | |
} | |
} | |
} | |
function scanScope(whatToScan, scanValue, whatToIgnore, parentTree) { | |
console.log('%c------------------------- Beginning scan', 'color: gold'); | |
scanLoop(whatToScan, scanValue, whatToIgnore, parentTree); | |
if (funArray.length > 0 || errArray.length > 0) { | |
console.log('-------------------------'); | |
} | |
if (funArray.length > 0) { | |
console.groupCollapsed('Functions found while scanning'); | |
funArray.forEach(function(entry) { | |
console.log(entry); | |
}); | |
console.groupEnd(); | |
} | |
if (errArray.length > 0) { | |
console.groupCollapsed('Errors found while scanning'); | |
errArray.forEach(function(entry) { | |
console.log(entry); | |
}); | |
console.groupEnd(); | |
} | |
console.log('%c------------------------- Scan complete', 'color: gold'); | |
} | |
function exists(whatToCheck) { | |
if (whatToCheck !== null & whatToCheck !== undefined) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment