kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2940 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
⚠️⚠️멀웨어 탐지 스크립트 (신종 RAT) - 260502⚠️⚠️
유틸
moomin
05/02 17483 103
RPG Maker MV/MZ 실시간 번역기 3.1 (구동휘정3 대응 -3)
유틸
mrpls
04/30 17234 36
게임을 윈도우 샌드박스 안에서 실행하는 스크립트 (악성코드 대책)
유틸
mrpls
04/30 7331 19
[노모파일, AI] 파치몬 -8bit MONSTER-
유틸
soxocel777
04/29 20447 56
자동 소미 해적판의 해적판의 해적판 (260503 13:58 v1.3.5 업데이트)
유틸
bellbell
04/28 13549 38
[복구] 란스03 노모패치
유틸
imakotou
04/28 16050 28
MZ MV data 복호화 실행기
유틸
미요포
04/27 13667 38
제품 코드 추출기, 제품 코드 중복 찾기
유틸
ㅇㅇ
04/27 8548 18
MMD 모션,음악 통팩 공유
유틸
pst0025
04/26 9187 56
(코이카츠) 솔O티엘 작가 프리셋 통팩 공유
유틸
pst0025
04/25 12145 73
(코이카츠) 에러난 파일 복구 및 빠진거 보완
유틸
pst0025
04/25 10718 31
RPG MV/MZ 치트 플러그인 웹 딸깍 설치 오픈
유틸
mrpls
04/25 11374 28
RPG MV/MZ 안실시간 미리번역 업데이트
유틸
mrpls
04/23 7824 27
(코이카츠) - "큰거"
유틸
pst0025
04/22 16068 66
(코이카츠) 큰거 올리기 전에 작은거
유틸
pst0025
04/22 18964 62
(코이카츠) - 최신 프리셋 일부 공유 [v2]
유틸
pst0025
04/22 10920 45
마나카 모드들
유틸
kkkktrrr
04/22 17175 33
(코이카츠) - 최신 프리셋 일부 공유
유틸
pst0025
04/21 10777 48
RPG MV/MZ 실시간 번역기 딸깍 설치 웹사이트 오픈 (2.3 번역 주위 짤림)
유틸
mrpls
04/19 33325 106
(코이카츠) - グラフ 통팩 공유
유틸
pst0025
04/19 23176 56
RPG MV/MZ 실시간 번역기 1.10 (루나와 음욕의 함정 던전, 젬마4)
유틸
mrpls
04/18 24752 35
[노모패치, AI] 한 번만이라도 좋으니까, 나랑 해줘!
유틸
soxocel777
04/17 15270 29
( 코이카츠 ) - Anna anon 씬카드 공유
유틸
pst0025
04/16 24333 63
이미지 폴더 병합 & 일괄 이름 변경
유틸
noname
04/15 11563 30
RPG VX ace게임 전체화면으로 하는 꿀팁
유틸
야겜인생
04/14 11698 19
(코이카츠) Shibal 통팩
유틸
pst0025
04/14 19400 57
[노모패치] 부유마법도시의 레이 ~직계의 마도사~
유틸
데프픗
04/14 19635 28
[노모패치] Restore
유틸
데프픗
04/14 11713 21
[노모패치] 엘프 소녀 리피아와 몽환의 미궁
유틸
데프픗
04/14 18960 23
[90일] 용병의 모험 v3.001 노모 패치
유틸
ㅇㅇ
04/13 19100 47