Finding JavaScript function in the global scope

折月煮酒 提交于 2019-12-04 17:09:30

Loading https://github.com/angus-c/waldo and using it from the console looks like it should do the trick. A little more complex but also tool-agnostic.

I wrote up the recursive type function I mentioned in the comment as an anonymous function

(function(searchTerm, parent, parentStr, depthLeft, parentsArr){
    var p = parent || window,
        child, cObj = null,
        s = parentStr || '',
        r = [],
        d = (depthLeft > 0 ? depthLeft-1 : 5),
        pArr = parentsArr || [p];
    for( child in p ){
        cObj = p[child];
        if ( child === searchTerm ) r[ r.length ] = (s+'.'+child).slice(1);
        if( d > 0 && cObj !== null && p.hasOwnProperty(child) && typeof cObj === 'object' && cObj !== p && pArr.indexOf(cObj) === -1 )
            r = r.concat( arguments.callee( searchTerm, cObj, s+'.'+child, d, pArr.concat([cObj]) ) );
    }
    return r;
})('createElement');

Last line means will search for .createElement, starting from window. The deeper you go, the longer it will take.

If the function is global, you can call it from a userscript using this constructor:

var global = new Global(); // Initialize the Global constructor
// Some code
var globalVar = global.get('variableName'); // Assign the global variable 'variableName' to the local variable 'globalVar'

Because closures cannot be called from the global scope, you will have to use string searching to get any of those (as far as I know).

The only way I can think of is by parsing your scripts and using regular expressions to avoid strings and other cases you may not want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!