kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2918 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
고전 명작 도트 액션 야'겜' 3개( 쿠로바디스, 에로이코, 리지넷타)
복구
blackmalangcalf
04/28 57732 133
[구매보급/최면음성] 거짓말쟁이 후배 좋아하는 정신 지배
소리
rocoa
04/28 14393 52
[요청복구] よっぷ 서클 3종 복구
복구
rubberduck
04/28 40973 111
[AI번역] [JUNN] 네토라레바에 - 인싸 여친의 SNS 네토라레 기록 3
동인
gkcuwuwlltnnrra
04/28 28373 96
[구매보급] 【상식 개변】황국의 공주의 의식을 재기록 성 처리 봉사를 매너라고 생각해
소리
rocoa
04/28 9777 73
[미번/번역요청] 화내지마 호시카와상 3
동인
downdodo779
04/28 22344 30
[liyoosa]싫은 표정으로 성처리를 해주는 간호사
동인
요요코코
04/28 29771 177
[구매보급] [최면음성] 이키닌교
소리
rocoa
04/28 9807 34
90일) RJ01278453 Exhibitionist Observer mono Auto ko.7z
번역
ㅇㅇ
04/28 45621 106
[구매보급] [칭 호칭 15 종류】 네쵸리 손음부 ~다우너 미소녀의 간편 「비큐」시코시코 서포트♡
소리
rocoa
04/28 12187 65
[요청복구]복구 4종
복구
dmol2279
04/28 37945 69
(노모화) [miyamoto muga] 전 양아치 아내, 네토라레 당한다 2
동인
kason
04/28 19794 71
티나2 진척 12
정보
마검사리네최고
04/28 8386 36
AI/청아) 임산부 스웨터 2
야짤
날개 로봇
04/28 11457 24
양겜 기번] Whispers of the Dark Elf
번역
도로롱
04/28 34279 136
[미번역] [번역요청]착정의 섬 1.08a(완성판),AI,인외,쇼타,혐오)
미번
stmo12
04/28 14362 25
AI) 편의점에서 계산하는 무표정쨩
야짤
miso5
04/28 16443 68
[보이스코믹][구매보급][한] 마미의 덫
소리
책먹는망아지
04/28 24562 101
[noripachi] 비용을 잔뜩 버는 방법
동인
agnet666
04/28 29837 77
[기계번역] My Girlfriend Advanced to the Dancer class and she buffs everybody v1.1r 완결 (번역파일만)
번역
karuparu13
04/28 34402 129
(AI)renbocloud patreon 전체 모음 4월 최신화
야짤
RMillet
04/28 14328 53
4월 30일 횡스크롤 오네쇼타 역간겜 발매애앳!!!
정보
ballddagu
04/28 13588 36
(미번/번역요청/히토미펌)[Neko Samurai] 僕らの女神さまは…2
동인
Ghost
04/28 19428 49
[구매보급/번역요청] RJ01527385 伯爵屋敷の事件簿 -交錯する二つの思惑-
미번
rubberduck
04/28 23501 136
[P and I] 수치스러운 모델 촬영 -카메라 앞에서 드러난 거유- + After 스토리
동인
ed123
04/28 24538 61
[복구] 란스03 노모패치
유틸
imakotou
04/28 16047 28
AI, 셀레스포니아) 잠자는 아마네에게 몰래
야짤
miso5
04/28 13595 94
[구매보급 기번] RJ01319586 소악마 스마트폰 (수정중)
번역
toung
04/28 81062 267
[료나, 고문, 스캇, 청아 ... ] [ EX12 ] [미번] 게임 모음
미번
셧다운
04/28 14533 31
블아) [zmix] 그런 거나 이런 것도 내 뜻대로!
동인
agnet666
04/28 24021 55