kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2899 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
젠존제) 엔젤디 4p
영상
darkunicorn
05/16 19835 109
[요청복구] [RJ01540816] 창해의 레이디 스파이 ver.1.0.0 (번역파일만)
번역
andal
05/16 43988 122
[요청복구] RJ231296 나이트테일 ナイトテール Kr v1.12
복구
stonerock
05/16 15180 38
블아) 미요 강제 + 순애
영상
darkunicorn
05/16 23399 100
[구매보급] RJ01601558(후타), RJ01581759, RJ01577122
소리
stitch
05/16 14023 70
Mankai Kaika 작품모음
동인
ㅇㅇ
05/16 23255 97
(요청복구) Futa Familly 0.245 번역
복구
Onko
05/16 25408 38
AI) 무표정쨩 갱뱅
야짤
miso5
05/16 17427 93
[요청복구]Evil Goddess Ver1.092 복구
복구
로켓드릴킥
05/16 23513 43
청아) 사죠 유키미
영상
darkunicorn
05/16 25651 102
[요청복구/스캇] 수상한 마사지 체험판 EX
복구
be정상인
05/16 24994 45
청?아) Hⓐreⓒhipⓟai 레나 2종류 + 코하루 2종류
영상
darkunicorn
05/16 22385 96
ai)스커크 선생님4 완전굴복 bbc주의
야짤
ezmood
05/16 8809 52
ai)원신 스커크선생님 참교육 3
야짤
ezmood
05/16 13438 41
후원보급,Br@n)서큐버스 하렘 + 통합편집
영상
비밀봉투
05/16 18271 82
[AI번역, 검수] 아득한 세레스피아 1.0.5
번역
제로콜라라이트
05/16 86029 357
인기 게임 스트리머의 성생활
동인
나나세마루
05/16 42777 247
AI역식, Mafuyu) 춘풍정 최음비화 3
동인
sexe1
05/16 15141 53
(청아, 노모, yukino minato)와라베 단지
동인
에우리알레
05/16 25503 94
[구매보급] [스캇물포함] 의붓어머니 대변 외3
소리
책먹는망아지
05/16 10511 46
[AI번역][VJ004665] Innocent Blue 이노센트 블루 (패치파일만)
번역
호빵할배
05/16 26889 67
hechima koubou 같은반 건방진 갸루는 처녀였습니다.
동인
SK
05/16 21562 91
Poriuretan 기생 고블린
동인
SK
05/16 31014 196
[미번 복구]RJ220960 네코로노미콘 복구
미번
printink
05/16 17784 25
[자체번역] 스칼렛 이스케이프 체험판 ScarletEscapeDemo_ver2
복구
송편
05/16 44212 174
[번역기+검수][urakan] 폭유엄마와 의붓아들들
동인
alen
05/16 13627 77
펌,RK-2] 의붓어머니의 장난감이 된 나
동인
kjalar
05/16 20465 52
던전 앤 브라이드v1.56 통합 모드v4.0 업뎃알림
번역
지나가던사람
05/16 32391 73
[Hoeeeng]그 날, 내 usb에 담긴 것은 - 1 중국어 원본+ ai번역
동인
qpsjcb10
05/16 24097 39
<링크 수정>[한글패치만] subverse 1.2.01
번역
mybest
05/16 37105 62