kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2800 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
[업뎃] base64 자동복호화. 글제목(작가 이름)도 지원. CJK문자 지원
유틸
arcjay
05/29/25 5957 14
update0529_ DL + STEAM (태그|평점|이미지) 미리보기 크롬 확장.
유틸
ddegul
05/29/25 4214 11
개념글/전체글 버튼 분리 스크립트(수정)
유틸
딸기맛농축함유🍓
05/27/25 2800 3
전체글 버튼을 만들어주세요
유틸
글쓴이
05/27/25 3237 6
[업뎃] Auto 소미 XSS보안 업데이트
유틸
김머시기
05/27/25 11283 52
후타)후타나리들과 뷰릇뷰릇 착정던전 노모패치
유틸
레가토
05/26/25 5539 5
코네 미리보기 / 갤러리 뷰
유틸
mowajelly
05/25/25 8539 23
[업뎃] 자동 복호화/DL미리보기/자동국룰/자동다운 통합 스크립트 Auto 소미
유틸
김머시기
05/24/25 17472 44
20250527update_ STEAM, DL 이미지+태그(tag) 미리보기 크롬확장
유틸
ddegul
05/24/25 4013 9
Starbound 통팩 V0.2 (Sexbound, 스타바운드)
유틸
파에톤1호팬
05/24/25 5635 12
다키스트 던전 Lustiest Lair 1.6 메가-커스텀 팩
유틸
파에톤1호팬
05/24/25 10455 15
base64 자동복호화 (자동/수동모드 전환 가능)
유틸
arcjay
05/24/25 18872 79
Lossless Scaling 오리 꿱꿱
유틸
otona
05/24/25 4160 9
루나트랜스 ai번역 프롬프트 (탈옥+번역개선)_06.10업뎃
유틸
GOLAL
05/23/25 10068 16
링크 프리뷰 내맘대로 업데이트
유틸
cloud67p
05/23/25 2526 3
업데이트!) Base64 변환기 2.0 [확장 프로그램]
유틸
꼬께
05/23/25 8957 42
Base64 변환기 [확장 프로그램]
유틸
꼬께
05/23/25 6253 4
자동 국룰입력/복호화/다운로드 확장프로그램 스크립_귀인 분 코드 긴급 패치_이거 말고 원본 쓰쎔
유틸
noname911
05/22/25 13043 16
kone 이미지 일괄 다운로드
유틸
글쓴이
05/21/25 17503 37
이미지 뷰어(좀 더 편하게 볼 수 있는 그거) - 유기
유틸
noname911
05/20/25 7102 13
후타)착정생물에게 절대 패배하지 않는 거근거유 후타나리 메스가키 노모패치 v2
유틸
레가토
05/20/25 9057 14
ExFa viewer
유틸
글쓴이
05/19/25 4679 7
단축키 -펑-
유틸
유령
05/19/25 3910 11
썸네일 미리보기 다크모드, 댓글창 개선 스크립트
유틸
김머시기
05/18/25 16280 32
자동 국룰입력/복호화/다운로드 확장프로그램 스크립트
유틸
김머시기
05/18/25 61732 174
[유틸/수정1] 히토미 다운로더 스크립트 with 코네
유틸
kts
05/17/25 13062 30