The script is now 40 times faster! Due to a programming oversight, the old script takes much longer than it needs to in order to work. This can cause Firefox to lock up for up to 10 seconds on pages that have a lot of smileys.
[spoiler]If you use Firefox, click here and press the big “Add to Firefox” button to install GreaseMonkey. (Confirm any dialog boxes, and restart Firefox if prompted.) If you use Chrome, click here and press the “+ Free” button to install TamperMonkey. (Confirm any dialog boxes.)
Then, whichever browser you use, click here and press the “Install” button to install the “SDMB Old Smileys” script I extracted. Again, confirm any dialog boxes that appear.
(“Confirming a dialog box” means to click the button that will continue the action, such as “Install” or “Add” or “Yes” or “OK.”)
And, yes, Internet Explorer users are out of luck, like pretty much always[/spoiler]
For anyone who wants the details of the faster speed:
[spoiler]The script I copied used Search/Replace to change the image URLs. This means it would check each source string multiple times to see if it contained the URL. Instead, I now check each image URL only once per smiley, and replace the whole thing all at once.
I also added short circuiting, which means it will stop as soon as a replacement is made, and utilized a newish JavaScript feature called forEach which can utilize multiple processors. This only saved around 1% on the time, however. The big win is using if statements instead of Search/Replace.[/spoiler]
I can walk you through this, but in testing to make sure it worked, I stumbled upon something that makes me question if I should support users of the SDMB Avatar script.
Is there something in the avatar script you might want to tell me about, that I might want to get fixed?
Yes, that is correct. I actually debated leaving the smileys on the edit page unswitched to remind users that most people are going to see the new smileys, not the old ones.
// A user script based avatar system for the SDMB. By Polerius, Spinky, and Crazyhorse
// Last update: March 11, 2014 - added option to use old board smileys
// 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=“80”;
// 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 = {
'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 = “”;
//Use old SDMB Smileys
//If this is on the old (Pre March 2014 board upgrade) smileys will be displayed
//to you and other users of the script instead of the newer ones.
var UseOldSmileys = “off”; //set to “on” or “off”
// Happy Avataring
if (UseOldSmileys.toLowerCase() == “on”)
{
window.addEventListener(‘load’, function() {
var images = document.getElementsByTagName(‘img’);
for (var i = 0; i < images.length; i++) {
images*.src = images*.src.replace(‘http://boards.straightdope.com/sdmb/images/smilies/smile.gif’, ‘data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAMAAAAMCGV4AAAAflBMVEXAwMAAAACCZgCFaACIawCJbACJbQCNcQCOcQCQdACSdQCUdwCZfACdfwCfggCgggCihQClhwCpjACqjQCsjgCtjwCxkwC1lwC2mAC5mwC8ngDBowDFpgDGpwDNrgDQsQDRsgDTtADYuQDevgDgwQDjwwDqygDtzQDz0wD31wBBwt/MAAAAAXRSTlMAQObYZgAAAI1JREFUCB0FgDFKBEEABKtnN7hTLhD8gML5/+eYGqiJIKKBrNNTEgACIECA8GhX3xECuUY72+NTNnIdI4i6H+yQPPOUvHIfGHlUUEHPSR62RDvb42/+7pREq0sXO8sRl22rDNqXOdu23y0bPzeXt9vV9us0lyF3Ix8Ap1kN5BLVzqUECGeXXQgBIAAC/ANkLmjbVUdosQAAAABJRU5ErkJggg==’);
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);
}
})();[/spoiler]which contains this “Use old SDMB Smileys”, I’m pretty sure it came with this “var UseOldSmileys = “off”; //set to “on” or “off”” set to “on” (I turned it off last night).
I assume that trying to use two GM scripts to do the same thing just might cause a conflict, so I thought I’d give ya’ll a heads up.
Then you’ve already fixed the conflict, just by turning it off in the other add-on.
I believe you may have misinterpreted my reply to you. I know what the Avatar script is. My script was originally just copied from it. (And he subsequently copied it back so he could embed the images.) Eventually he will probably copy my new code into the Avatar script.
I am questioning whether I should support a script that is being used to make fun of certain posters. Though I now know the person hosting the images is not the person who made the script.