기능 1: 코네 메인 페이지 설명 펼치기/접기 기능 ( 모바일에 있길래 PC에서도 동작하게 수정)
기능2: 댓글창 좌클릭 잠금 버튼
댓글창에서 복사하거나 드래그하려고할때 대댓글창으로 자꾸 넘어가서 추천/비추천 우측에 자물쇠 버튼이 개별적으로 적용되어
기본적으로는 클릭시에 대댓글이 열리지않음, 자물쇠를 풀면 좌클릭 한번에 대댓글이 열림
// ==UserScript==
// @name 코네 유틸
// @namespace http://tampermonkey.net/
// @version 1.1
// @description kone.gg 잠금버튼으로 답글 토글 (켜기/끄기): 기본적으로 댓글 클릭시 답글 안나오도록 & 메인페이지 토글 (접기/펼치기): 기본 접어두기
// @author cloud67p
// @match https://kone.gg/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
/***** [1] 댓글 관련 기능 *****/
/****댓글 요소(commentEl) 옆에 잠금/해제 버튼을 추가하는 함수****/
function addToggleButton(commentEl) {
// 이미 버튼이 붙어 있으면 중복 추가하지 않기
if (commentEl.querySelector('.reply-toggle-btn')) return;
const btn = document.createElement('button');
btn.textContent = '🔒';
btn.classList.add('reply-toggle-btn');
// 스타일 조정 (필요에 따라 위치/크기 바꿔도 무방)
btn.style.marginLeft = '8px';
btn.style.fontSize = '14px';
btn.style.cursor = 'pointer';
btn.style.background = 'transparent';
btn.style.border = 'none';
// 클릭 시 data-reply-enabled 토글 및 아이콘 변경
btn.addEventListener('click', function(e) {
e.stopPropagation();
e.preventDefault();
const enabled = commentEl.dataset.replyEnabled === 'true';
if (enabled) {
commentEl.dataset.replyEnabled = 'false';
btn.textContent = '🔒';
} else {
commentEl.dataset.replyEnabled = 'true';
btn.textContent = '🔓';
}
});
// 댓글 엘리먼트 마지막 자식으로 버튼 붙이기
commentEl.appendChild(btn);
}
function findReplyWrapper(commentEl) {
const parentContainer = commentEl.closest('div.relative.pl-4.py-1\\.5');
if (!parentContainer) {
return null;
}
const sibling = parentContainer.nextElementSibling;
if (!sibling) return null;
return sibling.querySelector('#comment_write') ? sibling : null;
}
/**
* 특정 댓글(commentEl)을 왼쪽 클릭했을 때,
* data-reply-enabled="true" 상태가 아니면 원래 동작(대댓글창 열기)을 차단합니다.
* 다만, 클릭된 요소가 버튼 또는 버튼 내부라면 차단하지 않습니다.
*/
function disableClick(commentEl) {
commentEl.addEventListener('click', function(e) {
// 잠금 상태일 때만 처리
if (commentEl.dataset.replyEnabled !== 'true') {
// 클릭된 요소가 button 태그이거나, button의 자손인 경우—버튼 클릭은 허용
if (e.target.closest('button')) {
return;
}
// 그 외(예: 댓글 텍스트 또는 빈 공간 클릭)는 차단
e.stopPropagation();
e.preventDefault();
}
});
}
/**
* 한 댓글(commentEl)에 대해:
* 1) 왼쪽 클릭 제한 (disableClick)
* 2) 우클릭(contextmenu) 시 data-reply-enabled 속성을 토글 (true ↔ false)
* 3) 댓글 옆에 잠금/해제 버튼 추가
* 4) 대댓글창의 “취소” 버튼을 눌러도 대댓글창이 닫히도록 연결
*/
function patchComment(commentEl) {
// 이미 처리된 댓글이면 패스
if (commentEl.dataset.replyPatched === 'true') {
return;
}
commentEl.dataset.replyPatched = 'true';
// 1) 왼쪽 클릭 제한
disableClick(commentEl);
// 2) 댓글 옆에 잠금/해제 버튼 추가
addToggleButton(commentEl);
// 3) 우클릭(contextmenu) 시 토글 로직 (기존에 있던 코드)
commentEl.addEventListener('contextmenu', function(e) {
e.preventDefault();
e.stopPropagation();
if (commentEl.dataset.replyEnabled === 'true') {
commentEl.dataset.replyEnabled = 'false';
} else {
commentEl.dataset.replyEnabled = 'true';
}
});
// 4) 대댓글창 “취소” 버튼 클릭 시 wrapper 닫기 (기존 코드)
const wrapper = findReplyWrapper(commentEl);
if (wrapper) {
Array.from(wrapper.querySelectorAll('button')).forEach(btn => {
if (btn.textContent.trim() === '취소') {
btn.addEventListener('click', function(ev) {
ev.stopPropagation();
ev.preventDefault();
wrapper.style.display = 'none';
});
}
});
}
}
/**
* 페이지 내 모든 댓글을 찾아 patchComment 실행
*/
function patchAllComments() {
document.querySelectorAll('.group\\/comment').forEach(patchComment);
}
/**
* 댓글이 동적으로 추가/삭제될 때마다 patchAllComments 재실행
*/
const observer = new MutationObserver(() => {
patchAllComments();
});
observer.observe(document.body, { childList: true, subtree: true });
// 초기 실행 (DOMContentLoaded 이후)
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', patchAllComments);
} else {
patchAllComments();
}
/***** [2] 환영 메시지 토글 복원 기능 *****/
const esc = cls => cls.replace(/:/g, '\\:');
function fixToggle() {
document.querySelectorAll(`.overflow-hidden.max-h-32.${esc('md:max-h-none')}`)
.forEach(el => el.classList.remove('md:max-h-none'));
document.querySelectorAll(`button.${esc('md:hidden')}`)
.forEach(btn => btn.classList.remove('md:hidden'));
}
fixToggle();
const toggleObserver = new MutationObserver(fixToggle);
toggleObserver.observe(document.documentElement, { childList: true, subtree: true });
})();
