Mastodon ROT13 bookmarklet

Drag the following link to your bookmarks bar: rot13

Click the bookmarklet when on a Mastodon page to ROT13 every toot.

(Here's a version that only unscrambles toots that are open in the detailed status view in the rightmost column: rot13)

(Finally, here's a bookmarklet that rotates the toot text input field, so you can type rotated toots! rotoot)


The un-minified code is shown below. It should deal with the case where new posts appear and only reset the existing rot13-rotated toots rather than inverting the entire page including the new, unrotated toots leaving a terrible mess. I spent more time on this page than the code so please let me know if you can improve it!

Thanks to @marrus_sh for helping me make the bookmark work on Firefox.

Whole-page version

if(typeof rot === 'undefined') { var rot; } 

function rts( s ) 
{ 
    return s.replace(/[a-zA-Z]/g,function(c)
    {
        return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);
    }); 
}

var stl=document.getElementsByClassName("status__content");
for(var i = 0; i < stl.length; i++)
{ 
    st = stl[i];
    
    if( rot && st.classList.contains( "rot13" ) )
    {
        st.classList.remove("rot13"); 
        st.innerText = rts( st.innerText );
    }
    else if ( !rot && !st.classList.contains( "rot13" ) )
    {
        st.classList.add("rot13"); 
        st.innerText = rts( st.innerText );
    }
    
}
rot = !rot;
void(0);

Detail view-only version

function rts( s )
{
    return s.replace(/[a-zA-Z]/g,function(c)
    {
        return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);
    });
}

var stl=document.querySelectorAll(".detailed-status .status__content");
stl[0].innerText = rts( stl[0].innerText );
void(0);

Toot input version

function rts( s )
{
    return s.replace(/[a-zA-Z]/g,function(c)
    {
        return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);
    });
}

var stl=document.querySelectorAll(".autosuggest-textarea__textarea");
stl[0].value = rts( stl[0].value );
void(0);