kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2898 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) 큐어 아르카나 섀도 비키니
야짤
Ghost
05/16 17349 47
ai) 큐어 아르카나 섀도
야짤
Ghost
05/16 9598 34
ai) ----움짤---- 렌탈카노죠
야짤
Ghost
05/16 19139 47
[요청복구] RJ297120 마법소녀 셀레스포니아 v1.10 순정
복구
toung
05/16 19350 42
[구매보급]【한국어 자막판】 【키스특화】사에키 선배와 방과 후 키스 연습~겨울방학 첫 참배 데이트편~【역NTR】
소리
puella
05/16 17731 92
[요청복구] (RJ354108) 비타민퀘스트2 업스케일링 판
복구
sinbiru
05/16 26456 79
[손번][RJ01620541]이치카짱 간발의 차
번역
dmol2279
05/16 50944 203
명방엔필) 관리자 착유+촉수
영상
darkunicorn
05/16 37529 103
자작 MMD 공유
영상
pst0025
05/16 19851 95
블아) 노노미 수영복
영상
darkunicorn
05/16 20558 153
[손번역,노모작업] 감각 차단 암컷화 트랩!
번역
미스터장
05/16 60524 271
직번)son yohsyu)깨끗하고 올바르게, 성교중
동인
woo15
05/16 17289 63
[구매보급][한국어자막]변태인 새댁이 보○를 귀여움 받는 이야기[오호고에/정음 트름】
소리
이름뭐하지
05/16 14661 88
블아) 키쿄
영상
darkunicorn
05/16 21066 87
TXVqaXRhWA 영상 4k 모음
영상
karatro
05/16 19553 123
(고어, 료나) [요청복구] RJ01186269 Devastate
미번
ArIso
05/16 18620 39
[AI번역,이미지번역,미검수] RJ432297 크로네의 기분 v1.0.3
번역
qqoro
05/16 47735 154
청아) 프루네
영상
darkunicorn
05/16 21873 82
[5/15] 야고코로 에이린의 맨즈 클리닉
영상
브레머튼
05/16 23475 137
TjNCMWNIVT0= 영상 관련해서 일단 의도치 않은 분란 일으킨거에 대해 사과
일반
meruna00
05/16 6960 61
버튜버) 아마미야 코코로
영상
darkunicorn
05/16 26209 94
ㅇ1와라에 거물급 신인 등장
영상
strongman76
05/16 47515 211
[복구] RJ01540816 창해의 레이디 스파이 ver.1.0.0
복구
simsim22
05/16 22770 90
청?아 / 버튜버 / 이종간) 아르스X촉수
영상
darkunicorn
05/16 23017 66
[미번/번역요청]미용실 스텝 누나가 빼주는 이야기
동인
아돌
05/16 10009 20
[고전/모음집] almond collective 업스케일링
영상
미노타쿤
05/16 26322 247
청?아 / 블아) 아리스(임ㅅ전)
영상
darkunicorn
05/16 22877 104
[구매보급] [버전업] RJ01485652 종말의 얼터에고이즘 ver1.08+DLC 포함 ver2.01
미번
gkqisq
05/16 14247 83
청아) 오네쇼타 귀핥기+대딸 3인칭 / 1인칭
영상
darkunicorn
05/16 25611 88
(ai번역)Akagi asahito - 불량한 여친 시리즈 7편
동인
플르
05/16 13395 35