kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2802 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
RJ코드 추출해서 클릭하면 바로 이동되는 파이썬 코드
유틸
siasia
04/15 8847 4
이미지 폴더 병합 & 일괄 이름 변경
유틸
noname
04/15 11550 30
RPG VX ace게임 전체화면으로 하는 꿀팁
유틸
야겜인생
04/14 11598 19
(코이카츠) Shibal 통팩
유틸
pst0025
04/14 19385 57
[노모패치] 성기사이야기 ~소녀에게 다가오는 음욕귀족~
유틸
데프픗
04/14 8669 13
[노모패치] 부유마법도시의 레이 ~직계의 마도사~
유틸
데프픗
04/14 19606 28
[노모패치] Restore
유틸
데프픗
04/14 11701 21
[노모패치] 엘프 소녀 리피아와 몽환의 미궁
유틸
데프픗
04/14 18943 23
[90일] 용병의 모험 v3.001 노모 패치
유틸
ㅇㅇ
04/13 19098 47
청아)코이카츠 미유 완성 기념 프리셋 공유
유틸
이상한 사람
04/12 11869 14
RPGM VXA 스크립트) ▼ 素材 ## 한글이름 입력 스크립트.txt
유틸
ㅇㅇ
04/11 6114 2
[복구] [유틸] DYSTHANASIA v1.0.8.1 텍스처패치 + 필터링 제거 패치
유틸
kkkkkk0909
04/11 10378 4
MV, MZ 대사 스킵 플러그인
유틸
r4gsdrg
04/11 13920 19
줄 바꿈, RPGM VXA 스크립트) ▼ シーン ## 자동 줄바꿈.txt
유틸
ㅇㅇ
04/11 8906 2
코이카츠 프리셋 히가시 통팩 보강
유틸
pst0025
04/11 11692 27
어르신들 빠알리 오세요~~~~~~~BeatMania98
유틸
a123456789
04/11 9553 9
(코이카츠) 갓 나온 따끈따끈한 프리셋
유틸
pst0025
04/10 28239 54
올려두면 누군가 개꼴리는 MMD를 뽑아주겠지
유틸
네토라레프린세스
04/09 12510 23
코이카츠 명조 캐릭터 프리셋 공유 (v3)
유틸
pst0025
04/08 22805 51
[노모패치] 미궁 거리의 그레이스
유틸
빙구론희
04/08 21666 29
코이카츠 명조 프리셋 공유 (2)
유틸
pst0025
04/07 11700 52
코이카츠 의상 공유 1
유틸
pst0025
04/07 11983 60
던전 앤 브라이드 치트엔진용 테이블
유틸
nooom
04/06 11370 24
코이카츠 프리셋 공유 ( SolityL pack )
유틸
pst0025
04/06 13556 59
파라서큐 조이플 이펙트 효과,사운드 패치
유틸
아이제이
04/06 6350 4
코이카츠 최애작가 4인 모음 (딸각 한방 패치 + 말딸캐릭터 제외 수정)
유틸
imakotou
04/05 14726 67
ㅁㅁㅁ로 깨지는 유니티 폰트 변경 방법
유틸
네토라레프린세스
04/05 5820 18
코이카츠 벽람 프리셋 공유 (개인 수정본)
유틸
pst0025
04/05 11914 30
코이카츠 아랴양 프리셋 콜렉션 공유
유틸
pst0025
04/05 9078 27
코이카츠 프리셋 공유 (히가시 통팩)
유틸
pst0025
04/05 13335 62