kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2914 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
[수정1] 대리업로드 번역게임 14개
번역
미스터장
04/27 97086 388
[AKIRE][컬러/노모] 나만의 응석을 받아주는 거유JK아내를 다른남자에게 안기게 해봤다 3
동인
프로베스트캣
04/27 22088 87
성지식 없어서 무신경하게 섹스해주는거 꼴리는
야짤
superkiller123
04/27 23601 97
[시모바시라 공방] 「마장영희 셀레녹시아」 제작 보고 69 - 서브 이벤트 다듬기!
정보
날개 로봇
04/27 19442 44
[구매보급][청아] 마마루미기획 작품 4개
영상
mantoo12
04/27 37573 96
ai, 이터널 리턴) 수영복 데비와 순애 섹스
야짤
kjh9304
04/27 17292 76
[미번] 내 여자친구가 지배 어플로 NTR 방송되고 있는데
미번
미스터장
04/27 10012 40
[미번] 다락방의 에로 낙원(에덴) ~귀여운 제자에게 첫 암컷 수업~
미번
미스터장
04/27 8770 29
Poriuretan 매칭
동인
uzaki
04/27 17003 56
Poriuretan 노출증 환자
동인
uzaki
04/27 17459 52
Poriuretan 동네누나
동인
uzaki
04/27 17267 31
Poriuretan 등산 캠핑에서 의기투합
동인
uzaki
04/27 10845 30
Poriuretan 너무 오래 기다리게한 소꿉친구
동인
uzaki
04/27 17323 33
Poriuretan 전직 야리사쿠(성인 동아리) 출신 유부녀
동인
uzaki
04/27 17299 42
Poriuretan 넷카페
동인
uzaki
04/27 31206 52
Poriuretan (본인은) 넘어가지 않았다고 생각하는 아이
동인
uzaki
04/27 24377 46
Poriuretan 가출과 무녀
동인
uzaki
04/27 15524 37
Poriuretan 흑백 갸루의 메리 크리스마스
동인
uzaki
04/27 21105 63
(청아) アブジャン 팬박스 26년 영상
영상
교미의요정
04/27 43776 136
내 근육 돌려줘!!
후기 및 공략
키리히토
04/27 11089 30
(ios 사용자 전용) 핸디맨 판타지 ipa
hornyhorse
04/27 28753 27
(이미지 번역 파일만/이미지 통합본) [RJ01414102] おかしな刑務所と淫欲の地下迷宮 (이상한 형무소와 음욕의 지하 미궁)
번역
5dk2io1
04/27 92425 540
생화학적 제한구역 전개방 세이브
세이브
thomastrain
04/27 14672 16
[gemma4][미검수][패치만]서큐버스들의 밤 ~음마간, 혹은 서큐버스와 인큐버스에 대하여~
번역
lovesccubus
04/27 40053 87
[구매보급,번역요청,청아]챔버 게임, 오빠 전용 딜리버리 J◯ plus
미번
12532748912
04/27 24712 31
bHVjaWZpbmEwMDZhMQ== 모음 한달
야짤
raime
04/27 11509 31
[구매보급,번역요청] RJ01613299 음주도시 휴프노즘? (기번이라 제목 맞나 모르겠음...)
미번
gkawkek23
04/27 19569 99
[한글자막] 산타 코스프레 타카기 양과 극혐남의 메모리
영상
실루엣21
04/27 31524 142
콜레다 & 와이즈 (ZZZ)
영상
브레머튼
04/27 17240 79
MZ MV data 복호화 실행기
유틸
미요포
04/27 13665 38