kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2801 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
섀도우버스WB 카드 누패
유틸
나나바
05/27 1792 9
방주 해제 스크립트 공유
유틸
ddiff
05/26 2638 9
unholy maiden seed of profanity모드 1.4
유틸
leessss25
05/26 2074 13
[복구]섹타듀벨리 모드팩
유틸
continuereset
05/26 5099 20
[그냥복구/본체없음] 배덕의 달콤함에 물든 마나카. 여기서 받은 모드팩
유틸
루파조아
05/26 2984 9
FORTUNE BRIDE ~절정개안의 의식~ 노모 패치
유틸
미스터장
05/24 6456 33
(코이카츠) 엔드필드 프리셋 공유
유틸
pst0025
05/23 8890 65
EnigmaVBUnpacker (MV MZ 언팩) 웹버전 오픈
유틸
mrpls
05/23 4319 15
파일/ 압축/ 폴더 제목의 품번 괄호 삭제해주는 유틸
유틸
몬스터가아니다신이다
05/23 2904 2
[패치만] 시니시스타2 따거 MOD
유틸
하우두유두
05/22 14068 50
(수정 사항3)내가 쓸려고 만든 코드 검색용 + 파일관리
유틸
ATTAA
05/21 4030 14
[노모패치] 갓 딴 임신시키기 좋은 날
유틸
나나바
05/21 9832 39
zenpy 폰트 설치기
유틸
thxl23
05/20 3534 6
내가 쓸려고 만든 유틸 프로그램임
유틸
몬스터가아니다신이다
05/20 4168 6
내가 쓸려고 만든 DLsite 코드 검색 용
유틸
ATTAA
05/19 5986 7
내가 쓸려고 만든 유니티 버전별 폰트랑 어디서 구해온거 (오토트랜스용)
유틸
neighborsbear
05/19 6905 4
[요청복구] 감옥용사 1.20 조이플 구동패치
유틸
ssddttj
05/17 3250 5
누군가 쓸 마법의하나 マホウノハナ 0.9e 실시간 번역용 프리패쳐 파일
유틸
ㅇㅇ
05/17 7152 8
키리키리 엔진 ScnEditorGUI 개선판 (scn 암호화 파일 에디터)
유틸
joyed47106
05/16 6721 7
시니시스타 2 업뎃기념 모드 모음
유틸
sims9876
05/16 20896 105
(코이카츠) 버튜버 프리셋 공유 ver.2
유틸
pst0025
05/16 13325 51
(코이카츠) 버튜버 프리셋 공유 (복구)
유틸
pst0025
05/16 14771 64
WebP_Converter 코네 다운로드하다 WebP 불편해서 만든 프로그램
유틸
noname
05/15 13211 16
(코이카츠) 최근에 풀린 프리셋 공유
유틸
pst0025
05/15 12770 34
[RPG Maker MV/MZ 실시간 번역기] 4.0 출시
유틸
mrpls
05/15 22718 70
내가 쓰려고 만든 동음 정리 유틸
유틸
yeppi
05/15 8250 24
Texture Tool for Unity 6 ( Mono / IL2CPP ) v0.1.1 최초 배포 버전
유틸
argoklarke
05/14 15267 28
(코이카츠) 학원마스 프리셋 공유
유틸
pst0025
05/14 15650 43
(코이카츠) 프리셋 공유
유틸
pst0025
05/14 11568 58
comfyui를 이용해서 배경음을 식질해보자
유틸
프로베스트캣
05/14 20852 13