kone
소미소프트

소미소프트

개념글/전체글 버튼 분리 스크립트(수정)

05/27/2025, 09:41:09
유틸
2882 views · 3 likes

스크립트 지식 1도없이 챗지피티로 만들었습니다~ 문제시 글삭함

오류 생기면 스크립트 삭제 추천드려요



1

원래 이렇게 붙어있던 개념글/전체글 버튼을



1

이렇게 분리했습니다. 왼쪽은 전체글 모드, 오른쪽은 개념글 모드


그리고 중요한건 전체글일때 전체글 버튼 누르면 전체글 새로고침됨

마찬가지로 개념글일때 개념글 버튼 누르면 개념글 새로고침됨

새로고침 할려고 버튼 나눈거임


하 근데 최신순(시계모양) 버튼이 버튼 오른쪽에서 왼쪽으로 가버림.. 이건 못고치겟서


1

게시판 하단에 있던 버튼도 바뀝니다


1
1

확장프로그램 템퍼몽키 설치하시고 새 스크립트 만들기 > 안에 내용 지우고 스크립트 복붙 > 저장




아래는 스크립트 코드

// ==UserScript==
// @name         kone.gg 개념글/전체글 버튼 삽입(수정판)
// @namespace    http://tampermonkey.net/
// @version      2.4
// @description  게시판 개념글/전체글 버튼 삽입 수정
// @match        https://kone.gg/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    let lastUrl = location.href;

    const createButton = (text, onClick, isActive) => {
        const button = document.createElement('button');
        button.textContent = text;
        button.style.cssText = `
            margin-right: 8px;
            padding: 6px 12px;
            border: none;
            border-radius: 9999px;
            font-size: 14px;
            cursor: pointer;
            background-color: ${isActive ? '#dc2626' : '#e4e4e7'};
            color: ${isActive ? 'white' : '#27272a'};
        `;
        button.addEventListener('click', onClick);
        return button;
    };

    const insertButtons = () => {
        const url = location.href;
        const isHot = url.includes('mode=hot');
        const basePath = location.pathname;

        const boardWrapper = document.querySelector('div.grow.flex.flex-col.rounded-b-lg');
        if (!boardWrapper) return;

        const buttonRows = boardWrapper.querySelectorAll('div.flex.items-center.gap-2');
        if (!buttonRows.length) return;

        buttonRows.forEach((targetRow) => {
            if (targetRow.querySelector('a[href*="write"]')) return;
            if (targetRow.querySelector('#custom-btn-hot') || targetRow.querySelector('#custom-btn-all')) return;

            // 기존 개념글/전체글 a 링크 삭제
            targetRow.querySelectorAll('a[href]').forEach(link => {
                const href = link.getAttribute('href');
                if (href.includes('mode=hot') || href === basePath) {
                    link.remove();
                }
            });

            const hotBtn = createButton('개념글', () => {
                window.location.href = basePath + '?mode=hot';
            }, isHot);
            hotBtn.id = 'custom-btn-hot';

            const allBtn = createButton('전체글', () => {
                window.location.href = basePath;
            }, !isHot);
            allBtn.id = 'custom-btn-all';

            targetRow.appendChild(allBtn);
            targetRow.appendChild(hotBtn);
        });
    };

    // 버튼 삽입 및 재삽입 시도
    const tryInsertButtons = () => {
        insertButtons();
    };

    // history API 훅 감싸기
    const hookHistoryMethod = (method) => {
        const original = history[method];
        return function () {
            const result = original.apply(this, arguments);
            window.dispatchEvent(new Event('locationchange'));
            return result;
        };
    };
    history.pushState = hookHistoryMethod('pushState');
    history.replaceState = hookHistoryMethod('replaceState');

    window.addEventListener('popstate', () => window.dispatchEvent(new Event('locationchange')));
    window.addEventListener('locationchange', () => {
        if (lastUrl !== location.href) {
            lastUrl = location.href;
            tryInsertButtons();
        }
    });

    // DOM 변경 감지해서도 버튼 갱신 (최상위 body 감시)
    const observer = new MutationObserver(() => {
        tryInsertButtons();
    });
    observer.observe(document.body, { childList: true, subtree: true });

    // 최초 실행 딜레이 줘서 기다렸다 삽입
    setTimeout(() => {
        tryInsertButtons();
    }, 1000);

})();
3
2 comments
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
Poriuretan 수영부의 에이스
동인
uzaki
04/25 15345 37
Poriuretan 여름 해변에서 의기투합
동인
uzaki
04/25 18067 48
Poriuretan 시골누나
동인
uzaki
04/25 16306 46
Poriuretan 선생님
동인
uzaki
04/25 13292 31
Poriuretan 옆방의 아주머니
동인
uzaki
04/25 14114 28
Poriuretan 정오가 지난 오후의 단지아내
동인
uzaki
04/25 15595 30
Poriuretan 폭풍전의 도서실
동인
uzaki
04/25 11619 28
Poriuretan 장마철의 빨래방
동인
uzaki
04/25 11427 43
Poriuretan 갸루b의 파파카츠
동인
uzaki
04/25 12749 60
[미번][번역요청] 디펜드 다이어리~_ver1.02
미번
minki
04/25 20962 27
[미번] RJ01612483,RJ01414102
미번
페비
04/25 55582 261
[요청복구] RJ01412500 Night High 5
미번
아무일도없었다
04/25 19239 37
기번) 더블 유부녀(미검수)
번역
썩은동태눈깔맨
04/25 32181 106
특공위원회 오우카 RPG 0 이미지(ui) 번역 80% 진행
작업현황
joyed47106
04/25 7201 19
[한국어 자막판][구매보급][전편느긋오호】 다우너 오호고에 개변태 후배와 섹스라이프
소리
이름뭐하지
04/25 19608 69
[미번] 비주얼노벨계 야겜 11개
미번
미스터장
04/25 19273 92
기번) BBC×FAMILY~
번역
썩은동태눈깔맨
04/25 42911 215
(요청복구) 테러블 레버토리 v1.01
복구
kakinara12
04/25 39293 62
고블린 네스트 세이브 최신화 완
세이브
흰꼴뚜기
04/25 8632 15
RJ388166 에이전트 시리우스 DLC
복구
doritori
04/25 27970 63
개꽂혀서 최소 10시간 이상 박았던 게임들
후기 및 공략
dpgutlqkf
04/25 30245 82
~임신 전설~ 옛 용사인 나와 초변태 폭유 공주님×3의 모유 듬뿍 임신시키기 아이 만들기 마왕 봉인 전설♪
소리
dasdaa
04/25 23358 109
후타, 명방) [직번] 시한테 박는 니엔
동인
wa4231
04/25 16082 94
[구매보급]【사상 최고의 오호신음】몰락 메스가키 영애 음문 조교
소리
이름뭐하지
04/25 13374 63
(요청복구) カーテンのむこう NTR 커튼 너머 NTR ver.1.8
복구
sinryeong
04/25 28073 90
[기번] 사신상관EX+DLC 2.0.02
번역
풍수식노천탕
04/25 52306 185
(요청복구) 무치 무치 자매 환생 목적지에서 변태 봉사 생활
복구
sinryeong
04/25 20972 67
메르시 (오버워치)
영상
브레머튼
04/25 19891 101
(청아) 꾸준 연필 30주차
창작
지나가던사람
04/25 17165 28
[AI번역] [JUNN] 네토라레바에 - 인싸 여친의 SNS 네토라레 기록 2
동인
gkcuwuwlltnnrra
04/25 44611 153