치지직 1080p 고정 + 광고 팝업 삭제 +치직치지직 광고 차단 로그 제거

치지직 1080p 고정 및 광고 팝업 삭제, 치직치지직 광고 차단 로그 제거 각 기능 별도로 실행 후 종료

  1. // ==UserScript==
  2. // @name 치지직 1080p 고정 + 광고 팝업 삭제 +치직치지직 광고 차단 로그 제거
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.4
  5. // @description 치지직 1080p 고정 및 광고 팝업 삭제, 치직치지직 광고 차단 로그 제거 각 기능 별도로 실행 후 종료
  6. // @match *://chzzk.naver.com/*
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. let previousChannelId = null;
  15. let scriptRunning = false;
  16.  
  17. // URL 변화를 감지하는 함수
  18. const detectChannelChange = () => {
  19. const currentUrl = window.location.href;
  20. const channelIdMatch = currentUrl.match(/live\/([a-f0-9]{32})/);
  21. const currentChannelId = channelIdMatch ? channelIdMatch[1] : null;
  22.  
  23. if (currentChannelId && currentChannelId !== previousChannelId) {
  24. previousChannelId = currentChannelId;
  25. if (!scriptRunning) {
  26. executeScripts();
  27. }
  28. }
  29. };
  30.  
  31. // 주기적으로 URL 변경 확인 (5000ms마다 확인)
  32. setInterval(detectChannelChange, 5000);
  33.  
  34. // 각 기능을 수행하는 스크립트 실행 함수
  35. function executeScripts() {
  36. scriptRunning = true;
  37.  
  38. // 랜덤 지연 시간 생성 함수 (500ms ~ 1500ms 사이 랜덤)
  39. function getRandomDelay() {
  40. return Math.floor(Math.random() * 1000) + 500;
  41. }
  42.  
  43. // 중복 실행 방지를 위한 플래그
  44. let qualitySet = false;
  45. let adRemoved = false;
  46.  
  47. // 모든 작업이 완료되었는지 확인하고 스크립트를 종료하는 함수
  48. function checkAndTerminate() {
  49. if (qualitySet && adRemoved) {
  50. scriptRunning = false;
  51. previousChannelId = null; // 이전 채널 ID 초기화하여 재실행 방지
  52. return true;
  53. }
  54. return false;
  55. }
  56.  
  57. // 품질 설정을 1080p로 고정하는 코드
  58. const qualityInterval = setInterval(() => {
  59. if (qualitySet) {
  60. clearInterval(qualityInterval); // 플래그가 true이면 인터벌 종료
  61. return;
  62. }
  63.  
  64. const qualityElement = document.querySelector(
  65. `.pzp-pc-setting-quality-pane__list-container > li:first-child:not(.pzp-pc-ui-setting-item--checked)`
  66. );
  67. if (qualityElement) {
  68. setTimeout(() => {
  69. qualityElement.click();
  70. qualitySet = true; // 작업 완료 플래그 설정
  71. clearInterval(qualityInterval);
  72. if (checkAndTerminate()) {
  73. return;
  74. }
  75. }, getRandomDelay());
  76. }
  77. }, 500);
  78.  
  79. // 광고 팝업 제거 코드
  80. const adInterval = setInterval(() => {
  81. if (adRemoved) {
  82. clearInterval(adInterval); // 플래그가 true이면 인터벌 종료
  83. return;
  84. }
  85.  
  86. const adbb = document.querySelector(`[class^="ad_block_title"]`);
  87. if (adbb) {
  88. setTimeout(() => {
  89. const closeButton = document.querySelector(`[class^=popup_cell] > button`);
  90. if (closeButton) {
  91. closeButton.click();
  92. adRemoved = true; // 작업 완료 플래그 설정
  93. clearInterval(adInterval); // 광고 팝업을 찾으면 인터벌을 종료하여 한 번만 실행
  94. if (checkAndTerminate()) {
  95. return;
  96. }
  97. }
  98. }, getRandomDelay());
  99. }
  100. }, 500);
  101.  
  102. // 광고 API 요청을 차단하는 코드 (에러 로그 방지)
  103. const originalFetch = window.fetch;
  104. window.fetch = function() {
  105. const url = arguments[0];
  106. if (typeof url === 'string' && url.includes('/ad-polling/')) {
  107. return new Promise((resolve, reject) => {
  108. resolve({ ok: false, status: 403 });
  109. });
  110. }
  111. return originalFetch.apply(this, arguments);
  112. };
  113.  
  114. // XMLHttpRequest 차단 (에러 로그 방지)
  115. const originalOpen = XMLHttpRequest.prototype.open;
  116. XMLHttpRequest.prototype.open = function(method, url) {
  117. if (url.includes('/ad-polling/')) {
  118. this.abort();
  119. return;
  120. }
  121. return originalOpen.apply(this, arguments);
  122. };
  123. }
  124.  
  125. // 처음 페이지 로드 시 스크립트 실행
  126. if (!scriptRunning) {
  127. executeScripts();
  128. }
  129. })();