// ==UserScript==

// @name         DC Inside Topic Blocker

// @namespace    http://tampermonkey.net/

// @version      1.0

// @description  DC Inside 갤러리에서 특정 키워드가 포함된 게시글을 차단합니다.

// @author       Assistant

// @match        https://gall.dcinside.com/*

// @grant        none

// @run-at       document-idle

// ==/UserScript==


(function() {

    'use strict';


    // 차단할 키워드 목록 (필요에 따라 수정 가능)

    const BLOCK_KEYWORDS = [

        '힘차게', '쿠폰', '공주', '꼭노', '탱글', '틱톡', '짱개',

        'ㅎㅂ', '후기', '대부분 모르는', '학점', '19', '한국', '후방'

    ];


    function findPostRow(element) {

        return element.closest('tr') || element.closest('.gall_list_wrap li') || element.closest('div.ub-content');

    }


    function containsBlockedKeyword(text) {

        if (!text) return false;

        const lowerText = text.toLowerCase();

        return BLOCK_KEYWORDS.some(keyword => lowerText.includes(keyword.toLowerCase()));

    }


    function filterPosts() {

        const titles = document.querySelectorAll('.gall_subject, .title, .ub-word');


        titles.forEach(titleElement => {

            const text = titleElement.innerText;

            if (containsBlockedKeyword(text)) {

                const row = findPostRow(titleElement);

                if (row && row.style.display !== 'none') {

                    row.style.display = 'none';

                    // console.log('Blocked post:', text);

                }

            }

        });

    }


    filterPosts();


    const observer = new MutationObserver((mutations) => {

        let shouldFilter = false;

        mutations.forEach((mutation) => {

            if (mutation.addedNodes.length > 0) {

                shouldFilter = true;

            }

        });


        if (shouldFilter) {

            filterPosts();

        }

    });


    const targetNode = document.body;

    const config = { childList: true, subtree: true };


    if (targetNode) {

        observer.observe(targetNode, config);

    }


})();