kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2886 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
(구매보급/번역요청)RJ01585268,RJ01537879
미번
챔피얀
04/26 14260 35
Chloe & Iroha
영상
브레머튼
04/26 27338 138
[47.06GB] 또 야애니다수
영상
아소필
04/26 27630 161
린네아 (원신)
영상
브레머튼
04/26 22873 94
브로냐 S+
영상
브레머튼
04/26 23275 86
[구매보급]【전편 느릿 오호】 게이머 그라돌 자매와 집콕하며 야한 생활
소리
이름뭐하지
04/26 12177 68
[번역, 히토미펌] 아첼레란도 (seto yuuki)
동인
drogba
04/26 23032 46
[takku] [청아] U149 이치하라 니나 만화
동인
edo
04/26 29585 98
생각보다 쎈데?
야짤
highblue
04/26 11143 28
렌파이 게임을 추천해보도록 하겠습니다
후기 및 공략
shsh112211
04/26 10537 19
[미번/번역요청][Katsura airi]들끓던 무렵에 동창회편
동인
cuphead-7
04/26 25213 45
유니티/기번) Taffy Tales Season 1 - v1.1.55 Redux
번역
마기사
04/26 47389 187
[체험판][gemma4][미검수]서큐버스의 밤 체험판 28일 발매예정
번역
lovesccubus
04/26 33647 83
[미번/번역요청] My Girlfriend Advanced to the Dancer class and she buffs everybody 1.1r 버전 (수정)
미번
unknown1357
04/26 15804 70
(청아,AI,GIF) [xssxsxk] cure arcana shadow
야짤
ArIso
04/26 23433 108
청아,방뇨) セネト 신작 아이마스 아리스 모모코
영상
ㅇㅇ
04/26 21729 113
분명 애들 만화라고 들었는데
야짤
lovesccubus
04/26 13008 20
[직접구매] 나츠노 사가시모노 RJ370402
번역
jsoon
04/26 61127 296
[직번][Hino Yamada] 이사 성교!
동인
qlkjrnd
04/26 18794 88
니트사장 신작 포켓몬 봄이
영상
ㅇㅇ
04/26 24047 126
청아) はるとし 신작 메구밍
영상
ㅇㅇ
04/26 20135 98
[AI] 큐어 스카이 !!
야짤
kifbodo245
04/26 12459 38
Lapin Gris 신작
영상
ㅇㅇ
04/26 15657 103
오타쿠 여학생의 판타지
미번
흰꼴뚜기
04/26 15098 66
[Dokuneko Noil] 소라이 사키에게 나쁜 짓을 하는 이야기【전편】
동인
ㅇㅇ
04/26 25359 131
[AI번역] RJ01577093 ふたなって鬼ヶ島!
번역
하츠네미쿠
04/26 64104 214
[이미지번역만] 모두의 유방육성(육유) 아카데미[fanzagames_0158]
번역
buaak
04/26 35154 89
[요청복구] 누키타시 THE ANIMATION OVA 1~4편 한글자막o
영상
imakotou
04/26 23484 87
직번) 암컷펫 시리즈 총집편 3
동인
이게아닌데
04/26 40440 359
음모없음) [Gujira 4 Gou] 마구 빼달라고 하는 입원성활
동인
카오스
04/26 44307 336