kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2988 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
후원보급,Br@n)서큐버스들 시리즈 + 통합편집
영상
비밀봉투
05/08 21849 105
[1편+2편][구매보급]오호호호! 리 아가씨! 시리즈(미슐랭 3스타 레스토랑 뺨치는 오호성)
소리
이름뭐하지
05/08 13468 60
요 근래 눈팅만 했는데 할말이 있슮
일반
브라자
05/08 8656 50
시니시스타2 안대 금발녀 모드 1.2.1 ver
유틸
cascastu
05/08 14502 37
90일, 2.42 GB, 복구) SEQUEL b, a, c, k, t
미번
ㅇㅇ
05/08 7090 31
[구매보급]RJ01118993 せんせーしっかく!w
미번
nonononononono
05/08 27672 67
12년의 족쇄
동인
아즈칼
05/08 28178 137
(미번) 후배 여자친구와 문란한 나날들
동인
아즈칼
05/08 16445 47
[구매보급] [자막] 2개
소리
puella
05/08 14105 82
[기번][미검수]RJ01617050 성녀 리나리아의 낙엽~침취음문해주담~
번역
Treants
05/08 78567 282
90일) 5. RJ329602 SEQUEL kludge v1.10 [kor] 개선 26.05.09.1.7z
복구
ㅇㅇ
05/08 25064 63
후원보급,Br@n)용사파티 시리즈 + 통합편집
영상
비밀봉투
05/08 31585 161
[구매보급] RJ01619395 ○リっ子健康診断2!
미번
cookieasy
05/08 11682 46
[미번/번역요청][Zuuga] 큰 가슴의 수녀가 너무 약해ㅋ~ 교회를 지키고 싶은 청초하고 경건한 금발 수녀, 저항해도 헛되이 쾌락에 빠져들다 ❤~
동인
majomesubuta
05/08 23066 78
기대하는 응석받이와 그림체비슷한 "여름마녀 ~ 두마녀와의 시골생활" 스팀진출 + 공식한글지원 소식
정보
kkkkkk0909
05/08 17478 39
[복구] 우리아이 판타지아 ver.0.61.0 구판 + 따로 패스파일 0 ~ 4을 뽑아놨음
복구
몬스터가아니다신이다
05/08 25016 43
[직번] [anabuki bouhatei] 발기부전 밖에 태어나지 않는 섬에서 유일한 절륜2
동인
maha1004
05/08 38787 217
AI, 셀레스포니아) 아마네의 남자화장실 침입
야짤
miso5
05/08 23478 166
[미번][구매보급] 라이브2D로 움직이는 이솝우화
미번
zombidoll
05/08 13894 47
[플래시] 몰랐어!동생의 비밀을 밝혀낸다!
영상
zombidoll
05/08 24422 121
수간) 카스둥이의 은밀한 취미
야짤
idjsio864
05/08 13429 56
[영상][구매보급]지〇니아 육상부 미사키와 에리의 오나서포
영상
zombidoll
05/08 16780 84
[미번][구매보급] ロゼリアム 로제리움
미번
zombidoll
05/08 16255 25
요즘 많이 덥대
야짤
zerocoke
05/08 14584 43
[요청복구] [오호고에, 트름 등등] 우라사카 히쿠메 팬박스 음성 모음
소리
acefs
05/08 13677 72
몬스터 블랙마켓
복구
grim3404
05/08 26507 55
[QHD 96f] 자양화 질 무렵에
영상
Shinjiro
05/08 30465 116
[기번/검수][suzunomoku]-인식 개변에 당해도 필살기(클리자위)로 토벌(절정)할 뿐입니다!!
동인
serdic
05/08 23574 141
[AI번역][미검수]Bones' Tales: The Manor 0.31.4 (오류 수정1)
번역
솔라셀
05/08 41779 103
mmd 자작영상 공유
영상
pst0025
05/08 12539 81