So I kinda-sorta made signatures...


  • BINNED

    I was bored...

    // ==UserScript==
    // @name        TDWTF signatures
    // @namespace   TDWTF
    // @include     http://what.thedailywtf.com/*
    // @version     1
    // @grant       none
    // ==/UserScript==
    var sig = 'Customize your signature here!';
    
    document.addEventListener('mousedown', function (event) {
        // Trigger only on "Reply" button in submit-panel
        if(event.target.className.indexOf('create') > -1 && event.target.parentNode.className.indexOf('submit-panel') > -1)
        {
            var postInputArea = document.getElementById('wmd-input');
            var postText = postInputArea.value;
            
            // Check if signature has already been appended
            if (postText.indexOf('tdwtf_signature_marker') == -1)
            {
                // Append the signature
                postInputArea.value = postText + '\n\r\n\r<tdwtf_signature_marker></tdwtf_signature_marker><hr>' + sig;
            }
        }
    });
    

    I didn't submit it anywhere yet since I'm after some scrutinizing, and what better place than TDWTF to get it.

    Also, someone who has access to IE should probably try it. I suspect it doesn't work, there should be a check if addEventListener is available and fall back to attachEvent if not, but I can't test that properly so I didn't add it yet.



  • IE supports userscripts?


  • BINNED

    @Arantor said:

    IE supports userscripts?

    I don't know. I'd guess you could do it in some capacity. Maybe not userscripts per-se, but "run this piece of JS on this here site" is not some kind of incredible technology that only higher beings browsers can accomplish.

    … right?



  • I think you may be thinking too highly.


  • BINNED

    Ok, so I see one problem with this - "signatures" will get quoted. I think I could change the marker tags to denote start and end of signature and remove contents from DOM on quote button click. But I don't have the time now.

    This would, of course, only work for those who have it active. But short of the plugin that's the best I can do.


  • Winner of the 2016 Presidential Election

    I made my modifications but my javascript is rusty and I can't be bothered to look up the functions I most likely screwed up. Can anybody fix it:

    // ==UserScript==
    // @name        TDWTF signatures
    // @namespace   TDWTF
    // @include     http://what.thedailywtf.com/*
    // @version     1
    // @grant       none
    // ==/UserScript==
    
    document.addEventListener('mousedown', function (event) {
        // Trigger only on "Reply" button in submit-panel
        if(event.target.className.indexOf('create') > -1 && event.target.parentNode.className.indexOf('submit-panel') > -1)
        {
            var postInputArea = document.getElementById('wmd-input');
            var postText = postInputArea.value;
    
            // Check if signature has already been appended
            if (postText.indexOf('Filed Under:') == -1)
            {
                var tagstring = "";
                var tags = new array();
                prompt("add Tags (split with | ):", tagstring);
                tags = tagstring.split('|');
                tagstring = "Filed Under:";
                for(i = 0; i<tags.size(); i++){
                    tagstring += ' [' + tags[i] + '](#tag) |';
                }
                tagstring = substr(tagstring, -1); // Remove last |
                // Append the Tags
                postInputArea.value += '\n\r\n\r<hr />' + tagstring;
            }
        }
    });```
    Because who needs signatures if you can just add tags to everything :smiley:
    Also: I want this as a plugin for Discourse (with an option in settings to turn it on and off) 
    Also, please note my amazing reuse of tagstring. Thats totally well designed code, right?
    
    Filed Under: [did JS have foreach?](#tag) |  [\[code\]\[/code\] do nothing T_T](#tag)

  • BINNED

    @Kuro said:

    Filed Under: did JS have foreach?

    Kind of:

    for(i in arr)
        console.log(i + "th element of array is " + arr[i]);
    

    @Kuro said:

    do nothing T_T

    They do. They break quotes, apparently. Also:

    http://what.thedailywtf.com/t/posting-on-tdwtf-101/614



  • @Kuro said:

    did JS have foreach?

    First result on Google for javascript foreach:

    Also, I suggest splitting on commas and shuffling the array before converting back to a string, for old time's sake.


    Filed under: There's markdown for <hr>



  • Will this implementation support Signature Guys? That's a much-missed feature.



  • This post is deleted!


  • This post is deleted!

Log in to reply