WEB Any of you nigs use Greasemonkey? I want to make a script for SFTW..

Discussion in 'OT Technology' started by Jesse, Dec 12, 2008.

  1. Jesse

    Jesse PSN: iamajesse; XBL: Inhale My Rod; G8 GT crew; Ne OT Supporter

    Joined:
    Jan 12, 2005
    Messages:
    25,649
    Likes Received:
    0
    Location:
    California :: (925)
    Currently, my thoughts are for just OT: Replace the common smilies (mamoru, rofl, ugh, hsugh, etc) with Xmas emoticons, hosted by SmiliesFTW.

    It would need to replace the BB code with BB code for SFTW, on the fly.. I'm not talking just so you can see certain images differently (replacing html with more html), but so you actually post the image differently, so everyone could see it.

    Anyone got some useful info for doing this? or want to help with it?

    I'll S your D.
     
  2. Jesse

    Jesse PSN: iamajesse; XBL: Inhale My Rod; G8 GT crew; Ne OT Supporter

    Joined:
    Jan 12, 2005
    Messages:
    25,649
    Likes Received:
    0
    Location:
    California :: (925)
    Could this be better done with a Firefox extension?
     
  3. GlassUser

    GlassUser send an email not a pm OT Supporter

    Joined:
    Oct 26, 2003
    Messages:
    265,171
    Likes Received:
    150
    Location:
    Pearland, Texas
  4. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    hmm, i've made simple greasemonkey scripts before. let me play around and see what i can do.
     
  5. Jesse

    Jesse PSN: iamajesse; XBL: Inhale My Rod; G8 GT crew; Ne OT Supporter

    Joined:
    Jan 12, 2005
    Messages:
    25,649
    Likes Received:
    0
    Location:
    California :: (925)
    Right on.

    Keep in mind, I don't want to just convert them for the person running the script; I want them to convert the mamoru code to bb code linking to an SFTW smiley, so everyone sees it.
     
  6. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    ya i see what you want. let me run some tests to see how hard it'd be.
     
  7. Jesse

    Jesse PSN: iamajesse; XBL: Inhale My Rod; G8 GT crew; Ne OT Supporter

    Joined:
    Jan 12, 2005
    Messages:
    25,649
    Likes Received:
    0
    Location:
    California :: (925)
    You could actually do one of each.. one to just change them, and one to change how you enter them.

    The how to change them would work for all non OT sites.. could be useful to some, but the other forum viewers wouldn't see them as you would.
     
  8. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    ok it looks like this should be doable. i can overload vBulletins text editor object's function "insert_smilie" to do what it regularly does but replace urls for certains smilies. ill get back to you with some code in a bit
     
  9. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    i have the first workings of it. you need to update the part that says

    Code:
    var er = new Array();
    er['wtc'] = 'http://smiliesftw.com/x/hsughcry.gif';
    to contain all the emoticons you want to replace. as of yet i didn't make it work if they literally type in : wtc : in the box. but it works in that if they click an emoticon it will insert the smiliesftw one instead, and it also updates all the emoticons on the page with the smiliesftw emoticon as well.

    Code:
    // ==UserScript==
    // @name           SmiliesFTW emoticon replacer
    // @version        1.0
    // @description    replace emoticons from vB_Text_Editor with other emoticons
    // @include        http://*.offtopic.com/*
    // @author         Limp_Brisket
    // ==/UserScript==
    
    // ---------------- EDIT THIS STUFF APPROPRIATELY ------------ //
    var editorNames = ['vB_Editor_QR','vB_Editor_001'];
    
    var er = new Array();
    er['wtc'] = 'http://smiliesftw.com/x/hsughcry.gif';
    // ----------------------------------------------------------- //
    
    
    
    
    // replace emoticons on page with smiliesFTW emoticons
    var imgs = document.getElementsByTagName("img");
    for(var i = 0; i < imgs.length; i++){
        var s = imgs[i].alt.substr(1,imgs[i].alt.length-2);
        if(er[s]){
            imgs[i].src = er[s];
        }
    }
    
    // the function that will replace insert_smilie
    var new_insert_smilie = 'function(e, smilietext, smiliepath, smilieid){var er = new Array();';
    for(var i in er){
        new_insert_smilie += 'er[\''+i+'\']=\''+er[i]+'\';';
    }
    new_insert_smilie += 'var s=smilietext.substr(1,smilietext.length-2);if(er[s]){this.apply_format(\'insertimage\',false,er[s]);}else{this.check_focus();return this.insert_text(\'<img src="\' + smiliepath + \'" border="0" alt="0" smilieid="\' + smilieid + \'" />\', false);}};';
    
    // overload insert_smilies functions for known vb_Editors using location hack
    for(var i in editorNames){
        location.href = "javascript:void(window.vB_Editor['" + editorNames[i] + "'].insert_smilie = " + eval(new_insert_smilie) + ")";
    }
    
    
     
    Last edited: Dec 13, 2008
  10. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
  11. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    testing custom smilie [​IMG]
     
  12. Shampoo

    Shampoo Rinse & Repost

    Joined:
    May 5, 2004
    Messages:
    60,183
    Likes Received:
    0
    Location:
    California
    o snap
     
  13. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    k it's done including emoticons with :'s around them, im just adding all the xmasgifs.
     
  14. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    testing...

    [​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG][​IMG]
     
  15. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    ok, here is the new version. i added support for smilies in :'s as well as replaced all the smilies i could find a version for on smiliesftw that were in the main smilie window. if you want to add some more you can do it yourself at the top of the script.

    here's the link: www.xmission.com/~sna/smiliesftw.user.js

    or code

    Code:
    // ==UserScript==
    // @name           SmiliesFTW emoticon replacer
    // @version        1.1
    // @description    replace emoticons from vB_Text_Editor with other emoticons
    // @include        http://*.offtopic.com/*
    // @author         Limp_Brisket
    // ==/UserScript==
    
    // ---------------- EDIT THIS STUFF APPROPRIATELY ------------ //
    var editorNames = ['vB_Editor_QR','vB_Editor_001'];
    
    var er = new Array();
    er[':eek3:'] = 'http://smiliesftw.com/x/xmaseek3.gif';
    er[':wtc:'] = 'http://smiliesftw.com/x/xmastear.gif';
    er[':rolleyes:'] = 'http://smiliesftw.com/x/xmasrollfawk.gif';
    er[':hsugh:'] = 'http://smiliesftw.com/x/xmashsugh.gif';
    er[':bowdown:'] = 'http://smiliesftw.com/x/xmasbowdown.gif';
    er[':naughty:'] = 'http://smiliesftw.com/x/xmasnaughty.gif';
    er[':rofl:'] = 'http://smiliesftw.com/x/xmasrofl.gif';
    er[':wiggle:'] = 'http://smiliesftw.com/x/xmaswiggle.gif';
    er[':naughty:'] = 'http://smiliesftw.com/x/xmasnaughty.gif';
    er[':hs:'] = 'http://smiliesftw.com/x/xmashs.gif';
    er[':squint:'] = 'http://smiliesftw.com/x/xmassquint.gif';
    er[':ugh:'] = 'http://smiliesftw.com/x/xmasugh.gif';
    er[':cool:'] = 'http://smiliesftw.com/x/xmascool.gif';
    er[':x:'] = 'http://smiliesftw.com/x/xmasfingersx.gif';
    er[':wavey:'] = 'http://smiliesftw.com/x/xmaswavey3.gif';
    er[':squint:'] = 'http://smiliesftw.com/x/xmassquint.gif';
    er[':noes:'] = 'http://smiliesftw.com/x/xmasohnoes.gif';
    er[':wink:'] = 'http://smiliesftw.com/x/xmaswink.gif';
    er[':greddy:'] = 'http://smiliesftw.com/x/xmasgreddy.gif';
    er[':mamoru:'] = 'http://smiliesftw.com/x/xmaskekegay.gif';
    er[':o'] = 'http://smiliesftw.com/x/xmasredface.gif';
    er[':nono:'] = 'http://smiliesftw.com/x/xmasnono.gif';
    er[':fawk:'] = 'http://smiliesftw.com/x/xmasfawk.gif';
    er[':p'] = 'http://smiliesftw.com/x/xmastongue.gif';
    er[':eek4:'] = 'http://smiliesftw.com/x/xmasugheek.gif';
    er[':bigthumb:'] = 'http://smiliesftw.com/x/xmasthumbup.gif';
    // ----------------------------------------------------------- //
    
    
    
    
    // replace emoticons on page with smiliesFTW emoticons
    var imgs = document.getElementsByTagName("img");
    for(var i = 0; i < imgs.length; i++){
        var t = ':'+imgs[i].title.replace(' ','').toLowerCase()+':';
        var a = imgs[i].alt.replace(' ','').toLowerCase();
        // try using titles first
        if(er[t]){
            imgs[i].src = er[t];
        }
        // if that doesn't work try the alt tags
        else if(er[a]){
            imgs[i].src = er[a];
        }
    }
    
    // the function that will replace prepare_submit
    var new_prepare_submit = 'function(subjecttext, minchars){var er = new Array();';
    for(var i in er){
        new_prepare_submit += 'er[\''+i+'\']=\''+er[i]+'\';';
    }
    new_prepare_submit += 'this.textobj.value = this.get_editor_contents();for(var i in er){var re = new RegExp(i,"i");this.textobj.value = this.textobj.value.replace(re,\'<img src="\'+er[i]+\'"/>\');}this.editdoc.body.innerHTML = this.textobj.value;var returnvalue = validatemessage(this.textobj.value, subjecttext, minchars);if (returnvalue){return returnvalue;}else if (this.captcha != null && this.captcha.failed){return returnvalue;}else{this.check_focus();return false;}}';
    
    
    // the function that will replace insert_smilie
    var new_insert_smilie = 'function(e, smilietext, smiliepath, smilieid){var er = new Array();';
    for(var i in er){
        new_insert_smilie += 'er[\''+i+'\']=\''+er[i]+'\';';
    }
    new_insert_smilie += 'var s=smilietext;if(er[s]){this.apply_format(\'insertimage\',false,er[s]);}else{this.check_focus();return this.insert_text(\'<img src="\' + smiliepath + \'" border="0" alt="0" smilieid="\' + smilieid + \'" />\', false);}};';
    
    
    // overload insert_smilies functions for known vb_Editors using location hack
    for(var i in editorNames){
        location.href = "javascript:void(window.vB_Editor['" + editorNames[i] + "'].insert_smilie = " + eval(new_insert_smilie) + ")";
        location.href = "javascript:void(window.vB_Editor['" + editorNames[i] + "'].prepare_submit = " + eval(new_prepare_submit) + ")";
    }
    
    edit - it most likely has some bugs, but none that i could find instantly.
     
    Last edited: Dec 13, 2008
  16. crazybenf

    crazybenf Active Member

    Joined:
    Nov 14, 2001
    Messages:
    15,578
    Likes Received:
    3
    mother fucker comes through with the quickness.


    well done.
     
  17. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah

    [​IMG]
     
  18. m3s3lf

    m3s3lf *Jeep Crew*

    Joined:
    Oct 4, 2001
    Messages:
    5,460
    Likes Received:
    0
    Location:
    Sacramento, CA
    Holy shit. You're the man! [​IMG]

    :bigthumb:
     
    Last edited: Dec 14, 2008
  19. m3s3lf

    m3s3lf *Jeep Crew*

    Joined:
    Oct 4, 2001
    Messages:
    5,460
    Likes Received:
    0
    Location:
    Sacramento, CA
    <img src="http://smiliesftw.com/x/xmaseek3.gif"/>
    I think you've got the :: versions being replaced with HTML instead of VB Code... and it doesn't work w/ the quick reply for me.
     
    Last edited: Dec 13, 2008
  20. m3s3lf

    m3s3lf *Jeep Crew*

    Joined:
    Oct 4, 2001
    Messages:
    5,460
    Likes Received:
    0
    Location:
    Sacramento, CA
    Better?
    Code:
    // ==UserScript==
    // @name           SmiliesFTW emoticon replacer
    // @version        1.1
    // @description    replace emoticons from vB_Text_Editor with other emoticons
    // @include        http://*.offtopic.com/*
    // @author         Limp_Brisket
    // ==/UserScript==
    
    // ---------------- EDIT THIS STUFF APPROPRIATELY ------------ //
    var editorNames = ['vB_Editor_QR','vB_Editor_001'];
    
    var er = new Array();
    er[':eek3:'] = 'http://smiliesftw.com/x/xmaseek3.gif';
    er[':wtc:'] = 'http://smiliesftw.com/x/xmastear.gif';
    er[':rolleyes:'] = 'http://smiliesftw.com/x/xmasrollfawk.gif';
    er[':hsugh:'] = 'http://smiliesftw.com/x/xmashsugh.gif';
    er[':bowdown:'] = 'http://smiliesftw.com/x/xmasbowdown.gif';
    er[':naughty:'] = 'http://smiliesftw.com/x/xmasnaughty.gif';
    er[':rofl:'] = 'http://smiliesftw.com/x/xmasrofl.gif';
    er[':wiggle:'] = 'http://smiliesftw.com/x/xmaswiggle.gif';
    er[':naughty:'] = 'http://smiliesftw.com/x/xmasnaughty.gif';
    er[':hs:'] = 'http://smiliesftw.com/x/xmashs.gif';
    er[':squint:'] = 'http://smiliesftw.com/x/xmassquint.gif';
    er[':ugh:'] = 'http://smiliesftw.com/x/xmasugh.gif';
    er[':cool:'] = 'http://smiliesftw.com/x/xmascool.gif';
    er[':x:'] = 'http://smiliesftw.com/x/xmasfingersx.gif';
    er[':wavey:'] = 'http://smiliesftw.com/x/xmaswavey3.gif';
    er[':squint:'] = 'http://smiliesftw.com/x/xmassquint.gif';
    er[':noes:'] = 'http://smiliesftw.com/x/xmasohnoes.gif';
    er[':wink:'] = 'http://smiliesftw.com/x/xmaswink.gif';
    er[':greddy:'] = 'http://smiliesftw.com/x/xmasgreddy.gif';
    er[':mamoru:'] = 'http://smiliesftw.com/x/xmaskekegay.gif';
    er[':o'] = 'http://smiliesftw.com/x/xmasredface.gif';
    er[':nono:'] = 'http://smiliesftw.com/x/xmasnono.gif';
    er[':fawk:'] = 'http://smiliesftw.com/x/xmasfawk.gif';
    er[':p'] = 'http://smiliesftw.com/x/xmastongue.gif';
    er[':eek4:'] = 'http://smiliesftw.com/x/xmasugheek.gif';
    er[':bigthumb:'] = 'http://smiliesftw.com/x/xmasthumbup.gif';
    // ----------------------------------------------------------- //
    
    
    
    
    // replace emoticons on page with smiliesFTW emoticons
    var imgs = document.getElementsByTagName("img");
    for(var i = 0; i < imgs.length; i++){
        var t = ':'+imgs[i].title.replace(' ','').toLowerCase()+':';
        var a = imgs[i].alt.replace(' ','').toLowerCase();
        // try using titles first
        if(er[t]){
            imgs[i].src = er[t];
        }
        // if that doesn't work try the alt tags
        else if(er[a]){
            imgs[i].src = er[a];
        }
    }
    
    // the function that will replace prepare_submit
    var new_prepare_submit = 'function(subjecttext, minchars){var er = new Array();';
    for(var i in er){
        new_prepare_submit += 'er[\''+i+'\']=\''+er[i]+'\';';
    }
    new_prepare_submit += 'this.textobj.value = this.get_editor_contents();for(var i in er){var re = new RegExp(i,"i");this.textobj.value = this.textobj.value.replace(re,\'[img]\'+er[i]+\'[/img]\');}this.editdoc.body.innerHTML = this.textobj.value;var returnvalue = validatemessage(this.textobj.value, subjecttext, minchars);if (returnvalue){return returnvalue;}else if (this.captcha != null && this.captcha.failed){return returnvalue;}else{this.check_focus();return false;}}';
    
    
    // the function that will replace insert_smilie
    var new_insert_smilie = 'function(e, smilietext, smiliepath, smilieid){var er = new Array();';
    for(var i in er){
        new_insert_smilie += 'er[\''+i+'\']=\''+er[i]+'\';';
    }
    new_insert_smilie += 'var s=smilietext;if(er[s]){this.apply_format(\'insertimage\',false,er[s]);}else{this.check_focus();return this.insert_text(\'[img]\' + smiliepath + \'[/img]\', false);}};';
    
    
    // overload insert_smilies functions for known vb_Editors using location hack
    for(var i in editorNames){
        location.href = "javascript:void(window.vB_Editor['" + editorNames[i] + "'].insert_smilie = " + eval(new_insert_smilie) + ")";
        location.href = "javascript:void(window.vB_Editor['" + editorNames[i] + "'].prepare_submit = " + eval(new_prepare_submit) + ")";
    }
    I didn't fix the quick reply part though.
     
  21. GlassUser

    GlassUser send an email not a pm OT Supporter

    Joined:
    Oct 26, 2003
    Messages:
    265,171
    Likes Received:
    150
    Location:
    Pearland, Texas
    Yeah that's some fucking awesome work. I dabbled, but I focused on getting it done for the quick reply box, so it automatically replaces the emoticons with SFTW image urls on submit.
     
  22. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    testing quick reply [​IMG] [​IMG]
     
  23. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    hmm, it worked for me...

    one thing that might make it not work, are you using the WYSIWYG reply box? if you're using the standard reply box it probably won't work, or at least i didn't test for it.

    the other thing that could possibly make it not work is the var editorNames = ['vB_Editor_QR','vB_Editor_001']; part. that's where it tells it what text editors objects to work with, and as far as i could find those were always the names vB_Editor_QR for the quick reply object, and vB_Editor_001 was always the advanced reply object. but there might be times when that is not the case, but i wasn't able to find any. [​IMG]
     
  24. GlassUser

    GlassUser send an email not a pm OT Supporter

    Joined:
    Oct 26, 2003
    Messages:
    265,171
    Likes Received:
    150
    Location:
    Pearland, Texas
    I took the scripts apart at work. If you get it working for one, the best solution is to hijack the "post quick reply" button to run your event, which changes the box to what you want, then runs the submit event.
     
  25. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    you mean for the standard editor?

    i did it the way i did for the WYSIWYG editor because that textarea is encapsulated in their vB_Text_Editor object and i couldn't access it to change it regularly through the DOM.
     

Share This Page