kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2808 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
[일부 노모패치] 서큐버스 & 매직 (청아,언버스짤 있음)
유틸
OTGie
11/02/25 5573 26
[노모패치]신인마왕과 100명의 연인들
유틸
아르
11/02/25 10644 35
Anaertailin 작가의 Slay the Spire 모음집
유틸
삐뉴
11/01/25 26361 42
[노모 + 텍스쳐 패치] 여신 메르의 만지작 동거 성활 v1.0
유틸
털털털털털털털털
11/01/25 11488 67
무료 BGM 모음집 2025.11.01.
유틸
날개 로봇
11/01/25 4839 15
다시 돌아온 다키스트 던전 NSFW 완전판 [Npc 리텍 / 영웅 리텍 / 이쁜이쁜 영웅 모드 / 몬스터 리텍] + 새 모드!
유틸
삐뉴
10/30/25 21709 122
[노모패치] PRIMITIVE HEARTS (DMM판O, 스팀판X)
유틸
마나난
10/29/25 2310 7
슬레이 더 스파이어 (Slay The Spire) R18 패치 모드
유틸
cirial
10/28/25 27087 43
미끼 치한 수사관 리나 모드
유틸
happy123
10/27/25 10044 17
렌파이 갤러리 강제 오픈 스크립트
유틸
난민1호
10/27/25 2761 9
일라이자의 비약 노모(Decensor) 패치
유틸
이브라브
10/26/25 4649 25
압축파일 썸네일 확장
유틸
h-aszzcb
10/24/25 1773 9
코네 추천순 정렬 스크립트 업데이트
유틸
ducktail
10/24/25 12769 38
추출된 *.txt 파일 번역툴 ( 파워셀 코드)
유틸
lovesccubus
10/23/25 1965 5
코네 추천 컷 & 추천순 정렬 스크립트
유틸
ducktail
10/20/25 10554 59
[폰트파일] 네노토리 2.0에 들어있던 MsNanumGothicWK 폰트파일
유틸
katress
10/19/25 3040 6
MV/MZ 실시간 번역기 0.3 업데이트
유틸
moveit
10/18/25 6267 47
동인 런처 db활용 딸각 방주 이름 정리기 GUI판
유틸
asdf1243
10/16/25 3141 11
[노모이미지만][청아] 호문쿨루스와의 성생활 노모패치
유틸
Ghost
10/16/25 8839 64
RPG Maker MV, nwjs 프로필 오류 프레임 드랍 해결방법
유틸
rinsor
10/15/25 3334 14
동인런처 db 백업 기능을 활용한 방주이름 딸깍 정리기
유틸
asdf1243
10/14/25 2360 3
기번 누락 대사 검수 보조 툴 (Tsukuru Extractor 보조 툴)
유틸
bermuda
10/14/25 2107 11
오토소미 autosomi업뎃함
유틸
김머시기
10/13/25 8623 61
방주정리기 (파일명정리 프로그램) v1.16 (26.04.04)
유틸
알비노
10/12/25 14036 54
RPG Maker MV/MZ 실시간 번역기 (DeepL) - 셀레스포니아 3in1 외 기타등등 가능
유틸
moveit
10/11/25 11927 36
쯔꾸르[MV]MOG플러그인[MZ]SOR배틀링 파일 교환용 플러그인-1.3
유틸
brothers
10/11/25 1281 5
감옥용사 조이플 오류 패치파일
유틸
감비아
10/11/25 5647 6
자작 암호화된 링크 새탭으로 띄워주는 크롬 확장프로그램 공유
유틸
cx7175
10/11/25 2006 13
자작 히토미 다운로더 헬퍼 크롬 확장프로그램 공유
유틸
cx7175
10/10/25 4549 4
도나도나 미검열 CG 오류 수정 최종완성본final최종2
유틸
riel64
10/06/25 14810 77