Greasy Fork is available in English.

네이버 카페 - 댓글 클리너

네이버 카페 댓글 이모티콘 숨기기, 내용 없는 댓글 숨기기

// ==UserScript==
// @name         네이버 카페 - 댓글 클리너
// @name:ko         네이버 카페 - 댓글 클리너
// @description  네이버 카페 댓글 이모티콘 숨기기, 내용 없는 댓글 숨기기
// @description:ko  네이버 카페 댓글 이모티콘 숨기기, 내용 없는 댓글 숨기기
// @namespace    http://tampermonkey.net/
// @version      20240316
// @author       You
// @match        https://cafe.naver.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=naver.com
// @grant        GM_addStyle
// @run-at       document-end
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    GM_addStyle(`
        .CommentBox .comment_list .CommentItemSticker .comment_sticker_link .image {
            /*height: 50px !important;*/
            display: none;
        }
        .CommentBox .comment_list .CommentItemSticker {
            display: none;
        }
    `);

    function convertToRelativeTime(timeString) {
        var time = new Date(timeString.replace(/\. /g, '-'));
        var now = new Date();
        var diffMilliseconds = now - time;
        var diffSeconds = Math.floor(diffMilliseconds / 1000);
        var diffMinutes = Math.floor(diffSeconds / 60);
        var diffHours = Math.floor(diffMinutes / 60);
        var diffDays = Math.floor(diffHours / 24);

        if (diffSeconds < 60) {
            return '방금 전';
        } else if (diffMinutes < 60) {
            return diffMinutes + '분 전';
        } else if (diffHours < 24) {
            return diffHours + '시간 전';
        } else if (diffDays === 1 && now.getDate() === time.getDate()) {
            return '어제';
        } else if (diffDays < 7) {
            return diffDays + '일 전';
        } else {
            var monthNames = ["1월", "2월", "3월", "4월", "5월", "6월",
                              "7월", "8월", "9월", "10월", "11월", "12월"];
            return time.getDate() + ' ' + monthNames[time.getMonth()];
        }
    }

    function getReadableTime(item) {
        var commentInfoDateElement = item.querySelector('span.comment_info_date:not(.done)');

        if (commentInfoDateElement) {
            var inputTime = commentInfoDateElement.textContent.trim();
            var formattedTime = inputTime.replace(/(\d{4})\.(\d{2})\.(\d{2})\. (\d{2}):(\d{2})/, '$1-$2-$3T$4:$5:00');
            var relativeTime = convertToRelativeTime(formattedTime);

            commentInfoDateElement.textContent = relativeTime;
            commentInfoDateElement.setAttribute('title',`${inputTime}`);
            commentInfoDateElement.classList.add('done');
        }
    }

    function checkDynamicElements() {
        var commentItems = document.querySelectorAll('.CommentItem');

        commentItems.forEach(function(item) {
            var textComment = item.querySelector('.text_comment');
            if (!textComment || textComment.textContent.trim() === '') {
                item.style.display = 'none';
            } else {
                item.style.display = 'block';
            }
            getReadableTime(item);
        });
    }

    var mutationCallback = function(mutationsList, observer) {
        checkDynamicElements();
    };

    var observer = new MutationObserver(mutationCallback);

    var targetNode = document.body;
    var config = { childList: true, subtree: true };

    observer.observe(targetNode, config);

})();