Greasemonkey script to replace annoying phrases on the SDMB (e.g. quarry throwing)

Below is a script for people who use Greasemonkey in Firefox or Chrome.

Replace any string on the SDMB. Especially useful for frequently occurring annoying phrases. (Especially powerful if you happen to know regular expressions, but still useful if you don’t)

Just edit the “var replacements = {” entry with things you would like to see replaced.

In the two examples below, the quarry-throwing phrase is always replaced by “LOL”. In the first example using a simple string, and in the second example using a regular expression in order to catch several possible versions of the phrase.


// ==UserScript==
// @name           Replace any string on SDMB
// @namespace      Polerius
// @description    Replace any string in threads on SDMB
// @include        http://boards.straightdope.com/sdmb/*
// ==/UserScript==

(function() 
 {
     var replacements = {
         "Let's go to the quarry and throw stuff down there"                              : "LOL",
         "Let's go (down )?to the quarry and throw (shit|stuff) (down|in) (there|here)"   : "LOL"
       };

     var allPosts    = document.getElementsByClassName('alt1');

     for (var i = 0; i < allPosts.length; i++)
     {
	 var kids = allPosts*.children;
	 for (var j=0; j<kids.length; j++)
	 {
	     if (kids[j].id.match(/^post_message_/))
	     {
		 var newHTML = kids[j].innerHTML;
		 //alert(newHTML);
		 for (var old_str in replacements)
		 {
		     newHTML = newHTML.replace(RegExp(old_str,"mg"), replacements[old_str]);
		 }
		 kids[j].innerHTML = newHTML;
	     }
	 }
     }
 })();


Really? LOL.

Hey, it works!

‘LOL’ is not annoying ?

You can replace it with anything you want, including nothing (i.e. ‘’)

No more signed posts! Thank you, Polerius!
Enjoy
Regards
mmm
:slight_smile: :slight_smile: :slight_smile: GOD BLESS YOU ALWAYS!!! :slight_smile: :slight_smile: :slight_smile:

Awesome!
I just replaced
“pricciar this is an official warning.” to
“pricciar that post was amazing, insightful and hilarious. Keep it up!”
also, “pricciar you are now banned” to
“pricciar, please create a new screen name to post under, this one is far too popular!”

Thanks!

Let’s go to the quarry and throw stuff down there!

Now people won’t have to read my “Am I the only one who…” posts! :wink:

LOL, you say?

Oops, wrong Greasemokey script…
:smiley:

I just added Pricciar is the kindest, bravest, warmest, most wonderful human being I’ve ever known in my life. I don’t know why. I think I’ll play a game of Minesweeper.

I was not familiar with Greasemonkey, or even the option for adding these extensions to Chrome.

Thanks for the script and—especially—the introduction to Greasemonkey!

Now I just need to figure out how to convert :rolleyes: into random XKCD links.

Don’t you need to consider a huge variety of possibilities? Like spam email?
Lets go to the quorry and throw stuf down there

Can someone link to a “Hello World”-level beginner’s tutorial on how to write, install, and use these Greasemonkey thingies?

(Uh, Should I do something like Google it?)

˙ǝɹǝɥʇ uʍop ɟɟnʇs ʍoɹɥʇ puɐ ʎɹɹɐnb ǝɥʇ oʇ oƃ s,ʇǝן

GreaseMonkeyBasics

You need to get the Greasemonkey extension for Firefox, but it’s especially easy if you are using Chrome.


// ==UserScript==
// @name           Hello World
// @namespace   SiXSwordS
// @description    display Hello World
// @include        http://boards.straightdope.com/sdmb/*
// ==/UserScript==

(function()
	{
		var myMessage = "Hello World";
		alert( myMessage );
	})
();

Save that code (it’s basically Javascript) and be sure to save your file as someFile.user.js. The @include (and @exclude… which isn’t used here) determines which pages will be affected. My example is pretty annoying because it pops up an alert on every single page on the Dope.

If your include statement were //@include http://boards.straightdope.com/sdmb/showthread.php?p=16686120* you would only get the alert in this thread.

On my version of Chrome (29.0.1547.65) you have to go to the far right of the address bar and click the button that looks like three horizontal lines. (In earlier versions, apparently you could just drag and drop the XXX.user.js file into the window.)

Click the button and choose Tools > Extensions from the dropdown. Drag and drop the XXX.user.js file into the Extensions window. You will have to click ok to allow the script to access the page.

Now, reload and enjoy!

In case anyone is interested, I find W3 schools to be a good source for basic stuff. The link is a Javascript introduction.
Oh, and to disable annoying scripts like mine, go back to Tools > Extensions and disable or trash unwanted scripts.

I wrote a similar script a while back to replace annoying signatures with pre-selected phrases.

I haven’t tried this one out yet, but assume it may create a situation similar to one I ran into using my own script: if you quote someone’s post and it changes text within the quote box that is technically against the rules, so use it carefully with that in mind.

Add this line to the definition of the replacements variable :slight_smile:


  "<img [^>]*src=\"images/smilies/rolleyes.gif\"[^>]*>"  : "<a target=\"_blank\" href=\"http://xkcd.com/"+Math.floor((Math.random()*1300)+1)+"\">Random xkcd</a>"

I haven’t had a chance to use this very much yet, but—so far as I can tell—if you use the Post Reply or Quote options (as opposed to Quick Reply) the URL will contain ‘newreply.’ My tests have allowed me to eliminate the script if the URL contains ‘newreply’ but I haven’t tested that beyond the Hello World Script I posted.