Resolved Preferring a new window, not the overlay, for a click on a user

grahamperrin

macrumors 601
Original poster
Jun 8, 2007
4,946
627
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 http://forums.macrumors.com/posts/21455119 and http://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.
 

redheeler

macrumors 604
Oct 17, 2014
7,398
6,965
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.
 

grahamperrin

macrumors 601
Original poster
Jun 8, 2007
4,946
627

AngerDanger

macrumors 601
Dec 9, 2008
4,384
19,073
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 http://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

redheeler

macrumors 604
Oct 17, 2014
7,398
6,965
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 http://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

redheeler

macrumors 604
Oct 17, 2014
7,398
6,965
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.
 

redheeler

macrumors 604
Oct 17, 2014
7,398
6,965
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.
Nope, it's still happening the way I described.
 

AngerDanger

macrumors 601
Dec 9, 2008
4,384
19,073
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

grahamperrin

macrumors 601
Original poster
Jun 8, 2007
4,946
627
… 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?
 

redheeler

macrumors 604
Oct 17, 2014
7,398
6,965
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'));
 

grahamperrin

macrumors 601
Original poster
Jun 8, 2007
4,946
627
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 :)
 

AngerDanger

macrumors 601
Dec 9, 2008
4,384
19,073
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?
 

redheeler

macrumors 604
Oct 17, 2014
7,398
6,965
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

AngerDanger

macrumors 601
Dec 9, 2008
4,384
19,073
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. :)
 

redheeler

macrumors 604
Oct 17, 2014
7,398
6,965
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.