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

Jesse

PSN: iamajesse; XBL: Inhale My Rod; G8 GT crew; Ne
OT Supporter
Jan 12, 2005
25,625
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.
 
TS
TS
Jesse

Jesse

PSN: iamajesse; XBL: Inhale My Rod; G8 GT crew; Ne
OT Supporter
Jan 12, 2005
25,625
California :: (925)
hmm, i've made simple greasemonkey scripts before. let me play around and see what i can do.
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.
 

Limp_Brisket

Active Member
Jan 2, 2006
48,290
Utah
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.

ya i see what you want. let me run some tests to see how hard it'd be.
 
TS
TS
Jesse

Jesse

PSN: iamajesse; XBL: Inhale My Rod; G8 GT crew; Ne
OT Supporter
Jan 12, 2005
25,625
California :: (925)
ya i see what you want. let me run some tests to see how hard it'd be.
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.
 

Limp_Brisket

Active Member
Jan 2, 2006
48,290
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
 

Limp_Brisket

Active Member
Jan 2, 2006
48,290
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:

Limp_Brisket

Active Member
Jan 2, 2006
48,290
Utah
testing custom smilie
hsughcry.gif
 

Limp_Brisket

Active Member
Jan 2, 2006
48,290
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:

m3s3lf

*Jeep Crew*
Oct 4, 2001
5,445
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:

m3s3lf

*Jeep Crew*
Oct 4, 2001
5,445
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.
 

GlassUser

Flavors Matter
OT Supporter
Oct 26, 2003
281,944
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.
 

Limp_Brisket

Active Member
Jan 2, 2006
48,290
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.
xmasredface.gif
 

GlassUser

Flavors Matter
OT Supporter
Oct 26, 2003
281,944
Pearland, Texas
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.
xmasredface.gif
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.
 

Limp_Brisket

Active Member
Jan 2, 2006
48,290
Utah
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.

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.
 

Users who are viewing this thread

About Us

  • Please do not post anything that violates any Local, State, Federal or International Laws. Your privacy is protected. You have the right to be forgotten. Site funded by advertising, link monetization and member support.
OT v15.8.1 Copyright © 2000-2022 Offtopic.com
Served by fu.offtopic.com

Online statistics

Members online
433
Guests online
66
Total visitors
499

Forum statistics

Threads
369,545
Messages
16,894,047
Members
86,873
Latest member
vitalesan