아프리카TV 정렬 개선

Adjust chat styles on AfreecaTV live streams for consistent alignment

As of 05.02.2024. See апошняя версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         아프리카TV 정렬 개선
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Adjust chat styles on AfreecaTV live streams for consistent alignment
// @author       You
// @match        https://play.afreecatv.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const adjustLayout = () => {
        // 숨기고 싶은 클래스 목록
        const classesToHide = ['grade-badge-fan', 'thumb', 'grade-badge-vip'];

        // 각 클래스에 대해 숨기기 처리
        classesToHide.forEach(className => {
            document.querySelectorAll(`.${className}`).forEach(element => {
                element.style.display = 'none';
            });
        });

        // 모든 username 요소를 찾음
        const usernames = document.querySelectorAll('.username');
        const maxUsernameWidth = 6 * 14; // 6글자 * 14px

        // 각 username에 계산된 최대 너비를 적용
        usernames.forEach(username => {
            username.style.minWidth = `${maxUsernameWidth}px`;
        });

        // 모든 메시지 컨테이너 요소의 마진을 0으로 설정
        document.querySelectorAll('.message-container').forEach(container => {
            container.style.margin = '0px';
        });
    };

    // MutationObserver를 사용하여 DOM 변화 감지
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                adjustLayout();
            }
        });
    });

    // 관찰할 대상 요소와 설정 (채팅 메시지가 추가되는 컨테이너 지정 필요)
    const config = { childList: true, subtree: true };
    const targetNode = document.body; // 예시로 body를 사용했지만, 실제 채팅 메시지가 추가되는 컨테이너로 변경해야 함

    // 관찰 시작
    observer.observe(targetNode, config);

    // 초기 레이아웃 조정
    adjustLayout();
})();