kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2804 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
Joiplay 1.20.611
유틸
o_o
08/30/25 6770 7
검은정복왕 공략
유틸
pqland5051
08/30/25 14550 8
제복 그녀 2.5
유틸
미스터장
08/27/25 6338 25
감옥용사 조이플 구동 패치
유틸
DASL
08/26/25 2103 7
시니시스타2 아헤모드 v3
유틸
cordial
08/24/25 25485 32
쯔꾸르 MV,MZ AI 번역 툴과 그 외 번역에 유용한 툴들 공유 및 사용법 대충 정리
유틸
미스터장
08/22/25 40849 128
시니시스타2 1.1 아헤모드 v2
유틸
cordial
08/18/25 12222 24
유저 차단 스크립트 업데이트 알림
유틸
글쓴이
08/17/25 5329 6
[스팀노모이미지만] BLACK SOULS ~검은 동화와 오마 공주~
유틸
미스터장
08/16/25 4923 17
동인메뉴판 - 동인지 관리 유틸 만들어옴
유틸
qqoro
08/15/25 24202 95
음문이 새겨진 마더 알리시아 ver.1.483 신음 소리 증폭
유틸
shdcd
08/15/25 3458 3
Auto Somi 업데이트
유틸
김머시기
08/11/25 9272 38
유니티 게임 XUnity.AutoTranslator용 폰트모음
유틸
미스터장
08/11/25 8027 12
시니시스타2 1.1 아헤모드
유틸
cordial
08/11/25 13512 30
던전앤브라이드 후기와 상세정보
유틸
positron
08/09/25 11922 13
히토미 다운로더용 케모노 다운로드 스크립트
유틸
글쓴이
08/08/25 19431 20
유니티 자동번역기 유니티6000 tmp 폰트 에셋 번들
유틸
1bvk3b6ka8
08/07/25 4835 11
DLsite 썸네일 원클릭! 다운로더 v0.2.1 (20250806) 스크립트
유틸
Legnax
08/05/25 3884 10
공식AI번역에서 추출한 마인드 류다 이미지번역파일만
유틸
미스터장
08/05/25 4759 19
시니시스타 2 모드 모음(1.10)
유틸
sims9876
08/05/25 9704 15
Joiplay 1.20.600
유틸
o_o
08/05/25 5242 7
DLsite 썸네일 원클릭! 다운로더 v0.1.1 (20250805) 스크립트
유틸
Legnax
08/05/25 3185 6
[버려짐] 던전 앤 브라이드 치트모드 1.44 업데이트 + 번역 모드 대응 버전 출시 *10/15 18:33 수정
유틸
rengester
08/05/25 30060 64
울프툴 3.625 한글화
유틸
brothers
08/03/25 3682 16
사파리 base64 디코딩 단축어
유틸
wjsrlzhs
08/03/25 1995 1
[게임 미포함] 배덕의 충동 v1.2 아랫털 추가 패치
유틸
털털털털털털털털
08/03/25 5526 14
Winlator (엑시노스 구동 가능)
유틸
o_o
08/02/25 14715 16
[버려짐] 내가 직접 만든 던전 앤 브라이드 모드 공유 *치트 기능 추가 08/04 10:03 수정
유틸
rengester
08/02/25 13464 24
update0731 DL + STEAM 미리보기 크롬 확장.
유틸
ddegul
07/30/25 3444 11
거01212155 특전 비밀번호와 수정파일
유틸
커댕이
07/30/25 3166 4