kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2913 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
엽빛나 [ZZZ] (기본 + 후타)
영상
브레머튼
04/27 23530 95
시시아 & 와이즈 (ZZZ)
영상
브레머튼
04/27 22667 102
[P and I] 장난으로 수영복 수치 노출 -반 친구들에게 보여진 가슴- + IF 스토리
동인
ed123
04/27 27709 64
[야애니] 누퀴톼쉬 스페셜 1-4
영상
공승아
04/26 47183 260
[요청복구] Glory & Miserable Survivors DX
복구
stir-friedturnip
04/26 22972 53
미번) 교배 라이센스 ~ 비치헌팅으로 마구 섹스 편 ~
동인
kjalar
04/26 25420 44
(アブジャン)산타코스 타카기 양과 씹덕남의 메모리
영상
greenwow
04/26 25767 118
[고전 명작]나와 그녀와 그녀의 사랑
복구
blackmalangcalf
04/26 21858 62
(요청복구) RJ140344 아카쿠비 투기장
복구
Ghost
04/26 21300 43
[sugiyuu] 암컷타락 누나. 늘 나를 지켜주던 여장부 같던 누나는 오늘도 선배의 품에 안겨 여자가 된다
동인
asawqs11
04/26 25648 75
AI, 블아) 수영복 이즈나랑 해변
야짤
miso5
04/26 13824 46
[한글패치]이상한 형무소와 음욕의 지하 미궁 ~빈틈투성이인 나나의 H한 프리즌 브레이크~_1.1.0
번역
아르
04/26 90278 371
걸레인 미카 씨는 만지게 해주지 않아.
소리
dasdaa
04/26 17656 60
후기) 내 근육 돌려줘!
후기 및 공략
parmisgood
04/26 12112 43
RJ01557970 너스콜 경비원(자택경비원3) 세이브파일
세이브
ersya
04/26 19688 18
[Isenori] 음침한 여동생을 『교육』해서 쾌락 중독의 육변기로 만든다 28
동인
요요코코
04/26 20068 52
[🔞체험판 공개! 체험판 한국어 패치 파일] 대 꽃 필 무렵에 체험판
번역
폭8맛
04/26 80647 169
[미번] 미번 일겜 73개 + 미번 양겜 14개
미번
미스터장
04/26 62356 272
AI, 셀레스포니아) 벽 엉덩이, 그 후
야짤
miso5
04/26 11230 114
이미지 잘못 드래그해서 바이러스 대처 방안 2800자 날라감 장문
정보
laat2
04/26 12790 74
[번역/저퀄] [kawase seiki] Underworld Lover
동인
cjd08
04/26 20190 41
[요청복구] RJ01361520 Trial of lust 번역 파일
복구
도로롱
04/26 24075 58
신학 & 감우 'DON'T GIVE UP' 4K
영상
브레머튼
04/26 28133 154
미끼 치한 수사관 리나 유저 모드 업데이트
정보
happy123
04/26 13613 35
본디지 게임 & 본디지 게임 DVG
미번
argoklarke
04/26 10444 45
[구매보급]암컷 타락 합숙【전편 느릿오호】
소리
이름뭐하지
04/26 17099 69
[구매보급/최면 영상] RJ405819 더블 서큐버스 마인드 해킹 라이브
영상
summer4552
04/26 24055 83
[야애니/알림] 음오옥 똰지 2화 업 알림
영상
공승아
04/26 21749 59
RJ01406729 퇴마사 시즈나 (게임+회상방 개방)
세이브
gnown
04/26 12676 19
루콜라 (포켓몬 챔피언스)
영상
브레머튼
04/26 32885 214