Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grahamperrin

macrumors 601
Original poster
Jun 8, 2007
4,942
648
Please

What stylesheet override can allow a click on a user's name, or his or her avatar, to open the profile in a new window?

Background

I was always surprised by Command-Click never working as expected for clicks on names and avatars whilst reading a topic.

I did not look at profiles often enough for the misbehaviour to bother me.

I realised that Command-Click can work as expected when twenty-six or more posts are on the page – thanks to AutoPagerize (see https://forums.macrumors.com/posts/21455119 and https://forums.macrumors.com/posts/21457821) – but there remains the misbehaviour for the first twenty-five.

I'd like a new tab, consistently, for any and every Command-Click on a name or avatar.
 
Javascript can do this, but not CSS. And it's likely the solution would be to turn the profile link into a normal link, meaning no way to show the user card with a regular click.
 
Based on your post mentioning AutoPagerize, @grahamperrin, you're already familiar with user scripts. Here is a rather clunky workaround for pasting into a new user script:

Code:
// ==UserScript==
// @name UserWindow
// @namespace http://ss-o.net/
// @include https://forums.macrumors.com/*
// ==/UserScript==
var usernames = document.getElementsByClassName('username');
for (var n = 0; n < usernames.length; n++){
    if (usernames[n].tagName == 'A'){
        usernames[n].setAttribute('target', '_blank'); // <----
        usernames[n].className = 'dummy';
        usernames[n].style.fontWeight = 'bold';
        n--;
    }
}

After applying it, simply clicking on names should open profiles in new tabs. EDIT: If you remove the indicated line, the error @redheeler posted won't occur, but you will need to command-click to open profiles in a new tab instead.
 
Last edited:
  • Like
Reactions: grahamperrin
Based on your post mentioning AutoPagerize, @grahamperrin, you're already familiar with user scripts. Here is a rather clunky workaround for pasting into a new user script:

Code:
// ==UserScript==
// @name UserWindow
// @namespace http://ss-o.net/
// @include https://forums.macrumors.com/*
// ==/UserScript==
var usernames = document.getElementsByClassName('username');
for (var n = 0; n < usernames.length; n++){
    if (usernames[n].tagName == 'A'){
        usernames[n].setAttribute('target', '_blank');
        usernames[n].className = 'dummy';
        usernames[n].style.fontWeight = 'bold';
        n--;
    }
}

After applying it, clicking on names should open profiles in new tabs.
What a fantastic idea :D
Screen Shot 2015-06-16 at 2.58.22 PM.png
 
  • Like
Reactions: grahamperrin
Urm, yes, I thought it was quite an improvement. :p:oops: How frequently did that appear compared to nothing popping up except for a new tab? Also, what user script extension are you using? I'd like something different from NinjaKit.
My own extension which cleanly injects Javascript files into MacRumors Forums like a Safari extension should. I've been nicely browsing the forums with Retina avatars and "Thread Starter" badges for the OP, although your script seems to have broken one of those things :)

It does it every time I click on a username link.
 
My own extension which cleanly injects Javascript files into MacRumors Forums like a Safari extension should. I've been nicely browsing the forums with Retina avatars and "Thread Starter" badges for the OP, although your script seems to have broken one of those things :)

It does it every time I click on a username link.

Yeah, yeah, yeah, don't worry about making me jealous with all your pixels; 72dpi is totally fine with me. Yep. Completely. :p
Ah, I can imagine how that happened. Ideally, a script would prevent the calling of whatever function pulls up the member info overlay, but I haven't ben able to find out where in the xenforo.js and other scripts that occurs.

Nope, it's still happening the way I described.

Darn. I wonder which confounding variable is causing this difference. EDIT: It just happened to me a few times, but refreshing the page cleared it up. 'Clunky' might've been an underestimation of this script's functionality.
 
  • Like
Reactions: grahamperrin
Please

What stylesheet override can allow a click on a user's name, or his or her avatar, to open the profile in a new window?
Just right click the name and select open in a new tab. I don't see the need to try to implement such kludgy work arounds.
 
  • Like
Reactions: grahamperrin
… right click … open in a new tab …

Yes, but (defocusing from the redesigned MacRumors) I'm always bothered when a Command- variation to Click, Enter or Return does not work as expected. For example, with vBulletin here, every part of the search interface that required a contextual menu was a minor annoyance every time that requirement hit me. I always had to think twice before using the Command key; think, then refrain from using the Command key.

To clarify: I don't suggest a change to the site.

… If you remove the indicated line …

Sorry, I lack the script fu. Which line?
 
Here. This opens a profile in a new tab in addition to the user pop-up card on a Command-click of a username or avatar (@grahamperrin if you're still browsing without avatars you can remove the last line). It won't work with posts that have been inserted after the page load.
Code:
function openNewWindowOnCommandClick(linkElements){
    for(var i=0; i<linkElements.length; i++){
        linkElements[i].onclick = function(e){
            if(e.metaKey){
                window.open(this.href);
            }
        }
    }
}
openNewWindowOnCommandClick(document.getElementsByClassName('username'));
openNewWindowOnCommandClick(document.getElementsByClassName('avatar'));
 
From the opening post:

… I'd like a new tab, consistently, for any and every Command-Click on a name or avatar.

That wish is realised, so the topic is resolved, but it remains open for any additional contributions.

Thanks are as indicated above :)
 
I've been nicely browsing the forums with Retina avatars and "Thread Starter" badges for the OP, although your script seems to have broken one of those things :)
Out of curiously, would you mind sharing the script for thread starter badges?
 
Out of curiously, would you mind sharing the script for thread starter badges?
No problem :)
Code:
function displayThreadStarter(){
    var pageDescription = document.getElementById('pageDescription');
    if(pageDescription == null || pageDescription.getElementsByClassName('username')[0] == null){return;}
    var originalPoster = pageDescription.getElementsByClassName('username')[0].innerHTML;
    var posts = document.getElementsByClassName('message');
    for(var i=0; i<posts.length; i++) {
        var post = posts[i];
        var poster = post.getAttribute('data-author');
        if(poster == originalPoster){
            post.getElementsByClassName('userText')[1].innerHTML += '<em class="userBanner wrapped" itemprop="title" style="background: rgb(84, 191, 86);"><span class="before"></span><strong>Thread Starter</strong><span class="after"></span></em>';
        }
    }
}
 
  • Like
Reactions: AngerDanger
No problem :)
Code:
function displayThreadStarter(){
    var pageDescription = document.getElementById('pageDescription');
    if(pageDescription == null || pageDescription.getElementsByClassName('username')[0] == null){return;}
    var originalPoster = pageDescription.getElementsByClassName('username')[0].innerHTML;
    var posts = document.getElementsByClassName('message');
    for(var i=0; i<posts.length; i++) {
        var post = posts[i];
        var poster = post.getAttribute('data-author');
        if(poster == originalPoster){
            post.getElementsByClassName('userText')[1].innerHTML += '<em class="userBanner wrapped" itemprop="title" style="background: rgb(84, 191, 86);"><span class="before"></span><strong>Thread Starter</strong><span class="after"></span></em>';
        }
    }
}

Thanks! FYI, if you want to stay true to Xenforo (whatever that means), userBanner has a class with a green background called bannerGreen. :)
 
Thanks! FYI, if you want to stay true to Xenforo (whatever that means), userBanner has a class with a green background called bannerGreen. :)
Oh, I hadn't noticed that. It's actually closer to the shade of green used for "Thread Starter" on the old forums. I'll have to decide which I like more, but I'm leaning toward the lighter green, just as the "Staff Member" badge uses a custom shade of red.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.