Smart Text Justifier

Justifies p and textarea tags unless they (or their parents) are centered.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Smart Text Justifier
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Justifies p and textarea tags unless they (or their parents) are centered.
// @author       Ȼaptain Jøhn “Søap” MacTavish
// @license      CC-BY-NC-SA-4.0
// @match        *://*/*
// @grant        none
// ==/UserScript==

(
    function()
    {
        'use strict';
    
        const JustifyTargetElements = () =>
        {
            const TargetNodes = document.querySelectorAll('p, textarea');
    
            TargetNodes.forEach
            (
                Element =>
                {
                    // Check the actual computed alignment from CSS or attributes
                    const ComputedAlignment = window.getComputedStyle(Element).textAlign;
    
                    // Only apply justification if the element is NOT centered
                    if (ComputedAlignment !== 'center')
                    {
                        Element.style.setProperty('text-align', 'justify', 'important');
                        Element.style.setProperty('text-justify', 'inter-word', 'important');
                    }
                }
            );
        };
    
        const InitializeObserver = () =>
        {
            // Initial run
            JustifyTargetElements();
    
            // Observe the body for dynamically loaded content (AJAX, infinite scroll)
            const ContentObserver = new MutationObserver
            (
                () =>
                {
                    JustifyTargetElements();
                }
            );
    
            ContentObserver.observe
            (
                document.body,
                {
                    childList: true,
                    subtree: true
                }
            );
        };
    
        // Run the script once the window is stable
        if (document.readyState === 'complete')
        {
            InitializeObserver();
        }
        else
        {
            window.addEventListener('load', InitializeObserver);
        }
    
    }
)();