Greasy Fork is available in English.
Add RTL support for Notion, as all other solutions don't seem to work. Not really optimized currently.
当前为
// ==UserScript==
// @name Notion RTL support for written text
// @namespace http://www.sumit.co.il/
// @version 0.1
// @description Add RTL support for Notion, as all other solutions don't seem to work. Not really optimized currently.
// @author Effy Teva
// @include https://www.notion.so/*
// @grant none
// @require https://code.jquery.com/jquery-3.6.0.slim.min.js
// @license MIT
// ==/UserScript==
(function() {
'use strict';
/*var GM_addStyle =
function(css) {
var style = document.getElementById("GM_addStyleBy8626") || (function() {
var style = document.createElement('style');
style.type = 'text/css';
style.id = "GM_addStyleBy8626";
document.head.appendChild(style);
return style;
})();
var sheet = style.sheet;
sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
};
GM_addStyle(".notion-selectable * { text-align: start !important; }");
GM_addStyle(".notion-selectable.notion-to_do-block > div > div:nth-of-type(2) { margin-right: 4px !important; }");
*/
//var blackListClasses = ['notion-collection-item', 'notion-collection_view-block'];
var FixDirection = function(Element) {
var InnerText = Element.innerText;
var IsRTL = false;
for (var i = 0; i < InnerText.length; i++) {
if ((InnerText[i] >= 'a' && InnerText[i] <= 'z') || (InnerText[i] >= 'A' && InnerText[i] <= 'Z'))
break;
else if (InnerText[i] >= 'א' && InnerText[i] <= 'ת') {
IsRTL = true;
break;
}
}
Element.style.direction = IsRTL ? "rtl" : "ltr";
jQuery(Element).find('.notranslate').css('text-align', IsRTL ? 'right' : 'left');
};
var FixDirectionDefaultRTL = function(Element) {
var InnerText = Element.innerText;
var IsLTR = false;
for (var i = 0; i < InnerText.length; i++) {
if ((InnerText[i] >= 'a' && InnerText[i] <= 'z') || (InnerText[i] >= 'A' && InnerText[i] <= 'Z')) {
IsLTR = true;
break;
}
else if (InnerText[i] >= 'א' && InnerText[i] <= 'ת') {
//IsRTL = true;
break;
}
}
Element.style.direction = !IsLTR ? "rtl" : "ltr";
jQuery(Element).find('.notranslate').css('text-align', !IsLTR ? 'right' : 'left');
};
jQuery(function() {
let CurrentContentEditable;
jQuery(document).on("click", ".notion-selectable", function(Event) {
CurrentContentEditable = this;
Event.stopPropagation();
});
jQuery(document).on("keyup", "[contenteditable]", function(Event) {
var $Closest = CurrentContentEditable.closest(".notion-selectable");
if ($Closest && !$Closest.closest('.notion-outliner-workspace')) {
FixDirectionDefaultRTL($Closest);
console.log($Closest);
}
});
jQuery(document).on('DOMNodeInserted', function(e) {
jQuery(document).find(".notion-frame .notion-selectable").each(function() {
FixDirectionDefaultRTL(this);
});
});
});
})();