kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2918 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
엘렌 오랄 & 핸드잡 (ZZZ)
영상
브레머튼
04/28 24859 131
ai, 이터널 리턴) 수영복 마를렌과 순애 섹스
야짤
kjh9304
04/28 15861 69
[구매보급][버전업][DLC포함] 타락신관: 여동생과 악마의 혈통 v1.3.2 steam 04/26/1237
번역
Ghost
04/28 126048 629
Shaggy Susu 신작 원신 감우
영상
ㅇㅇ
04/28 17165 142
[미번보급] お姉ちゃんにはナイショの同居生活——血より濃いミルクティー関係
미번
karoru
04/28 18203 29
(구매보급/ai 번역/NTL/트름 주의) 【NTR 타락】남자친구가 있는 오만한 미나토구 여성을 감금하고 7일간 훈육하다~
소리
Ghost
04/28 15196 74
직번) [AI번역] [Punifuka Ume] 누님계의 유부녀는 배신의 끝에 네토라레 당한다
동인
코코네
04/28 30129 106
타락신관 DLC 추가된점 및 여관 이벤트 분기점 공략 및 후기
후기 및 공략
asdf788
04/28 26493 47
[메이초기주쿠] 【루나와 색욕의 고도】 제작 #3
정보
날개 로봇
04/28 11766 17
【초밀착 속삭임】 파파♡~ 몽글몽글 F컵의 의붓딸에게서 계속 달콤달콤 속삭임♡ 엄마가 잠든 옆에서 밀착 처벌 아이 만들기 에치♡~ 【듬뿍 무성음】
소리
키리안
04/28 13214 108
[Migihaji] 러브가 아니라면 프리섹스 1~2
동인
ㅇㅇ
04/28 40646 203
[수정알림] 대리업로드 번역게임 수정된거 재업
번역
미스터장
04/28 38090 110
[직번] [Kagto] 반찬 당번의 성태 - 딸감 여신 마치다짱
동인
acefs
04/28 40810 180
[4K] 타카기 양, 이미지 비디오(?)에 출연하다
영상
실루엣21
04/28 31885 131
(노모화) [Shiwasu No Okina] 그녀 그이 그녀 -단행본 버전 작업중-
동인
xbox
04/28 18915 70
[Gamogamo] 이웃집의 음침퇴폐(다우너) 모녀에게 착정당하는 이야기
동인
ㅇㅇ
04/28 35534 234
내가 맛있게 먹었던거 복구 (청아)
복구
순애좋아
04/28 83741 336
[구매보급] [버전업] RJ01588884 외 1
미번
gkqisq
04/28 14518 46
[구매보급]왕궁 여자 기사의 처녀 연애 - 마지못해 그녀는 당신을 사랑한다
소리
이름뭐하지
04/28 10523 56
[구매보급] 【한국어 자막판】 【1시간 50분】 당신을 놓아주지 않아! 초밀착♪ 달콤한 속삭임 변태 체험판〜3명의 히로인 모음집〜
소리
puella
04/28 17732 73
[AI] 내 여자친구가 지배 어플로 NTR 방송되고 있는데
번역
미식이네
04/28 68170 221
[구매보급] [버전업] RJ01582213 라스티던전2 ver1.0h 2026.04.25
미번
gkqisq
04/28 12036 48
[구매보급] [버전업] [청아] RJ157224 공원장난 한국어 ver.MAKO 1.3 (Type A) 23.11.11
미번
gkqisq
04/28 13377 44
(초스압,스토리스포x)性処理用勇者 성처리용용사 후기 및 짧공략
후기 및 공략
끄얽돍
04/28 14188 21
[AI번역] [kojirou] 환상거유
동인
cjd08
04/28 12193 36
자동 소미 해적판의 해적판의 해적판 (260503 13:58 v1.3.5 업데이트)
유틸
bellbell
04/28 13549 38
Re:Dive 뉴토끼
일반
의인화
04/28 24756 204
어떤 버튜버 사진들~
야짤
지나가던허접a
04/28 15833 31
[구매보급]서머 폴리
소리
이름뭐하지
04/28 14130 74
리오 - Chill like that
영상
Poznan
04/28 24648 89