kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2952 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
Poriuretan 동거 1개월
동인
uzaki
05/01 20873 75
Poriuretan 집에서 술마시며 보내는 크리스마스
동인
uzaki
05/01 19886 47
Poriuretan 갸루하고 엘리베이터에 갇혀버렸다
동인
uzaki
05/01 19692 40
Poriuretan 어느 p활 여자
동인
uzaki
05/01 13425 28
Poriuretan 보건실의 선생님
동인
uzaki
05/01 10434 35
Poriuretan 트릭 오어 트릿 2022
동인
uzaki
05/01 11321 52
Poriuretan 쿨한제자
동인
uzaki
05/01 16110 51
[ai번역] RJ01591409 구련휘정 퀄터 아르미네스 & 탄젤
번역
gre0204
05/01 54293 282
[구매보급]【한국어 자막판】 길 잃은 숲에서 폭유 엘프 자매에게 구조되었지만... 결국 잡아먹혔습니다♪
소리
이름뭐하지
05/01 11183 80
Poriuretan 네토라세 입문
동인
uzaki
05/01 12787 42
Poriuretan 제멋대로인 여자친구
동인
uzaki
05/01 10711 46
[요청복구]노예 공주 엘리자
복구
ㅇㅇ
05/01 31986 58
번역) [♀こみ] 마리 인생 종료 최면
동인
cyberse
05/01 19194 55
RJ01613299 번역하는 중
작업현황
norin021
05/01 8528 63
[재업][chalies] 이 자식이! (냥코대전쟁 동인지)
동인
ashgray
05/01 11953 46
구매보급) eGlhb2NodW4= 작가 유부녀섹스파티 1~17
영상
경계선상
05/01 30402 137
Napo 사랑의 랭크 매치
동인
SK
05/01 18198 94
카프카 & 히메코 & 은랑 '섹스 파티'
영상
브레머튼
05/01 16757 99
이젠 vpn 상시로 키는게 디폴트가 되겠네
일반
아나스타샤
05/01 9640 20
mmd 자작영상 공유 2
영상
pst0025
05/01 10622 53
[구매보급, 자체한글번역] 여우 마을의 수호전
번역
saika
05/01 63270 290
AI) 래빗홀 미쿠
야짤
miso5
05/01 10044 100
[Shirabe Shiki] 대음마전에 있어서 감각 차단 부적은 필수 대비책입니다 ① (캐릭터 디자인 변경)
동인
티모
05/01 33214 136
90일, 26.05.02, 1.11 GB) RJ01517134 3D Custom Okazu Maker mono Auto ko.7z
번역
ㅇㅇ
05/01 43472 122
[ai번역] RJ01591409 구련휘정 쿠르타 아르미네스 & 탄젤 EG (1.0.0d) v3(20260503)
번역
mowajelly
05/01 42117 246
[Liyoosa] 도련님께 음문이 새겨진 채 천천히 길들여지는 메이드
동인
요요코코
05/01 23570 136
[복구] pin-point사 작품 6개 ai 번역
복구
karatro
05/01 31081 83
90일) RJ01474906 Tentacle Game v.1.1 mono Auto ko.7z
번역
ㅇㅇ
05/01 33559 130
이와라 차단먹은김에 브픈서버 만들었다
일반
kiffufuf
05/01 8973 32
히카리나이토anomarin9 4월영상
영상
001245
05/01 22978 84