Clean Up Web Jargon

By JoeSimmons Last update May 27, 2009 — Installed 109 times. Daily Installs: 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0

There are 15 previous versions of this script.

scr_meta=<><![CDATA[
// ==UserScript==
// @name           Clean Up Web Jargon
// @namespace      http://userscripts.org/users/23652
// @description    Replaces slang and acronyms with the full phrases and capitalizes sentences.
// @include        http://*
// @include        https://*
// @include        file:*
// @exclude        http://pastebin.*/*
// @exclude        http://*.google.*/*
// @exclude        https://*.google.*/*
// @copyright      JoeSimmons
// @version        1.0.4
// @license        Creative Commons Attribution-Noncommercial 3.0 United States License
// ==/UserScript==
]]></>.toString();

var highlight_replaced_words = true;
var words = {

// Capitalization and Slang
'i' : 'I',
'u' : 'you',
'y' : 'why',
'y?ur' : ' your',
'youre' : 'you\'re',
'youll' : 'you\'ll',
'whats' : 'what\'s',
'thats' : 'that\'s',
'pl[ea]{0,2}(s|z)' : ' please',
'(than(x|z)|thx)' : ' thanks',
'(ty|thank ?(you|u|ya|ye))' : 'thank you',
'srr?y' : ' sorry',
'dont' : ' don\'t',
'b4' : 'before',
'i\'?m' : 'I\'m',
'dunno' : 'don\'t know',

// General Misspellings
'awsome' : 'awesome',

// Acronyms
'brb' : 'be right back',
'i ?dk' : 'I don\'t know',
'i ?dr' : 'I don\'t remember',

'(b?cuz)|(b\/c(uz)?)' : 'because',
'dat' : 'that',

// Leet speak
'r[o0]{2}l' : 'rule',
'k[o0]{2}l' : 'cool',
'(1|l)[e3]{2}' : 'leet'

};

//////////////////////////////////////////////////////////////////////////////
// This is where the real code is
// Don't edit below this
//////////////////////////////////////////////////////////////////////////////

// addGlobalStyle
function addGlobalStyle(css) {
	if(typeof GM_addStyle=='function') GM_addStyle(css);
    else if((head=document.getElementsByTagName('head')[0])) {
    var style = document.createElement('style');
    style.type = 'text/css';
    head.appendChild(style).innerHTML = css;
	}
}
if(highlight_replaced_words) addGlobalStyle('.webjargon {border-color:#71B8FF;border-style:solid;border-top-width:1px;border-bottom-width:1px;border-left-width:0;border-right-width:0;}');

function isOkTag(tag) {
var ok = true;
var badTags = ['a','pre','blockquote','code','input','button','textarea'];
Array.forEach(badTags, function(badTag) {if(tag==badTag) {ok=false;}});
return ok;
}

function upper(r) {
return r.toUpperCase();
}

var regexs=[],
	replacements=[],
	full_regex='',
	wildcard_regex = /\*/g,
	lowercase_regex = /^\s*[a-z]/,
	caps_regex = /\. [a-z]/,
	tmp='';
for(var word in words) {
tmp = '\\b'+word.replace(wildcard_regex,'[^ ]*')+'\\b';
full_regex += '('+tmp+')|';
regexs.push(new RegExp(tmp, 'gi'));
replacements.push(words[word]);
}
full_regex = new RegExp(full_regex.replace(/\|$/,''));


var texts = document.evaluate("//text()[normalize-space(.)!='']",document,null,6,null);
for(var i=texts.snapshotLength-1; (this_text=texts.snapshotItem(i)); i--) {
	if(isOkTag(this_text.parentNode.tagName.toLowerCase()) && (text=this_text.textContent) && (lowercase_regex.test(text)||caps_regex.test(text)||full_regex.test(text))) {
	for(var x=regexs.length-1; x>=0; x--) {
	text = text.replace(regexs[x], replacements[x]);
	}

	// Fix cases
	if(lowercase_regex.test(text)) text = text.replace(lowercase_regex, upper);
	if(caps_regex.test(text)) text = text.replace(caps_regex, upper);

	if(!highlight_replaced_words) this_text.textContent = text;
	else {
	var span = document.createElement('span');
	span.setAttribute('class', 'webjargon');
	span.setAttribute('title', 'Original Text: '+this_text.textContent);
	span.textContent = text;
	this_text.parentNode.replaceChild(span, this_text);
	}
}
}

// Auto update by Sizzlemctwizzle
aaus_38017={
i:'50055', // Script id on Userscripts.org
d:1, // Days to wait between update checks
n:/\/\/\s*@name\s+(.*)\s*\n/i.exec(scr_meta)[1],v:/\/\/\s*@version\s+(.*)\s*\n/i.exec(scr_meta)[1].replace(/\./g, ''),t:new Date().getTime()|0,ca:function(r){GM_xmlhttpRequest({method:'GET',url:'https://userscripts.org/scripts/source/'+this.i+'.meta.js',onload:function(x){aaus_38017.co(x,r)}})},co:function(x,r){this.xv=/\/\/\s*@version\s+(.*)\s*\n/i.exec(x.responseText);this.xn=/\/\/\s*@name\s+(.*)\s*\n/i.exec(x.responseText);if(this.xv&&this.xn[1]==this.n){this.xv=this.xv[1].replace(/\./g, '');this.xn=this.xn[1];}else{if(x.responseText.match('Uh-oh! The page could not be found!')||this.xn[1]!=this.n)GM_setValue('updated', 'off');return false;}if(this.xv>this.v&&confirm('A new version of the '+this.xn+' user script is available. Do you want to update?')){GM_setValue('updated',this.t);GM_openInTab('http://userscripts.org/scripts/source/'+this.i+'.user.js')}else if(this.xv&&this.xv>this.v){if(confirm('Do you want to turn off auto updating for this script?')){GM_setValue('updated','off');GM_registerMenuCommand("Auto Update "+this.n,function(){GM_setValue('updated',new Date().getTime()|0);aaus_38017.ca('return')});alert('Automatic updates can be re-enabled for this script from the User Script Commands submenu.')}else{GM_setValue('updated',this.t)}}else{if(r)alert('No updates available for '+this.n);GM_setValue('updated',this.t)}},ch:function(){if(GM_getValue('updated',0)==0)GM_setValue('updated',this.t);if(GM_getValue('updated',0)!='off'&&+this.t>+GM_getValue('updated',0)+86400000*this.d){this.ca()}else if(GM_getValue('updated',0)=='off'){GM_registerMenuCommand("Enable "+this.n+" updates",function(){GM_setValue('updated',new Date().getTime()|0);aaus_38017.ca(true)})}else{GM_registerMenuCommand("Check "+this.n+" for updates",function(){GM_setValue('updated',new Date().getTime()|0);aaus_38017.ca(true)})}}};if(self.location==top.location&&typeof GM_xmlhttpRequest!='undefined')aaus_38017.ch();