kone
소미소프트

소미소프트

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

05/27/2025, 09:41:09
유틸
2823 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
아 근데 지금 해보니까 게시판에 들어와서 새로고침을 한번 해줘야 버튼이 바뀝니다;; 참고해주세용
ㄴ수정했습니다 혹시 처음에 받으신 분 있으시면 다시 써주세용
RJ364579 이종 간 임신 실험 공주-침략 된 망국의 공주님의 잔인한 이야기
미번
monrang
05/25 12571 34
[Ojou] 침략계 여친 1, 2
동인
1uF
05/25 25220 151
[구매보급,번역요청,바킨툴] RJ01634909 NTR룸~구해내지 않으면 뺏기는 방~
미번
륄트
05/25 10805 38
[Seto Ryouko] 첫사랑
동인
1uF
05/25 14295 112
프로미아 & 와이즈 6단지 야외 플레이
영상
브레머튼
05/25 16156 89
(료나) 세이카&PA씨
동인
나나세마루
05/25 9203 31
마나카 모드 번역
번역
ㅇㅇ
05/25 26804 60
[구매보급] Umemaro3D 모음집
미번
cassett
05/25 10929 72
[직번] [Tanaka no Miso] 젖소를 기르는 방법 미나츠 완벽이해 총집편
동인
maha1004
05/25 12385 65
구매보급) 【한국어판】 아싸 주제에 젖꼭지 자극으로 절정하는 건 건방지잖아~!!
동인
GOOD
05/25 15419 69
청아) [ろるり] 조작당하는 아줌마 귀여워
동인
kbyxw79376
05/25 23975 82
젖통삽입 단짝친구
동인
pofox
05/25 21071 123
doji ro)처녀가 동정과의 첫 체험에서 눈을 뜨는 이야기 4
동인
woo15
05/25 9470 23
[구매보급]무지한 운동부 선배를 으스대며 조교해서 임신시킨 이야기
소리
이름뭐하지
05/25 5597 44
욕망의 여신 이리나 시작부터 쉽지 않네
후기 및 공략
마사지
05/25 8679 28
94. AI, 셀레스포니아, 식질) 셀레스포니아 인터뷰, 악수회
창작
miso5
05/25 7969 96
[ai번역][Usagi Nagomu] 황혼의 창 엘프 총집편 엠마편 1 [P.127]
동인
mybest
05/25 9966 57
(후타) 딸치다 걸린 미쿠
야짤
duckuu12
05/25 9777 26
노모 동인지나 상업지 구하는곳
정보
mybest
05/25 8823 40
내 비참한 인생 후기
후기 및 공략
15238603208
05/25 7354 34
AI번역 손식질) 직장근처에서 만난 알바(41)와 여행을 갔더니 애정어린 연인같은 섹스에서 성욕이 드러난 본능을 마음껏 이틀동안 폭풍섹스했던 이야기
동인
1Q2W3E4R
05/25 15401 95
[후타][퍼리][귀박주의] ear fuck 영상 모음
영상
roomonfire
05/25 20956 78
[요청복구] 렌파이 NewHorizon-0.4-pc
복구
65410
05/25 11517 47
직번) ※보추주의 [Brother Pierrot] 갸루 낭자애 수사관과 자지 쥠초밥
동인
qlalfsla
05/25 14896 39
여름 전에 나오는 갓겜
정보
aemeath
05/25 10183 52
[미번/이종간/촉수] 태양의 기사 에리카 0.1.9.1 핫픽스버전 (치트판)
미번
루파조아
05/25 13757 71
mmd - 비스크돌 코스프레 실루엣 야스댄스 - Thumbs Up
영상
madrush
05/25 32134 260
[요청 복구]For the queen
복구
오우즉시반말
05/25 20724 64
[요청복구] 장탈기사 님포리아 v1.07
복구
zadvoskoi
05/25 12017 33
35살 처녀 마법사 속편근황
정보
sorbe123
05/25 6273 16