Skip to content

Instantly share code, notes, and snippets.

@hamidazimy
Last active August 26, 2018 15:30
Show Gist options
  • Select an option

  • Save hamidazimy/a21584843a8e782488e9 to your computer and use it in GitHub Desktop.

Select an option

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

pejhar commented Aug 26, 2018

Copy link
Copy Markdown

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

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