kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
3007 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
타락신관 조이플 이미지 오류 해결
유틸
yeppi
11/23/25 7856 21
RPG MV/MZ 실시간 번역기 - 1.3
유틸
mrpls
11/15/25 22831 116
[노모패치] 란스03
유틸
imakotou
11/14/25 12834 70
포레스티아 낚시 파일 수정본
유틸
geekel
11/09/25 4927 21
demosaic colMask
유틸
kumarin
11/06/25 37451 57
후타)잠꾸러기 후타나리의 착정던전 구출기 노모패치
유틸
레가토
11/03/25 12699 18
[일부 노모패치] 서큐버스 & 매직 (청아,언버스짤 있음)
유틸
OTGie
11/02/25 5590 26
[노모패치]신인마왕과 100명의 연인들
유틸
아르
11/02/25 10661 35
Anaertailin 작가의 Slay the Spire 모음집
유틸
삐뉴
11/01/25 26471 42
[노모 + 텍스쳐 패치] 여신 메르의 만지작 동거 성활 v1.0
유틸
털털털털털털털털
11/01/25 11603 67
무료 BGM 모음집 2025.11.01.
유틸
날개 로봇
11/01/25 4856 15
다시 돌아온 다키스트 던전 NSFW 완전판 [Npc 리텍 / 영웅 리텍 / 이쁜이쁜 영웅 모드 / 몬스터 리텍] + 새 모드!
유틸
삐뉴
10/30/25 21709 122
슬레이 더 스파이어 (Slay The Spire) R18 패치 모드
유틸
cirial
10/28/25 27115 43
미끼 치한 수사관 리나 모드
유틸
happy123
10/27/25 10062 17
일라이자의 비약 노모(Decensor) 패치
유틸
이브라브
10/26/25 4802 25
코네 추천순 정렬 스크립트 업데이트
유틸
ducktail
10/24/25 12787 38
코네 추천 컷 & 추천순 정렬 스크립트
유틸
ducktail
10/20/25 10726 59
MV/MZ 실시간 번역기 0.3 업데이트
유틸
moveit
10/18/25 6340 47
[노모이미지만][청아] 호문쿨루스와의 성생활 노모패치
유틸
Ghost
10/16/25 8957 64
오토소미 autosomi업뎃함
유틸
김머시기
10/13/25 8637 61
방주정리기 (파일명정리 프로그램) v1.16 (26.04.04)
유틸
알비노
10/12/25 14229 54
RPG Maker MV/MZ 실시간 번역기 (DeepL) - 셀레스포니아 3in1 외 기타등등 가능
유틸
moveit
10/11/25 12122 36
도나도나 미검열 CG 오류 수정 최종완성본final최종2
유틸
riel64
10/06/25 14827 77
카린즈 프리즌 cc모드 기계번역해옴
유틸
고추보집물
10/03/25 8956 39
무기력 천사 추가 렉 개선 패치 (a.k.a 쯔꾸르는 최적화 쓰레기가 분명하다)
유틸
erukajihx
10/02/25 6681 65
다키스트던전 Deovolente 에디션
유틸
doyoulikekim
09/27/25 9874 29
[v10] 자동 소미 Auto Somi 개조판
유틸
마나난
09/26/25 14504 22
좀더! 불꽃의 시리즈 붉은화면 수정패치
유틸
adsv42
09/23/25 3815 15
도나도나 미검열 CG 오류들 수정
유틸
riel64
09/23/25 17314 77
SW_Decensor v0.7.4.1
유틸
kumarin
09/21/25 9520 38