Frick / ttplus

Turntable Plus - a fan-made Chrome Extension!
http://turntableplus.fm
48 stars 16 forks source link

Look up any user <Feature Request> #41

Open BenTheHokie opened 11 years ago

BenTheHokie commented 11 years ago

The ability to pull up any user's profile by simply typing their name in. I have some javascript code that you might be able to use to incorporate into your extension.

Get the "room":

for (var a in turntable) {
    var b = turntable[a];
    if (typeof b !== "object" || b === null) {
        continue
    }
    if (typeof b.setupRoom !== "undefined") {
        room = b;
    }
}

Get the room manager:

for (var a in room) {
    var b = room[a];
    if (typeof b !== "object" || b === null) {
        continue
    }
    if (typeof b.blackswan !== "undefined") {
        var manager = b;
    }
}

Get the websocket for the API. You may be able to use your TTPAPI for this part:

var a = / Preparing message /i;
for (var b in turntable) {
    var c = turntable[b];
    if (typeof c !== "function") {
        continue
    }
    c.toString = Function.prototype.toString;
    if (a.test(c.toString())) {
        ttApi = c;
    }
}

Pull up the profile:

javascript: var userName = prompt('User to search for:');
if (userName != null) {
    ttApi({
        api: 'user.get_id',
        name: userName
    }, function (m) {
        if (m.err) {
            turntable.showAlert('Error: ' + m.err);
        } else {
            manager.callback('profile', m.userid);
        }
    });
}