Wednesday, December 17, 2008

greasemonkey replace words on websites

// ==UserScript==// @name NAME // @namespace http://www.WEBSITE.com/ // @include http://www.WEBSITE.com/ // ==/UserScript==

(function() {
var replacements, regex, key, textnodes, node, s;
textnodes = document.evaluate( "//body//text()", document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < textnodes.snapshotLength; i++) {
node = textnodes.snapshotItem(i);
if(node != null && node.nodeName == '#text' && /\S/.test(node.nodeValue))
{

s = node.data;

s = s.replace( /\bWORD OR WORDS TO GET RID OF\b/g, "WORDS THAT IT IS REPLACED WITH OR JUST 2 QUOTES FOR NOTHING");
s = s.replace( /\bWORDS CAN NOT CONTAIN PERIODS OR COMMAS OR SINGLE OR DOUBLE QUOTES\b/g, "IF YOU DO IT WILL NOT WORK");
s = s.replace( /\bBEFORE EACH THING WILL BE A SMALL LETTER B AND END WITH SLASH B AND IF YOU REMOVE ANYTHING BUT THESE BOLD WORLDS IT WONT WORK\b/g, "BELOW ARE SHORTER EXAMPLES");
s = s.replace( /\bERASED\b/g, "REPLACED");
s = s.replace( /\bINPUT\b/g, "OUTPUT");
s = s.replace( /\b0\b/g, "1");
s = s.replace( /\bMAKE BLANK\b/g, "");
node.data = s;

}} })();




By doing this, when you go to a website, you can make specific things either be there or not or be changed. If you frequently go to a website and it says things like "welcome to the blah blah blah website blah blah blah" you can have it removed as the page loads. If there is a bad word, you can replace it with a less harsh word on all website if you want. If you hate a word, you can replace it with one you like or don't mind. It will not change anything except for what it displayed to you after the page loads and then is modified automatically with the script. It will not change what you typed or cause you to get different search results.

The most important thing, is that the first lines are all on 1 single line with "wordwrap" off! on NotePad for Windows. If they are on 2 separate lines or more, it will not work at all. from // ==UserScript==// to // ==/UserScript==//


If you understand this... this is what I started making for YouTube:

s = s.replace( /\bfirst comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bsecond comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bthird comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bfourth comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bfifth comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bsixth comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bseventh comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\beighth comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bnineth comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b1st comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b2nd comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b3rd comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b4th comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b5th comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b6th comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b7th comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b8th comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\b9th comment\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bFirst\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bfirst\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");
s = s.replace( /\bFIRST\b/g, "!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!");

which looks like this


awptions (12 hours ago)
-2 Poor comment
!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!

RonnieTalamaivao (23 hours ago)
-4 Poor comment
!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!! WAHHAHAHOOO

Supermutt18 (1 week ago)
-3 Poor comment
!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!!

lovemyfavourites (1 week ago) Show Hide
-5 Poor comment
!!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!! LOL.

tidusquall10x (1 week ago)
-2 Poor comment
I love !!!!!!!!!!!!!!!!!!!!!!!BLOCK ME!!!!!!!!!!!!!!!!!!!!!!!

No comments: