kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2999 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
MV, MZ 대사 스킵 플러그인
유틸
r4gsdrg
04/11 13948 19
코이카츠 프리셋 히가시 통팩 보강
유틸
pst0025
04/11 11704 27
(코이카츠) 갓 나온 따끈따끈한 프리셋
유틸
pst0025
04/10 28252 54
올려두면 누군가 개꼴리는 MMD를 뽑아주겠지
유틸
네토라레프린세스
04/09 12534 23
코이카츠 명조 캐릭터 프리셋 공유 (v3)
유틸
pst0025
04/08 22805 51
[노모패치] 미궁 거리의 그레이스
유틸
빙구론희
04/08 21674 29
코이카츠 명조 프리셋 공유 (2)
유틸
pst0025
04/07 11713 52
코이카츠 의상 공유 1
유틸
pst0025
04/07 11996 60
던전 앤 브라이드 치트엔진용 테이블
유틸
nooom
04/06 11387 24
코이카츠 프리셋 공유 ( SolityL pack )
유틸
pst0025
04/06 13563 59
코이카츠 최애작가 4인 모음 (딸각 한방 패치 + 말딸캐릭터 제외 수정)
유틸
imakotou
04/05 14741 67
ㅁㅁㅁ로 깨지는 유니티 폰트 변경 방법
유틸
네토라레프린세스
04/05 5821 18
코이카츠 벽람 프리셋 공유 (개인 수정본)
유틸
pst0025
04/05 11936 30
코이카츠 아랴양 프리셋 콜렉션 공유
유틸
pst0025
04/05 9088 27
코이카츠 프리셋 공유 (히가시 통팩)
유틸
pst0025
04/05 13365 62
로컬LLM(Ollama) 이용한 파이썬 MV 번역 코드
유틸
샤쿠
04/04 21887 21
[RJ01389782] [AI 번역] 비밀 노출 마나카 커스텀 미션 번역 [SekiMissions 8.5]
유틸
bunta_expert
04/04 11559 21
자동소미 해적판
유틸
buttercookie
04/03 7765 21
kio transfer 비번 자동입력
유틸
20250508
04/03 5186 22
코이카츠 버튜버 캐릭터 공유(v2)
유틸
pst0025
04/02 12005 53
눈동자 다운로더 GUI (아마도 최신버전)
유틸
하이바라
04/02 6133 16
코이카츠 야스씬 공유 - (홍차)
유틸
pst0025
04/01 13556 37
코이카츠 벽람 프리셋 공유(v2)
유틸
pst0025
04/01 15348 46
코이카츠 (?) 프리셋 공유
유틸
pst0025
04/01 16043 33
디코드 클릭하기 귀찮아서 만든 확장프로그램
유틸
20250508
03/31 11125 57
(빅파이 개조만) 평범한 현실 남매 IN 섹스하지 않으면 나올 수 없는 방.[RJ01332822]
유틸
123551
03/29 8597 15
Base 64 Encode Decode 확장 프로그램 만들어 봤습니다.
유틸
shinyiro18
03/28 6634 18
아오이짱 BepInEx 번역플러그인 잘리던거 해결봤다...
유틸
lalalala000
03/28 24378 59
(코이카츠) 시니시스타2 캐릭터 공유 - [리리아]
유틸
pst0025
03/27 20008 40
(코이카츠) 원신 캐릭터 공유
유틸
pst0025
03/27 10428 33