Created
October 5, 2018 13:53
-
-
Save postworthy/0b3243f656ed0c15b56240800ef900ca 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
var endpointFinder = function (log) { | |
var internal = new Array(); | |
var callback = function (x) { | |
internal.push(x); | |
if(log) log(x); | |
}; | |
var visitor = function (obj, fMatch) { | |
if (matchString(obj)) return; | |
var keys = Object.keys(obj); | |
for (var k in keys) { | |
var o = obj[keys[k]]; | |
if (o == null) return; | |
if (fMatch(o)) | |
callback({ Obj: obj, Prop: keys[k], val: o }); | |
else | |
visitor(o, fMatch); | |
} | |
}; | |
var matchString = function (o) { | |
return (typeof o === 'string' || o instanceof String); | |
} | |
var matchUrl = function (o) { | |
return (typeof o === 'string' || o instanceof String) && o.length > 1 && (o[0] == '/' || o.toLowerCase().startsWith("http")); | |
} | |
var matchFinds = function (o) { | |
try { | |
var f = String(o); | |
if (!f.includes("[native code]") && f.startsWith("function")) { | |
var some = internal.some(function (x, y, z) { return f.includes(x.Prop); }); | |
//if(some) | |
// console.log(o); | |
return some; | |
} | |
} catch(ex){ } | |
return false; | |
} | |
var ret = { | |
findUrls: function () { | |
internal = new Array(); | |
var keys = Object.keys(window); | |
for (var k in keys) { | |
var o = window[keys[k]]; | |
try { | |
var obj = JSON.stringify(o); | |
if (obj) visitor(o, matchUrl); | |
} catch (ex) { } | |
} | |
return ret; | |
}, | |
dump: function (func) { | |
console.log("***********************"); | |
if (func) func(internal); | |
else console.log(internal); | |
console.log("***********************"); | |
return ret; | |
}, | |
dumpFunctions: function () { | |
internal.forEach(function (x) { | |
if (typeof x.val === 'function') | |
console.log(x.val); | |
}); | |
}, | |
findUrlReferences: function () { | |
var keys = Object.keys(window); | |
for (var k in keys) { | |
var o = window[keys[k]]; | |
try { | |
var obj = JSON.stringify(o); | |
if (obj) visitor(o, matchFinds); | |
} catch (ex) { } | |
} | |
return ret; | |
} | |
}; | |
return ret; | |
}().findUrls().findUrlReferences().dumpFunctions(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment