LeonMarchetti / tampermonkey-scripts

Scripts for the Tampermonkey browser extension
1 stars 0 forks source link

Búsqueda de variables globales #14

Closed LeonMarchetti closed 5 months ago

LeonMarchetti commented 5 months ago

Función global para encontrar variables globales:

/**
 * Searches global variables and prints results in console
 *
 * @param {string} [text=""] Search text of the variable's name
 * @param {string} [type=""] Type of variable to search, empty returns all types
 */
function searchVariable(text = "", type = "") {
    // console.debug(`text = "${text}"\ntipo = "${type}"`);
    var variables;
    var sortedKeys = Object.keys(unsafeWindow).sort();
    if (type) {
        variables = sortedKeys.filter(v => v.indexOf(text) >= 0 && (typeof unsafeWindow[v] == type));
    } else {
        variables = sortedKeys.filter(v => v.indexOf(text) >= 0);
    }
    var table = variables.map(v => ({
        "variable": v,
        "type": typeof unsafeWindow[v]
    }));
    console.table(table);
}

unsafeWindow.searchVariable = searchVariable;