Greasy Fork

Greasy Fork is available in English.

Notion.so RTL support for written text

Changes dir attribute of page's div elements to 'auto' and forcing text aligning styles on selectable blocks

当前为 2020-03-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Notion.so RTL support for written text
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Changes dir attribute of page's div elements to 'auto' and forcing text aligning styles on selectable blocks
// @author       OrenK
// @include      https://www.notion.so/*
// @grant        none
// ==/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; unicode-bidi: plaintext;}");
    GM_addStyle(".notion-selectable.notion-to_do-block > div > div:nth-of-type(2) { margin-right: 4px !important; }");

    var observing = false;
    var hasClass = function(element, className) {
        return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;
    };
    var notionPageCallback = function(mutations, observer) {
        for (var i = 0; i < mutations.length; i++) {
            for (var j = 0; j < mutations[i].addedNodes.length; j++) {

                var addedNode = mutations[i].addedNodes[j];
                if (addedNode.nodeType === Node.ELEMENT_NODE) {
                    if (addedNode.tagName === 'DIV' && hasClass(addedNode, 'notion-selectable')) {
                        addedNode.setAttribute('dir', 'auto');
                    }
                    var divChildren = addedNode.getElementsByClassName('notion-selectable');
                    for (var y = 0; y < divChildren.length; y++) {
                        divChildren[y].setAttribute('dir', 'auto');
                    }
                }
            }
        }
    };
    var documentCallback = function(mutations, observer) {
        var notionPage = document.getElementsByClassName('notion-page-content');
        if (notionPage.length !== 0 && !observing) {
            var divElements = notionPage[0].getElementsByClassName('notion-selectable');
            for (var i = 0; i < divElements.length; i++) {
                divElements[i].setAttribute('dir', 'auto');
            }
            notionPageObserver.observe(notionPage[0], { subtree: true, childList: true });
            observing = true;

        }
        if (notionPage.length === 0 && observing) {
            notionPageObserver.disconnect();
            observing = false;
        }
    };
    var notionPageObserver = new MutationObserver(notionPageCallback);
    var documentObserver = new MutationObserver(documentCallback);

    documentObserver.observe(document, {
        subtree: true,
        childList: true
    });
})();