Skip to content

Instantly share code, notes, and snippets.

@samdenty
Created August 29, 2018 16:01

Revisions

  1. samdenty created this gist Aug 29, 2018.
    32 changes: 32 additions & 0 deletions Chrome getCompletions.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    (function getCompletions(type) {
    let object;
    if (type === "string") object = new String("");
    else if (type === "number") object = new Number(0);
    else if (type === "bigint") object = Object(BigInt(0));
    else if (type === "boolean") object = new Boolean(false);
    else object = this;
    const result = [];
    try {
    for (let o = object; o; o = Object.getPrototypeOf(o)) {
    if (
    (type === "array" || type === "typedarray") &&
    o === object &&
    o.length > 9999
    )
    continue;
    const group = { items: [], __proto__: null };
    try {
    if (typeof o === "object" && o.constructor && o.constructor.name)
    group.title = o.constructor.name;
    } catch (ee) { }
    result[result.length] = group;
    const names = Object.getOwnPropertyNames(o);
    const isArray = Array.isArray(o);
    for (let i = 0; i < names.length && group.items.length < 10000; ++i) {
    if (isArray && /^[0-9]/.test(names[i])) continue;
    group.items[group.items.length] = names[i];
    }
    }
    } catch (e) { }
    return result;
    });