19

See this link?

This link doesn't presently exist. I'm here to request its addition, so that visiting someone's profile on the same site as the one you're chatting on won't be a potentially long path.

If I'm chatting, and a user's profile is linked to the same site as the one the chat room belongs to, it's pretty simple to visit their profile. However, consider this situation:

  • I am on a chat room belonging to Role-Playing Games Stack Exchange
  • There is a user in there whose RPG.SE profile I would like to see
  • The user's parent profile belongs to a site other than RPG.SE

In this situation, the path to getting to their RPG.SE profile (if they have one) can be a long path.

The current path when their parent profile is on another SE site

1. Click the parent user link

2. Arrive at their parent profile

3. Scroll down, find the site in question, click

Goal!

The current path when their RPG.SE profile is not in their top 5

1. Click the parent user link

2. Arrive at their parent profile

3. Scroll down to the accounts list. RPG.SE isn't there; click 'view more'

4. Arrive at their global Stack Exchange profile

5. Scroll down or ctrl+f, find the site, click

Goal!

Both of these paths would be replaced with one the same length as if their parent user matched the site the chat is on: pop open that menu, click the link.

  • What should happen if the user doesn't have a profile on the given site? – Monica Cellio May 19 '15 at 18:32
  • @Monica It should probably not show up at all. – doppelgreener May 19 '15 at 23:03
7
+50

I've written a userscript to accomplish this.

GitHub link. Direct link.

If it doesn't work initially for you try increasing the timeout on line 105. If you find any bugs please let me know!

has profile

If you're in a network chat room (ones that aren't attached to any site) it will instead link to the user's network profile.

network profile

If the user has no profile it will tell you that as well.

no profile

// ==UserScript==
// @name        Chat site profiler thingy
// @namespace   http://askubuntu.com/users/44179
// @include     *chat.stackexchange.com/*
// @include     *chat.stackoverflow.com/*
// @include     *chat.meta.stackexchange.com/*
// @version     1
// @grant       none
// ==/UserScript==

    var networkID = "";
    var userID = "";
    var userBaseSite = "";
    var userBaseSiteID = "";
    var siteProfile = "";
    var mainSiteURL = $('#footer-logo > a').attr('href');
    var baseUserURL = mainSiteURL + "/users/";
    var mainSiteName = $('#footer-logo > a').attr('title').replace(/&/g, "&");
    var json;

    function getAssocAccounts(pageNum) {
        xhr = new XMLHttpRequest();
        xhr.open('GET', "https://api.stackexchange.com/2.2/users/" + networkID + "/associated?page=" + pageNum +  "&pagesize=100&filter=!*L2(U8cAI.NDVpWE", false);
        xhr.send();

        return xhr.response;
    }

    function findLocalProfile(data) {
        for (var item in data.items) {
            if (data.items[item].site_name == mainSiteName || data.items[item].site_name == mainSiteName + " Stack Exchange") {
                console.log(data.items[item].site_name);
                userID = data.items[item].user_id;
                siteProfile = "<a href='" + baseUserURL + userID + "'> user profile on this site </a>";
                return true;
            }
        }
        return false;
    }

    function setSiteProfile() {
        if (mainSiteName == "The Stack Exchange Network") {
            siteProfile = "<a href='" + baseUserURL + networkID + "?tab=accounts" + "'> network profile </a>";
        }
        else {
            var json =  JSON.parse(getAssocAccounts(1));
            if (findLocalProfile(json)) {
                return;
            }
            json = JSON.parse(getAssocAccounts(2));
            if (findLocalProfile(json)) {
                return;
            }
            else {
                siteProfile = "<a> user has no profile on site </a>";
            }
        }
    }

    function setNetworkID() {
        userBaseSite = $('.user-popup').find('div:contains("user profile on") > a').attr('href').split('/')[2].split('.')[0];
        userBaseSiteID = $('.user-popup').find("a:contains('user profile')")[1].href.split("/")[4];

        xhr = new XMLHttpRequest();
        xhr.open('GET', "https://api.stackexchange.com/2.2/users/" + userBaseSiteID + "?order=desc&sort=reputation&site=" + userBaseSite + "&filter=!23IbozPckvHAbU7zwAs_E", false);
        xhr.send();

        var response = xhr.response;
        var json = JSON.parse(response);
        networkID = json.items[0].account_id;
        console.log(networkID);
    }

    function doIt() {
        if ($('.user-popup').length > 0) {
            setNetworkID();
            setSiteProfile();
            console.log("inserting link");
            $('.user-popup').find('div:contains("user profile")').next().eq(0).after(siteProfile);
            return;
        }
        else {
            console.log("No popup");
        }
    }

    $('.avatar, #chat').click(function() {
        // if it doesn't work initially, try increasing the timeout (default: 300)
        window.setTimeout(doIt, 300);
    });

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .