Toggle Comments for Toki

토끼(마나,뉴,북) 댓글창 ON OFF 설정 버튼 추가

  1. // ==UserScript==
  2. // @name Toggle Comments for Toki
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 토끼(마나,뉴,북) 댓글창 ON OFF 설정 버튼 추가
  6. // @match *://*/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12. const url = window.location.hostname;
  13. const filePath = window.location.pathname;
  14.  
  15. if ((url.includes("newtoki")) || (url.includes("manatoki")) || (url.includes("booktoki"))) {
  16. // toon-nav 요소 찾기
  17. const toonNav = document.querySelector(".toon-nav");
  18.  
  19. if (toonNav) {
  20. // 댓글창 보이기/숨기기 버튼 생성
  21. const toggleCommentBtn = document.createElement("a");
  22. toggleCommentBtn.href = "#";
  23. toggleCommentBtn.id = "toggleCommentBtn";
  24. toggleCommentBtn.style.marginLeft = "10px"; // 간격 조정
  25.  
  26. // #viewcomment 요소 가져오기
  27. const commentSection = document.getElementById("viewcomment");
  28.  
  29. // localStorage에서 저장된 상태 불러오기
  30. const commentVisibility = localStorage.getItem("commentVisibility") || "show";
  31. if (commentSection) {
  32. if (commentVisibility === "hide") {
  33. commentSection.style.display = "none";
  34. toggleCommentBtn.textContent = "댓글창 보기";
  35. } else {
  36. commentSection.style.display = "block";
  37. toggleCommentBtn.textContent = "댓글창 숨기기";
  38. }
  39. }
  40.  
  41. // 버튼을 toon-nav 요소에 추가
  42. toonNav.appendChild(toggleCommentBtn);
  43.  
  44. // 댓글창 토글 기능 추가
  45. toggleCommentBtn.addEventListener("click", function(event) {
  46. event.preventDefault(); // 링크 기본 동작 방지
  47.  
  48. if (commentSection) {
  49. // 보임 상태 토글
  50. if (commentSection.style.display === "none" || getComputedStyle(commentSection).display === "none") {
  51. commentSection.style.display = "block";
  52. toggleCommentBtn.textContent = "댓글창 숨기기"; // 버튼 텍스트 변경
  53. localStorage.setItem("commentVisibility", "show"); // 상태 저장
  54. } else {
  55. commentSection.style.display = "none";
  56. toggleCommentBtn.textContent = "댓글창 보기"; // 버튼 텍스트 변경
  57. localStorage.setItem("commentVisibility", "hide"); // 상태 저장
  58. }
  59. }
  60. });
  61. }
  62. }
  63. })();