irdb / FFrtlizer

// ==UserScript==
// @copyright 2014, irdb
// @name        FFrtlizer
// @namespace   https://friendfeed.com/
// @description Change direction of rtl content on friendfeed.com
// @include     http://friendfeed.com/*
// @include     https://friendfeed.com/*
// @version     1
// @grant       none
// @oujs:author irdb
// ==/UserScript==
/*jslint browser: true*/
/*global $, jQuery, alert*/
function rtlizer() {
    'use strict';
    var rtl_chars_regex,
        rtl_length,
        match;
    rtl_chars_regex = /[\u0600-\u06FF]|[\u0750-\u077F]|[\u0590-\u05FF]|[\uFE70-\uFEFF]/gm;
    $('.text, .content')
        .each(function (i, e) {
            match = e.textContent.match(rtl_chars_regex);
            if (match) {
                rtl_length = match.length;
                if (rtl_length > e.textContent.length / 3) {
                    e.setAttribute('dir', 'rtl');
                }
            }
        });
}
$(rtlizer);
$(document)
    .ajaxComplete(rtlizer);