Last active
August 26, 2018 15:30
-
-
Save hamidazimy/a21584843a8e782488e9 to your computer and use it in GitHub Desktop.
Tiny script to add RTL support to slack.com (can be used everywhere with a little modification)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name RTL Slack | |
// @namespace slask.com | |
// @include https://*.slack.com/* | |
// @version 1.2.2 | |
// @grant none | |
// ==/UserScript== | |
function isRTL(text) { | |
if (text !== "") { | |
if ("اآبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیؤئيإأةك۰۱۲۳۴۵۶۷۸۹".indexOf(text[0]) > -1) { | |
return true; | |
} | |
} | |
return false; | |
} | |
if ($ !== undefined) { | |
$(document).ready(function() { | |
$('head').append('\ | |
<style type="text/css">\ | |
.rtl-input {\ | |
direction: rtl;\ | |
text-align: left;\ | |
}\ | |
.rtl:before {\ | |
content: "\u202B";\ | |
}\ | |
.rtl:after {\ | |
content: "\u200F";\ | |
}\ | |
.edited {\ | |
float: right;\ | |
}\ | |
</style>\ | |
'); | |
$('textarea').keyup(function() { | |
//var text = $(this).val(); | |
if (isRTL($(this).val())) { | |
$(this).addClass('rtl-input'); | |
} | |
else { | |
$(this).removeClass('rtl-input'); | |
} | |
}); | |
$('#msgs_div').bind('DOMNodeInserted', function(e) { | |
$('.message_body').not('rtl').not('ltr').each(function() { | |
if (isRTL($(this).text().trim())) { | |
$(this).addClass('rtl'); | |
} | |
else { | |
$(this).addClass('ltr'); | |
} | |
}); | |
$('#msg_text').focus(function() { | |
if (isRTL($(this).val())) { | |
$(this).addClass('rtl-input'); | |
} | |
else { | |
$(this).removeClass('rtl-input'); | |
} | |
}); | |
}); | |
// setInterval(function() { | |
// $('.message_content').addClass('rtl'); | |
// }, 1000); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
چطور کار می کنه؟