Scrambler

Scrambles inner text of words on the page, for enhanced readability :)

by jacksenechal

HTML

<script src="http://github.com/cowboy/jquery-replacetext/raw/master/jquery.ba-replacetext.min.js"></script>
<h2><span class="mw-headline" id="History">History</span></h2>
<div class="rellink relarticle mainarticle">Main article: <a href="/wiki/History_of_wikis" title="History of wikis">History of wikis</a></div>
<div class="thumb tright">
    <div class="thumbinner" style="width:222px;"><a href="/wiki/File:HNL_Wiki_Wiki_Bus.jpg" class="image"><img alt="" src="http://upload.wikimedia.org/wikipedia/commons/thumb/4/42/HNL_Wiki_Wiki_Bus.jpg/220px-HNL_Wiki_Wiki_Bus.jpg" width="220" height="165" class="thumbimage" /></a>
        <div class="thumbcaption">
            <div class="magnify"><a href="/wiki/File:HNL_Wiki_Wiki_Bus.jpg" class="internal" title="Enlarge"><img src="http://bits.wikimedia.org/skins-1.5/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>
            <a href="/wiki/Wiki_Wiki_Shuttle" title="Wiki Wiki Shuttle">Wiki Wiki Shuttle</a> at <a href="/wiki/Honolulu_International_Airport" title="Honolulu International Airport">Honolulu International Airport</a></div>
        
    </div>
</div>
<p>WikiWikiWeb was the first wiki.<sup id="cite_ref-ebersbach10_5-0" class="reference"><a href="#cite_note-ebersbach10-5"><span>[</span>6<span>]</span></a></sup> Ward Cunningham started developing WikiWikiWeb in Portland, Oregon in 1994, and installed it on the <a href="/wiki/Domain_name" title="Domain name">Internet domain</a> <a href="http://c2.com/" class="external text" rel="nofollow">c2.com</a> on March 25, 1995. It was named by Cunningham, who remembered a <a href="/wiki/Honolulu_International_Airport" title="Honolulu International Airport">Honolulu International Airport</a> counter employee telling him to take the "<a href="/wiki/Wiki_Wiki_Shuttle" title="Wiki Wiki Shuttle">Wiki Wiki Shuttle</a>" bus that runs between the airport's terminals. According to Cunningham, "I chose wiki-wiki as an alliterative substitute for 'quick' and thereby...

JavaScript

/* Called on document.ready */
$(function() {
    $("body *").replaceText(/\b([A-z]{4,})\b/g, scramble_inner);
}); /* Scramble the inner characters of a word */

function scramble_inner(word) {
    return word[0] + force_shuffle(word.slice(1, word.length - 1)) + word[word.length - 1];
}
/* Randomize characters in the string, but check to make sure
       * they're different from the original. Handle's the special
       * case where all inner characters are equal, for instance "moooo".
       */

function force_shuffle(str) {
    if (all_chars_same(str)) return str;
    var result = str;
    while (str === result) {
        result = str.split('').sort(function() {
            return Math.floor(Math.random() * 2) ? 1 : -1;
        }).join('');
    }
    return result;
} /* Check whether all characters in the string are equal, eg "ooo" */

function all_chars_same(str) {
    for (i = 0; i < str.length; i++) {
        if (str[i] !== str[0]) {
            return false;
        }
    }
    return true;
}