kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2989 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
이세계 asmr 추천
질문
amaggoto2
05/24 1482 0
전에 했던 게임인데 제목이 생각이 안나서 도움좀
질문
h8124
05/24 1580 0
이 게임 제목 아시는 분?
질문
paragino
05/24 2355 0
아이패드 구동 질문
질문
missumac
05/24 1422 0
우메마로 신작 음폭사 짧은 후기
후기 및 공략
두파루파
05/24 5619 9
픽시브 곧 차단당하나
일반
ㅇㅇ
05/24 2289 -13
RJ01634901 [Umemaro3D] Taboo Spell 영상버전(추가)
영상
ckkey
05/24 41186 252
[복구요청]옛날에 괴롭히던 양키가 나의 마사지점에 왔다
요청
sdfsdafsadfs
05/24 2278 0
[구매보급/ AI 공식 번역] 빗소리로 가득 차는 밤 1.2.0
번역
yeondooooo
05/24 46496 276
[요청복구][RJ342578] (청아) Jam packed line tale
복구
roomonfire
05/24 12767 33
[자동번역](이미지 번역 필요) 야간 버스에서 여자아이의 팬티가 흠뻑 젖을 때까지 치○ 해버렸다
번역
제로콜라라이트
05/24 39901 148
(스포)유니슨코드는 분위기는 백합인데
후기 및 공략
paddackmon
05/24 3296 3
[복구요청] [렌파이, 손번역] NewHorizon-0.4-pc
요청
하네카와 하스미
05/24 2526 4
이거 어디서 본 초식인데...
야짤
루파조아
05/24 4830 7
의술사 퀘스트 빈 퀘스트 질문좀
질문
djrmfh202
05/24 1885 1
유니슨코드 스포작 할 생각에 막막하네
일반
ENE
05/24 1894 2
게임 추천좀
질문
mkasdo
05/24 1946 0
[복구][RJ119910] 로리퀘2 ~순백~ 4.01
복구
개구리
05/24 13159 36
[요청복구] Fantasy Factory 서클작 3개 복구
복구
갈랐다고
05/24 14612 39
교만아내 정도면 SSS급 더빙인가
일반
gimku1556
05/24 1576 0
[복구요청] RJ201837 알프스와 위험한 (KR, 노모)
요청
dosirack1
05/24 2932 0
이런스토리 게임 더 없나요?
질문
enrkenrken
05/24 1786 0
[복구요청] 레이디 나이트 ~음마의 미궁~복구요청합니다
요청
ㅎㅌ 조아
05/24 2660 1
RJ341616 The Fate of Choice v1.1a 번역 오류
피드백
dsfswee
05/24 3104 0
비월선행록 정기흡수
질문
생각하는고래
05/24 2078 0
[1편+2편][구매보급]넷카페에서 옆개인실의 여고생과 교미하는 이야기
소리
이름뭐하지
05/24 6853 61
[버전업][AI][패치만] 알미오시온의 의술사 ver 1.06
번역
lovesccubus
05/24 26811 157
비월선행록 토지신 공물 퀘 질문
질문
202603110929
05/24 2486 0
잘 만든 순애물의 단점
일반
paddackmon
05/24 1606 1
검은 묵시룩 2 후기 및 회상방 및 기타 등등
후기 및 공략
60348152
05/24 2299 5