Skip to content

Instantly share code, notes, and snippets.

@hamidazimy
Last active August 26, 2018 15:30
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamidazimy/a21584843a8e782488e9 to your computer and use it in GitHub Desktop.
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)
// ==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);
});
}
@pejhar
Copy link

pejhar commented Aug 26, 2018

چطور کار می کنه؟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment