kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2927 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
ai,청아,버튜버)코코로쨩 마이크로비키니
야짤
gpsel157
05/12 19547 26
이전에 가지고 있던 것 복구(10개)
복구
ziririri123
05/12 51671 169
[LYCO]리오&토키 처벌쇼
영상
ㅇㅇ
05/12 35613 83
古い(furui) 모음
영상
쀏꿱이
05/12 35826 159
ガナイショウ(가나이쇼우) 26.3. 눈나
야짤
kuuki
05/12 10814 41
회복술사의 재시작 서비스씬 모음
영상
고죠/센세
05/12 42222 206
[90일복구] 요청자료 5종
복구
Ghost
05/12 42269 110
[AI번역/초반검수] 쾌락의 저주(The Curse of Pleasure) v1.0
번역
weller703
05/12 72803 245
대리업로드 번역게임 6개
번역
미스터장
05/12 77271 246
[한글자막] [NightHawk(ナイトホーク)] incest village インセストヴィレッジ
영상
lximiad
05/12 30537 73
Ai번역) 여동생의 친구가 동경하던 G컵 갸루 코스플레이어였던 이야기 2
동인
customer121
05/12 29665 180
[구매보급] [버전업] RJ01452526 이상적인 히키코모리 생활 ~부녀의 꽁냥꽁냥 동거~ 1.1.6 26.05.12 "26.05.22(수정)"
번역
gkqisq
05/12 35018 174
[GIF] (후타, 보추, 수?간 포함) QW1wbGVjdGVk gif 모음집
야짤
hannanas
05/12 14639 47
AI, 셀레스포니아) 아마네 데이트편
야짤
miso5
05/12 11903 112
[버전업] [구매보급] RJ01588884 이노센트 도터 v1.1.1
미번
gkqisq
05/12 11585 45
QW1wbGVjdGVk 모음집 없데이트 알림
영상
hannanas
05/12 23938 81
[구매보급] RJ432000 성처리가 있는 학교 2023.04.26
미번
gkqisq
05/12 17108 35
(요청복구, 미검수) Cursed Armor 2
복구
zeri1590
05/12 18207 49
[미번] 오네쇼타 마을의 엣치한 여름방학 스팀 노모 일어판
미번
미스터장
05/12 10035 44
[atahuta] 발정기 한창 오나홀 씨.
동인
ㅇㅇ
05/12 42966 276
[Croriin/노모] 마녀가 아끼는 것
동인
ㅇㅇ
05/12 25370 160
감각 차단 암컷화 트랩! 손번역 및 노모작업 현황
작업현황
미스터장
05/12 12406 36
[ai번역=오오토리 마히로] 나의 이세계 하렘 1
동인
mybest
05/12 17081 42
[유부녀/레이프/밀프쇼타/서양](보루토) 히나타의 숨겨진 욕망
영상
Ghost
05/12 29568 117
[한글자막] 미시 여교사, 쇼타 사정 도와주기 (上편)
영상
실루엣21
05/12 18592 97
QW1wbGVjdGVk 블렌더 파일 공유 첫번째 9.74GB
유틸
hannanas
05/12 15628 21
[bWlyYWNhbg== / RJ01602232] 전생 용사가 즉시 함락 마법으로 이세계 무쌍!! [전편]
영상
yozuna
05/12 26859 178
요몽원 이미지 번역하면 수요 있나?
일반
losress
05/12 6025 55
미번) [airu] 폭유에 엉덩이가 커다란 흑장발 무녀씨에게 사랑이 무거운 개변태봉사로 쥐어짜인다
동인
hun99
05/12 14122 26
[AI/이미지번역] Esurience 일본풍 미인 소꿉친구와 숨겨진 갈망
번역
미식이네
05/12 41476 168