kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2883 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
MMD 모션,음악 통팩 공유
유틸
pst0025
04/26 9175 56
미번,구매보급) 러브러브에치시뮬레이션(live 2d)
미번
lalolo
04/26 11318 32
AI, 셀레스포니아) 가짜에게 지고 벽엉덩이
야짤
miso5
04/26 15181 156
[AI번역][미검수] RJ01045491 [happypink] 최면의 공주기사 ver1.092
번역
coupon
04/26 52362 174
[업데이트 안내] 간호사 콜 경비원 +DLC1 v1.26.4.24 (자칭 : 자택경비원3)
번역
kkkkkk0909
04/26 42966 171
[Nunnu] Funny Fuck! | 퍼니 퍽!
동인
kifbodo245
04/26 15670 57
(청아 NTR 후타 등) 오오랜만에 다시 들고 와쓰
영상
bisesdop
04/26 36076 180
[업데이트 안내] 존재감 없는 여동생과의 소박한 일상 1.08rev.3
번역
kkkkkk0909
04/26 38591 118
[Togami] 분홍빛 여우 색기의 술! ~무참히 패배한 암여우의 임신 묘상화~
동인
ashgray
04/26 23570 117
[미번,구매보급] RJ01605204 ゆりかごのプエルステラ
미번
sfman6348
04/26 17714 34
RJ01412500 NightHigh5 mono Auto ko.7z
번역
ㅇㅇ
04/26 29685 98
6Zu25pum6JOd6Z+z 작가 영상 2개
영상
asd0222
04/26 14644 57
[Almondman] 마마 선생님들과 러브러브 놀이 시간
동인
멜신
04/26 32442 247
[구매보급]【패배메스타락특화】복수의 쿠노이치 아야메 굴욕의 패배 절정
소리
이름뭐하지
04/26 12445 72
[AI번역]음모일기 8+ 순애편
동인
mobilejoara
04/26 23197 36
[harusawa] 나를 좋아하는 문학여친이 NTR 섹파에게 범해져 타락하기까지
동인
agnet666
04/26 22539 35
[수정1][AI번역][미검수] RJ437935 성활 Hotel v1.0.3
번역
ㅇㅇ
04/25 43504 151
(노모화) [Shiwasu No Okina] 100번 차여버린 인기없는 나를 불쌍히 여겨준 남친 있는 여자사람 친구가...
동인
xbox
04/25 51722 289
Poriuretan 산악 드라이브에서 의기투합
동인
uzaki
04/25 23937 64
Poriuretan 친구네 누나
동인
uzaki
04/25 35402 91
Poriuretan 보란듯이 보여줌
동인
uzaki
04/25 24516 62
Poriuretan 노출증 환자의 할로윈
동인
uzaki
04/25 15601 45
Poriuretan 냄새 페티시
동인
uzaki
04/25 16310 39
돌보기 좋아하는 엄마, 아들한테 박혀버리다
동인
haroishi
04/25 25118 63
Poriuretan 들이닥친 갸루 a (무삭제 판)
동인
uzaki
04/25 25820 52
Poriuretan 아이의 씨를 원하는 유부녀
동인
uzaki
04/25 18505 35
Poriuretan 선배의 선택
동인
uzaki
04/25 17682 37
Poriuretan 보이시한 소꿉친구
동인
uzaki
04/25 20805 28
Poriuretan 세련된 선도부원
동인
uzaki
04/25 18122 34
Poriuretan 유부녀 요가 피트니스 (무삭제판)
동인
uzaki
04/25 21354 35