kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2917 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
takeyuu 부잣집 갸루가 내 이성을 파괴해서 질싸 시키기까지
동인
SK
05/14 46853 224
[요청복구] 크로네의 기분 - 별 내리는 마을의 마녀 견습
복구
ulul2684
05/14 34233 38
[요청복구] RJ356209 청아) 동물 귀☆트레이닝 ~광폭한 동물귀 아가씨 조교 트라이얼~ ver.1.0.10
복구
Ghost
05/14 27708 33
TU1EdHlwZTg3 모음집 업데이트 알림
영상
hannanas
05/14 21490 37
커오메 회사 신작 커스텀 로맨스 시티 8월 28일 발매 예정
정보
돔마
05/14 15893 24
[구매보급][번역요청] RJ01627306 よこしま修行村 요코시마 수행마을
미번
cjweoic214
05/14 21347 66
eGlhbmd3ZWl0dWRvdQ 23년 모음
영상
karatro
05/14 24718 93
(코이카츠) 학원마스 프리셋 공유
유틸
pst0025
05/14 15666 43
[벽람항로] 다이호 (기본 + 누드)
영상
브레머튼
05/14 26724 122
[AI 번역][Shiv] 내가 아는 학생 회장이 아니었다
동인
히알룩스
05/14 20665 48
(코이카츠) 프리셋 공유
유틸
pst0025
05/14 11568 58
[버전업][번역요청] No Tomorrow Rebellion 1.03
미번
마카라이트
05/14 15791 19
[보이스코믹][구매보급][한] 여자 사진부와 아저씨 지도원 2
소리
책먹는망아지
05/14 12276 83
eGlhbmd3ZWl0dWRvdQ 22년 모음
영상
karatro
05/14 21878 77
[후남,미번]후타나리 조카 리아라쨩
동인
jinys9810
05/14 13519 17
AI) 무표정쨩 레이프
야짤
miso5
05/14 14460 81
[이종간 / 청아] 6J6e6J+75LiK5qCh 작가 모음
영상
yozuna
05/14 34145 106
[고전/레이프/BDSM/group] pretty pridot 통합버전
영상
미노타쿤
05/14 28410 206
직번) ※취향주의 [John K. Pe-ta] 어떡해가 멈추질 않아 + 선생님 완전 쉽네♥
동인
qlalfsla
05/14 24912 58
eGlhbmd3ZWl0dWRvdQ 21년 모음
영상
karatro
05/14 27300 68
타락신관: 여동생과 악마의 혈통(+DLC) 세이브
세이브
NF레쉬
05/14 21219 47
Cyclone) 벌써 29도라니 더우니까 아이스께끼~
야짤
drogba
05/14 14975 31
[자체한글] 상식개변 시뮬레이터 -최○ 앱으로 좋아하는 그 아이와 연인이 되자 v1.016
번역
하우두유두
05/14 110871 340
[구매보급]모녀덮밥. 싱싱한 백보지 딸과 보지털 수북한 부인한테 내 마음대로 사정♪
소리
이름뭐하지
05/14 11591 66
힘과 쾌락의 융해
소리
grebiy
05/14 18639 54
은랑 LV.999 (스타레일)
영상
브레머튼
05/14 16440 105
(최신화) [미번] 밀옥 전편 v1.5 (26.04.25) >> godot엔진추정
미번
kkkkkk0909
05/14 18920 37
그레이스 (ZZZ)
영상
브레머튼
05/14 19014 103
[구매보급][번역요청] 뒤쪽의 흥신소
미번
minki
05/14 18018 20
ai, 원신) 만취한 시틀라리를 침실로 데려가 잔뜩 섹스했다
야짤
kjh9304
05/14 20410 115