kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2817 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
Kiosk 암호 자동 입력기 2.0
유틸
oroshinashi9
03/26 5195 32
[의상 파일 공유][비밀 노출 -배덕의 달콤함에 물든 마나카-] 데빌
유틸
akuma
03/26 12064 19
[요청복구] Prison Hero 감옥용사 조이플 구동패치
유틸
감비아
03/22 2784 3
Tsukuru Extractor에서 추출한 .txt 파일 재미나이2.5 flash로 번역하는 파이썬 코드
유틸
lovesccubus
03/21 2789 3
mp3,wav 여러 파일 한개로 병합해주는 프로그램 만듬
유틸
noname
03/21 11652 20
fapcraft (제니모드) v1.1
유틸
monolithliza
03/20 10185 48
하츠네 미쿠 (코이카츠) 프리셋 공유 v2
유틸
pst0025
03/19 19974 36
키오스크 비번 자동입력기(업그레이드)
유틸
oroshinashi9
03/19 5984 13
(코이카츠) 셀레스포니아 캐릭터 공유 (우리가 아는 그 게임 맞음)
유틸
pst0025
03/18 19730 38
(코이카츠) Vrchat 캐릭터 공유
유틸
pst0025
03/17 10621 42
트랜스크랩 1.0.5 패치에서 오류나는 사람들은 이거 다운받으셈.
유틸
liberty
03/17 13789 25
악!! 저는 파일 올릴 때 최신화 체크도 안하는 병신입니다!!
유틸
pst0025
03/16 6732 28
블아 캐릭터 공유 빠진거 3개
유틸
pst0025
03/16 10345 38
(코이카츠) 벽람 캐릭터 공유 [이것도 많다....]
유틸
pst0025
03/16 11802 43
(코이카츠) 블아 캐릭터 공유 [아무튼 ㅈㄴ 많음]
유틸
pst0025
03/16 12953 75
(코이카츠) 명조 캐릭터 공유
유틸
pst0025
03/16 19576 54
(코이카츠) '데어라' 프리셋 공유
유틸
pst0025
03/16 9212 45
던전 앤 브라이드 치트모드 1.56업데이트 + 번역모드 대응버전 출시 *04/04 18:31 수정
유틸
rengester
03/13 17621 37
아이폰) 아이폰 렌파이 자동 번역기 1티어 나옴
유틸
quilqiil132
03/12 4811 6
유니티 플러그인 만들어옴(받침유무에 따른 조사 수정)
유틸
neighborsbear
03/11 5567 14
아이폰 필독)아이폰용 무료 렌파이 자동 번역기앱 나옴
유틸
quilqiil132
03/10 5454 5
JSON AI 번역기 (마나카 커스텀미션 및 etc..)
유틸
bunta_expert
03/10 6553 20
MV 백로그 플러그인) Lunatlazur_BackLog.js
유틸
ㅇㅇ
03/09 7463 5
아리아 서큐즘 노모 텍스쳐 대체 방식
유틸
paleblood
03/09 7005 13
[노모패치] 324709 노엘 간바리마스! v.1.2.2
유틸
dd
03/07 12920 33
Darkest Dungeon NSFW 십덕 스킨모드
유틸
hibeast
03/07 13789 14
▼ 素材(Materials) ## VX Ace to MV Converter.rb
유틸
ㅇㅇ
03/06 10203 4
야식메뉴판 Plus 업뎃 안내 - 1.2.1
유틸
qqoro
03/06 16356 38
여동생 생활 판타지 DLC 2.0.1 치트에디터(파이썬)
유틸
jghkk9
03/05 5146 7
코이카츠 프리셋 공유
유틸
wonder11
03/04 9791 34