kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
3018 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
神の血:TheBloodofYidhra 발매 예고 개시
정보
도라야키
05/06 7099 20
AI, 블루아카, 청아) 키보토스의 무력
야짤
xepd5264
05/06 8125 19
[미번][구매보급][번역요청]NTR MOBILE v.0.23.0
미번
졸라급한마음
05/06 9882 23
(코이카츠) 명조 신캐 둘 프리셋
유틸
pst0025
05/06 6462 37
[복구] 레바테인 복구 영상
영상
브레머튼
05/06 14217 62
[구매보급]노예 소녀 티티와의 달콤한 공의존-노예 소녀를 잔뜩 응석받이로 만드는~
소리
이름뭐하지
05/06 8920 55
청아, AI번역) [직번] 요도확장 조교기록 (OKINA)
동인
rapbit
05/06 19499 41
(AI 이미지 번역 파일만)[RJ01482469] 최면 어플 NTR
번역
gyhaga
05/06 43414 143
[구매보급] [Pigtarotaro] [보이스판] 레이짱은 바람기 노출에 푹 빠진 것 같습니다 ⑤
영상
ikinokoru
05/06 31460 163
[후타주의] 클로린드 & 나비아 & 아이테르 (원신)
영상
브레머튼
05/06 16911 57
[55%] 완전자동 기계훈련 시리즈
영상
신군
05/06 24470 113
[yukimi] 이치하 5
동인
agnet666
05/06 17299 59
[구매보급/미번/촉수/이종간] 星守のレイン
미번
루파조아
05/06 13383 30
[구매보급] [버전업] RJ01548918 포스트 블러섬 -꽃이 피는 라이히와 사랑의 여제- 26.05.06 ver 1.3.0
미번
gkqisq
05/06 6806 35
구매보급) 여동생의 친구가 동경하던 G컵 갸루 코스플레이어였던 이야기
동인
GOOD
05/06 27329 177
버) RVNWaWRlb01ha2Vy 2024~2025
영상
qnpfrzlt2
05/06 31252 89
ṣ̌øłą [01~76] [96.6GB]
영상
2wjjs
05/06 28584 91
[복구] 복구 영상 4개
영상
브레머튼
05/06 19855 79
[구매보급, 미번] 하늘을 나는 하렘성의 비밀
미번
saika
05/06 8681 42
히토미펌) 19애니들 모음집
영상
yuoaijs
05/06 27157 62
이종간) 패배 강간 당하는 시리
야짤
177523
05/06 11693 24
[Misaki (Nagenyankotsu)] 제자 오나홀
동인
sgdvl
05/06 56493 423
상극의 알테르 예고 공개
정보
nyamberry
05/06 6104 19
Poriuretan 딸의 교복을 입고 외출했다가 동창에게 들킨 유부녀
동인
uzaki
05/06 22345 89
Poriuretan 비내리는 버스 정류장
동인
uzaki
05/06 12290 39
Poriuretan 유두 맞히기 게임
동인
uzaki
05/06 20679 83
(요청복구, 구버전) 서큐버스 듀얼 サキュバスデュエル
복구
werwerwer
05/06 19316 47
Poriuretan 권유
동인
uzaki
05/06 9353 35
Poriuretan 이웃집 유부녀
동인
uzaki
05/06 11131 54
Poriuretan 스트리머
동인
uzaki
05/06 10284 31