Want to see avatars on the SDMB? Here's a script.

Yay!

Na, it turns out I’d broken the script when I tried to get a poster’s username to appear with no avatar at all. Is there any way to do that?

To set a poster’s avatar to nothing, just leave the URL portion of that line set as two empty quotes.

For example in the list below, username3 would have no avatar. Note the list has to be separated by commas, and the last entry can’t have a comma.
‘username1’ : ‘url/image’, <comma
‘username2’ : ‘url/image’, <comma
‘username3’ : ‘’, <comma
‘username4’ : ‘url/image’ <no comma

For line 3 the url portion is just two single quotes.

It works! :slight_smile:

Now I have a different problem. When I try to set a custom image for Fear Itself the avatar size setting seems to get over ridden and all of the avatars are showing full size. E.g., Hockey Monkey’s is taking up half the browser width.

This is my entire avatar script:


// ==UserScript==
// @name           SDMB Avatars
// @namespace      SDMB_Avatars
// @description    SDMB Avatars
// @include        http://boards.straightdope.com/sdmb/*
// ==/UserScript==
(function() 
 {

// A user script based avatar system for the SDMB. By Polerius, ntucker, and Crazyhorse
// Last update: July 7, 2012

// ADDING YOUR AVATAR
// To add your own avatar so that you and other users of the script see it by your posts, edit your SDMB profile
// to include the line "SDMB Avatar: (URL to avatar)" in any area of your profile. example: "SDMB Avatar: www.images.com/myimage.jpg"
// After adding or changing an avatar URL in your profile it can take up to an hour for the new avatar to appear.

// SETTING THE DEFAULT DISPLAY SIZE
// The display size of avatars is set to 50x50 pixels by default. This size can be changed in the code 
// immediately below this comment. (ex. if you change "50" to "100", avatars will be displayed at 100x100)
var imgsize="50	";
// Hovering the mouse over an avatar while the Alt key is held down will display the avatar at full size.
// CUSTOM-ASSIGNED AVATARS
// Optionally add SDMB usernames and URLs in the list below to assign custom avatars to any posters.
// This can be used to block a given avatar by overriding their avatar choice, or to assign
// avatars to individual posters for any reason.

// Use the format <'username' : 'URL'> as shown in the examples below to add to the list.

var CustomAvatars = 	{	
				'Fear Itself' : 'http://www.motifake.com/image/demotivational-poster/0811/lord-douche-bag-cheerleader-demotivational-poster-1227638997.jpg',

			     	'SDMB Username' : 'http://link.to.image/image.jpg',

				'SdMb username 2' : 'http://another.image.link/image2.gif',
				
				'sdmb username 3' : 'http://another.link/image3.png' //<-- no comma after the final entry

				};
// DEFAULT AVATAR
// Optionally choose a default avatar to display for all posters without avatars. Enter the URL to an image between 
// the quotation marks in the line below this comment. Example: DefaultAvatar = "http://path.to.image/default_user.jpg";
// Set the URL to "" to disable this feature. 

var DefaultAvatar = "";  
// BANNED USER AVATAR
// Optionally choose a default avatar to display for any poster who has been banned. 
// Edit the line below this comment as with DefaultAvatar above, specifying a URL to an image for all banned users
// Example: BannedAvatar = "http://url.to.image/banned_user.jpg"   Set the URL to "" to disable this feature

var BannedAvatar = "";
// Happy Avataring
    function loadImage(header, imgurl) {
        var img = document.createElement('img');

        img.addEventListener('load', function(evt) {
            var img = evt.target;
            if(img.width > 1) {
                img.style.cssFloat = "left";
                img.style.marginRight = "5px";
                img.style.borderWidth = "0";
                img.style.maxWidth = imgsize+"px";
                img.style.maxHeight = imgsize+"px";

                function biggify(evt) {
                    if(!evt.altKey) return;

                    var img = evt.target;
                    img.style.maxWidth = null;
                    img.style.maxHeight = null;
                    img.addEventListener('mouseout', unbiggify);
                }
                function unbiggify(evt) {
                    var img = evt.target;
                    img.style.maxWidth = imgsize+"px";
                    img.style.maxHeight = imgsize+"px";
                    img.removeEventListener('mouseout', unbiggify);
                }
                img.addEventListener('mouseover', biggify);
                img.addEventListener('mousemove', biggify);
                header.insertBefore(img, header.firstChild);
            }
		else if (DefaultAvatar != ""){
			imageurl=DefaultAvatar;
			loadImage(header, imageurl);
		}
        });

        img.src = imgurl;
    }

    var allNameHeaders = document.getElementsByClassName('bigusername');

    for (var i = 0; i < allNameHeaders.length; i++)
    {
    
	var username = allNameHeaders*.innerHTML;
	var userhref = allNameHeaders*.href;
	var SplitID = userhref.split("u=");
	var userid1 = SplitID[1];
	var imageurl="http://splitter.august20th.com/sdmbav.rb?userid=" + userid1;
        if(username in CustomAvatars)
            imageurl = CustomAvatars[username];
	var hdr = allNameHeaders*;
	var title = hdr.parentNode.nextSibling.nextSibling;
	if(title.innerHTML == "BANNED" && BannedAvatar != "") {
            imageurl = BannedAvatar;
      }
        
      loadImage(allNameHeaders*, imageurl);
      }

 })();

I wonder if it has to do with editing it in TextEdit for Mac. When I’ve copy/pasted to this post it has inserted several spaces in the avatar size value. These spaces don’t appear to be in the file when I’m editing it, but maybe TextEdit is screwing with the file in some way.

I did try using ‘’ to display no avatar but it also seemed to break the script. I’ll try using a different edit program.
Something else occurs to me. Do I need to delete the examples for my real custom avatar for FI to work?

The space inside the quotes for the image size is causing that. Just change "50 " to “50” and it will fix the size problem. You can set that to a larger size like 100, too, but don’t add any extra spaces whatever size you choose.

The list of custom URLs looks fine. You don’t need to keep the examples in, but they won’t cause any harm as long as they remain intact and comma separated.

Very often if you make a simple change and the whole script stops working a small typo or missing comma will be the culprit.

Thing is, there is no space in the file itself. That space appeared when I cut and paste to the post you replied to. That’s why I wonder if TextEdit is breaking the file somehow.

Edit: I know what happened. At some point I changed the avatar size and when I changed it back to “50” I remember accidentally hitting the TAB key, but the second " just happened to be already at the next tab stop so it didn’t show any space between the 50 and the ". Because no space was shown I assumed I hadn’t hit the TAB key enough for it to register and didn’t worry about it. But that TAB information was still there and that was breaking the code. It’s all fixed now.

Ah, good detective work. In general textedit should be perfectly compatible but that tiny tab could do it.

Test.

ETA: This is pretty cool thx.

I can see your avatar now, but still not seeing it for the others that I mentioned.

It seems to be something imageshack does to people in certain regions, Thailand apparently one of them, where a free-hosted image might sometimes appear instead as an imageshack advertisement. That was reason enough for me to switch to a different image host.

Chrome is not letting me run Greasemonkey. I found a solution online… but could someone explain it so a technophobe like myself can understand it? :frowning:

About a month has passed since the huge debate here…taking stock, what I see is that virtually no new posters use avatars, and I would guess that almost all veterans who wanted to add them have likely added them by now, but there’s still a lot of vets who haven’t and likely never will. I don’t know if this would be representative of what would happen if avatars were added officially without the need for a separate plugin, but I am a bit disappointed that they aren’t seeing more widespread use.

Most of the avatars you are seeing don’t represent people who added the script. Most are people who have a picture in their profile, and the script of other users picks that up and displays it as an avatar. I do not currently have an avatar, yet I assume you see one next to my name.

For Chrome you don’t need Greasemonkey. Chrome has a built in “Greasemonkey like thing”. Just go and download the program and Chrome picks it up and says something like, “Do you want to install this?” you say yes and then you go into tools, or what’s it called, and then click on “add extension” or “expansion” or something and then click ok and it should just work.

I did it once and don’t really remember how and I also only have Chrome at home.

You’ll always have the occassional new guy who’ll ask about avatars, and so you can just point to this thread.

(And the whole “assign people an avatar” option is just too good to pass up.)

I didn’t know that. Just curious - is my crunluath showing up on your display, John DiFool? I’ve not added the script.

Ah but you do. For some reason, you were the only person to whom I assigned my own choice of avatar. It’s not very flattering, but I’m too lazy to change it back now. Shame: I don’t think I have anything against you as a poster.

Yes, those with the script have the crunluath show up next to your name. Coincidentally, after some googling, I now know what a crunluath is.

Random trivia: there appear to be about 435 different users running the avatar script, based on server logs. More than I would have expected.

Can anyone tell me what I’ve done wrong? I can see your avatars but I can’t see my own.

Edit: and now I can, please ignore this post.