Better Likes: A tale of one Userscript


  • FoxDev

    Continuing the discussion from The Official "Likes" Thread - Still not v1.0!:

    @abarker said:

    Please share once you get it worked out!

    I accept no responsibility for damage caused by using this script.

    // ==UserScript==
    // @name       Better Likes
    // @namespace  http://use.i.E.your.homepage/
    // @version    0.1
    // @description  enter something useful
    // @match      http://what.thedailywtf.com/t/*
    // @copyright  2012+, You
    // @require    https://raw.githubusercontent.com/bestiejs/punycode.js/master/punycode.min.js
    // ==/UserScript==
    
    var icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAACtSURBVDhPY8AGOjs7edva2t43NDT8B+Hm5uaPCxYsUIZKEwYVFRWCMM0wvGjRIh2oNGEwDAzo7u4WQzdgxYoV2A3o6Oi42NLS8hsZA0P9D7oBTU1Nf9DVAfEPBiDxBV0xKZihtbX1OzYJYjHIgCvYJIjBjY2Nv0EG6AEZ7sgYGAaR6Iq7urrS0dUBsS00KFHBaEpkYKivr+cBBuQLmGZgWvm4ZMkSeag0EmBgAADrZ1TWrm6cWgAAAABJRU5ErkJggg==';
    
    function BetterLikes (){
    	//attach to posts
    	var posts = document.body.querySelectorAll('article:not(.BetterLikes)');
        
        Array.prototype.forEach.call(posts, function(p){
            var post = p.attributes['id'].value.substring(5) *1;
            var actions = p.querySelector('div.actions');
            var reply = actions.querySelector('.create');
            var button = document.createElement('button');
            var i = document.createElement('i');
            button.appendChild(i);
            var img = document.createElement('img');
            img.src = icon;
            i.appendChild(img);
            i.onclick = function(){
                reply.click();
                setTimeout(function(){
                    var input = document.body.querySelector('#wmd-input');
                    
                    input.innerHTML='+['+punycode.ucs2.encode([post])+'][1]\n\n[1]: http://unicode-table.com/en/#'+ (post).toString(16);
                },20);
            }
            actions.insertBefore(button, actions.children[0]);
            p.className += ' BetterLikes';
        });
    }
    setInterval(BetterLikes,50);
    
    


  • Um, what does this do? Brain no worky good enough to parse JavaScript right now.


  • :belt_onion:

    adds buttons to all the posts that you can hit to start a reply with +&#POSTNUMBER; to make the +孾 like-posts

    I believe, didn't try it.



  • Interesting.


  • FoxDev

    exactly, except it uses the post number in the topic, not overall. we're already past the end of the unicode codepoints and i didn't feel like inventing a mapping.

    that does mean it doesn't get interesting for quite a while and there are a lot of posts that it doesn't produce a printable character, but it tries.

    I'll make it better tonight after i've had a beer or two.


  • :belt_onion:

    @accalia said:

    exactly, except it uses the post number in the topic, not overall. we're already past the end of the unicode codepoints and i didn't feel like inventing a mapping.

    no we arent...?
    There's a solid 9,000 - 10,000 left in the likes topic before they start failing.

    or did i misunderstand what you mean?


  • FoxDev

    your post id, the one i'm replying to is: 67428

    outside the range of 0-65535 that unicode has codepoints for.

    at least according to the markup, like i said i'll make it better after work today.

    so i used the post number within the topic, not overall.



  • Oh, there are characters beyond FFFF in Unicode.


  • :belt_onion:

    i said post number, i meant post number
    "post #6"
    however, for low # posts that doesn't do anything either of course, but it's mainly only needed in likes topic anyway.


  • FoxDev

    @Arantor said:

    Oh, there are characters beyond FFFF in Unicode.

    technically yes. but when was the last time you saw a font for anything other than the basic multilingual plane?



  • Phone emoji, anyone?


  • FoxDev

    actually there's an idea...

    add an emojii "keyboard" to discourse. in 100$ js, no frameworks allowed.

    that sounds like a fun weekend project!



  • @accalia said:

    when was the last time you saw a font for anything other than the basic multilingual plane?
    Last time I looked at TDWTF using <shudder> IE. This was a topic of discussion a while ago. At least some common Windows fonts have glyphs beyond the BMP. Application support is spotty; Chrome refuses to display them, even though IE does.


  • ♿ (Parody)

    @HardwareGeek said:

    Chrome refuses to display them, even though IE does.

    FF seems pretty good about it, too (though I haven't tried on Windows).


  • :belt_onion:

    @HardwareGeek said:

    Chrome refuses to display them

    Except in the URL bar for whatever god-forsaken reason. The place where they're LEAST needed.



  • @accalia said:

    it uses the post number in the topic, not overall.

    That's what we mean, anyway.

    Click reply. See "Replying to post 12345 by <avatar> foo." Type +&#12345;



  • @darkmatter said:

    Except in the URL bar for whatever god-forsaken reason. The place where they're LEAST needed.

    Ooook. Never noticed that.


  • :belt_onion:

    Some of them still don't work, even in the URL bar, but it has better support than the pages or editors themselves. Maybe if the encoding were set within the html head of the page to the correct thing, it might render though.


Log in to reply