My evil jQuery Plugin

I demonstrated this at my jQuery presentation earlier today at CFUNITED but I thought I'd share the code. The basic idea is this - you have a coworker you hate (we've all had one from time to time), so you quickly figure out their IP and output some code just for them:


<head> <script type="text/javascript" src=""></script> <script src="myplugin.js"></script> <script> <cfif cgi.remote_host is ""> function mean() { $("#content").notMean(); }

$(document).ready(function () { window.setInterval('mean()',5000)
}) </cfif> </script> </head>


<div id="content"> This is my text. It is only my text. It does not have anything special in it. You should not read it. </div>

</body> </html>

What does the 'notMean' plugin do? I think a video demonstration may be a bit nicer.

Be sure to watch the entire thing - it is a bit subtle. So I don't imagine anyone would ever use this in production (but if you do, let me know), but here is the source code:

$.fn.notMean = function(){ this.each( function(){ var contents = $(this).html() var ranPos = Math.ceil(Math.random() * contents.length) var ranChar = Math.ceil(Math.random() * 26) + 65 var newChar = String.fromCharCode(ranChar) if(Math.random() > 0.5) newChar = newChar.toLowerCase() var newContents = contents.substring(0,ranPos) + newChar + contents.substring(ranPos+1,contents.length) $(this).html(newContents) } )

return this



Like This?

If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can also subscribe to the email feed to get notified of new posts.