kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2861 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
[5/16] 스파키 (스타레일)
영상
브레머튼
05/21 17122 89
ai, 명조) 방순이에게 청혼하고 잔뜩 아기 만들기 섹스했다
야짤
kjh9304
05/21 10458 105
[구매보급]【한국어 자막판】 【4시간 × 더블 여검사 × 더블 하렘】 ~오네쇼타 길드~ 신참 모험가인 나와 엄청 야한 폭유 여검사 누님×2 와 아이 만들기 임신 젖가슴 퀘스트♪(RJ01457321)
소리
Mecklen
05/21 17247 338
ai) 사이좋은 부녀
야짤
메르헨소행성
05/21 10924 27
학원 생활 노출 RPG NAKED HIGHSCHOOL 세이브
세이브
ENE
05/21 7108 16
ai bbc 붕스)카스토리스 ntr 3
야짤
ezmood
05/21 8972 33
ai 붕스)카스토리스 ntr 2.5
야짤
ezmood
05/21 5415 27
[미번/번역요청][Ame arare] 도서실의 그녀 번외편
동인
yurisia
05/21 12786 15
[미번] 01202319 아타타케 공방 코야의 미련 해소 일기 ~도스케베 유령 여자에게는 생하메치〇포가 효과가 있다!~
영상
ctf5r4edfyfdr4r4
05/20 20490 146
익핸 딸깍 번역 방법
정보
알라라크
05/20 10707 27
(청아) [misao.] 색깔한가득
동인
memimemem
05/20 20648 63
[미번] 01521467 Nebula 【Live2D×ASMR】관능미 넘치는 요염한 서큐버스가 선사하는, 머릿속이 녹아내리는 최상의 자위 지원 중독성 있는 마약♡
영상
ctf5r4edfyfdr4r4
05/20 27007 157
장문)진짜 누가 이런 카지노 NTR 야겜 좀 안 만들어주나....
야짤
stealthmania
05/20 9400 35
[요청복구] RJ01180321 네네는 노출욕구가있다
복구
haust0005
05/20 20383 59
[미번/구매보급/번역요청] VJ004257 俺は彼女を信じてる! 나는 그녀를 믿고있다
미번
silver
05/20 8923 45
(NTR/NTL)수줍은 음침한 여자 두 명을 "여자인 친구"로 만들어서 편리한 꽁냥꽁냥한 생활을 보냈더니, 진짜 인싸에게 전부 빼앗겼다.
소리
키리안
05/20 12578 85
(청아)(번역) RJ141187 상복 로리타 구속 기담 미소녀 노예 조교 나이무검열판
번역
ilillilllilil
05/20 66828 495
로스트미디어 단간론파
영상
opqo34
05/20 25897 130
ai) ----청아---- 놀이수영장?
야짤
Ghost
05/20 9792 36
맛있는게임 2개 소개함
정보
칸코
05/20 10194 45
따끈따끈한 타케다 신규 낙서장 (나데시코)
동인
riden
05/20 26790 48
ai) 큰 가슴 사이로 총알이 쓩~~
야짤
Ghost
05/20 10169 37
ai) MMM 모음집
야짤
Ghost
05/20 9627 21
[[요청복구]] [RJ340568] 상태이상 1 〜음문 금서 기생충편〜
복구
에로스테는 필수 스테는 선택
05/20 19251 122
ai) ----스압-----아이마스 계열...?
야짤
Ghost
05/20 5351 19
Yutsuki Tsuzuri-쓰레기 현자 이야기 2
동인
k8625
05/20 20992 41
Eco Heeky-엉덩이로 여자를 구분할 수 있는 내가 여상사의 약점을 잡았다 1
동인
k8625
05/20 29556 189
Eco Heeky-엉덩이로 여자를 구분할 수 있는 내가 여상사의 약점을 잡았다 2
동인
k8625
05/20 37733 284
[직번] [kuroinu] 악몽의 학원 생활 위원장의 운명
동인
maha1004
05/20 20810 76
[손번역][2차번역본] RJ01526327 어서오세요! 어린이 만들기 온천 마을 1.01
번역
sjdwj
05/20 55097 271