강좌 / 팁

기 타 [팁] 유튜브 광고 차단

2023.12.03 20:59

천경지위 조회:7989 추천:28

 

Youtube 광고가 미쳤는지 좀 긴 영상보다보면 10분마다 한번씩 뜨는 경우가 있더군요.. 

30분에 한번씩 뜰때까지만 해도 그냥 광고 보이면 5초뒤에 건너띄기 눌러서 보고 그랬었는데 ... 

10분만다 뜨니 짜증이 나더군요...   어쩔수 없이 광고 건너띄는 방법을 찾아 봅니다. 

 

 

아래 소스를 즐겨찾기에 넣어두시고 유튜브 들어가서 한번씩 눌러주면 됩니다.   주소창에 복사해서 붙여넣고 맨앞에 javascript:를 넣은후 즐겨찾기로 끌어 오시면 즐겨찾기 추가한후 알아보기 쉽게 이름 바꿔주면 유튜브 접속후 해당 즐겨찾기를 한번 눌러주면 됩니다.      

혹은 유튜브 접속후 F12 눌러 콘솔탭에서 해당 소스를 붙여놓고 실행시키는 방법도 있습니다.

 

 

(function()

 {

    const adblocker = true;

    const removePopup = true;

    const debug = true;

 

    const domainsToRemove = [

        '*.youtube-nocookie.com/*'

    ];

    const jsonPathsToRemove = [

        'playerResponse.adPlacements',

        'playerResponse.playerAds',

        'adPlacements',

        'playerAds',

        'playerConfig',

        'auxiliaryUi.messageRenderers.enforcementMessageViewModel'

    ];

 

    const observerConfig = {

        childList: true,

        subtree: true

    };

 

    const keyEvent = new KeyboardEvent("keydown", {

      key: "k",

      code: "KeyK",

      keyCode: 75,

      which: 75,

      bubbles: true,

      cancelable: true,

      view: window

    });

 

    let mouseEvent = new MouseEvent("click", {

      bubbles: true,

      cancelable: true,

      view: window,

    });

 

    let unpausedAfterSkip = 0;

 

    if (debug) console.log("Remove Adblock Thing: Remove Adblock Thing: Script started");

    window.__ytplayer_adblockDetected = false;

 

    if(adblocker) addblocker();

    if(removePopup) popupRemover();

    if(removePopup) observer.observe(document.body, observerConfig);

 

    function popupRemover() {

        removeJsonPaths(domainsToRemove, jsonPathsToRemove);

        setInterval(() => {

 

            const fullScreenButton = document.querySelector(".ytp-fullscreen-button");

            const modalOverlay = document.querySelector("tp-yt-iron-overlay-backdrop");

            const popup = document.querySelector(".style-scope ytd-enforcement-message-view-model");

            const popupButton = document.getElementById("dismiss-button");

 

            const video1 = document.querySelector("#movie_player > video.html5-main-video");

            const video2 = document.querySelector("#movie_player > .html5-video-container > video");

 

            const bodyStyle = document.body.style;

 

            bodyStyle.setProperty('overflow-y', 'auto', 'important');

 

            if (modalOverlay) {

                modalOverlay.removeAttribute("opened");

                modalOverlay.remove();

            }

 

            if (popup) {

                if (debug) console.log("Remove Adblock Thing: Popup detected, removing...");

 

                if(popupButton) popupButton.click();

                popup.remove();

                unpausedAfterSkip = 2;

 

                fullScreenButton.dispatchEvent(mouseEvent);

              

                setTimeout(() => {

                  fullScreenButton.dispatchEvent(mouseEvent);

                }, 500);

 

                if (debug) console.log("Remove Adblock Thing: Popup removed");

            }

 

            if (!unpausedAfterSkip > 0) return;

 

            unPauseVideo(video1);

            unPauseVideo(video2);

 

        }, 1000);

    }

 

    function addblocker()

    {

        setInterval(() =>

                    {

            const skipBtn = document.querySelector('.videoAdUiSkipButton,.ytp-ad-skip-button');

            const ad = [...document.querySelectorAll('.ad-showing')][0];

            const sidAd = document.querySelector('ytd-action-companion-ad-renderer');

            const displayAd = document.querySelector('div#root.style-scope.ytd-display-ad-renderer.yt-simple-endpoint');

            const sparklesContainer = document.querySelector('div#sparkles-container.style-scope.ytd-promoted-sparkles-web-renderer');

            const mainContainer = document.querySelector('div#main-container.style-scope.ytd-promoted-video-renderer');

            const feedAd = document.querySelector('ytd-in-feed-ad-layout-renderer');

            const mastheadAd = document.querySelector('.ytd-video-masthead-ad-v3-renderer');

            const sponsor = document.querySelectorAll("div#player-ads.style-scope.ytd-watch-flexy, div#panels.style-scope.ytd-watch-flexy");

            const nonVid = document.querySelector(".ytp-ad-skip-button-modern");

 

            if (ad)

            {

                const video = document.querySelector('video');

                video.playbackRate = 10;

                video.volume = 0;

                video.currentTime = video.duration;

                skipBtn?.click();

            }

 

            sidAd?.remove();

            displayAd?.remove();

            sparklesContainer?.remove();

            mainContainer?.remove();

            feedAd?.remove();

            mastheadAd?.remove();

            sponsor?.forEach((element) => {

                 if (element.getAttribute("id") === "panels") {

                    element.childNodes?.forEach((childElement) => {

                      if (childElement.data.targetId && childElement.data.targetId !=="engagement-panel-macro-markers-description-chapters")

                            childElement.remove();

                          });

                       } else {

                           element.remove();

                       }

             });

            nonVid?.click();

        }, 50)

    }

 

    function unPauseVideo(video)

    {

        if (!video) return;

        if (video.paused) {

 

            document.dispatchEvent(keyEvent);

            unpausedAfterSkip = 0;

            if (debug) console.log("Remove Adblock Thing: Unpaused video using 'k' key");

        } else if (unpausedAfterSkip > 0) unpausedAfterSkip--;

    }

    function removeJsonPaths(domains, jsonPaths)

    {

        const currentDomain = window.location.hostname;

        if (!domains.includes(currentDomain)) return;

 

        jsonPaths.forEach(jsonPath => {

            const pathParts = jsonPath.split('.');

            let obj = window;

            let previousObj = null;

            let partToSetUndefined = null;

        

            for (const part of pathParts) {

                if (obj.hasOwnProperty(part)) {

                    previousObj = obj;

                    partToSetUndefined = part;

                    obj = obj[part];

                } else {

                    break;

                }

            }

        

            if (previousObj && partToSetUndefined !== null) {

                previousObj[partToSetUndefined] = undefined;

            }

        });

    }

 

    const observer = new MutationObserver(() =>

    {

        removeJsonPaths(domainsToRemove, jsonPathsToRemove);

    });

})();

 

 

위 소스는 해외유저가 github에 공개된 소스 입니다.

https://github.com/TheRealJoelmatic/RemoveAdblockThing/releases

 

매번 유튜브 들어가서 한번씩 눌러주는게 귀찮다면

Run Javascript 같은 별도의 확장 프로그램 이나 Tampermonkey 같은 확장프로그램을 이용하시는 방법도 있습니다.

 

번호 제목 글쓴이 조회 추천 등록일
[공지] 강좌 작성간 참고해주세요 gooddew - - -
4381 윈 도 우| VMware 윈도우10 RS4 Sysprep 통합윈도우 만들기 [33] 아차카차 7827 30 06-01
4380 소프트웨어| VMware workstation 사용법(본문 수정-2) [76] 고양이2 14927 30 11-14
4379 윈 도 우| 윈도우11&10 앱 제거 무인설치 [16] 무월 1713 29 03-22
4378 소프트웨어| pureBasic 소스 - 실행 목록 및 화면 캡처 v0.2 [7] 입니다 976 29 12-01
4377 윈 도 우| 윈도우 11 로컬 계정 암호 재설정 [15] 무월 1779 29 09-18
4376 소프트웨어| wim boot 관련 배치 파일 몇 가지 팁 [19] 지후빠 1465 29 08-03
4375 소프트웨어| 엑셀 제목표시줄에 파일 전체 경로 표시 [28] 지후빠 2679 29 04-02
4374 소프트웨어| Snapshot간이현지화 [업데이트10] [41] sunshine 3653 29 09-26
4373 소프트웨어| GPT 파티션 삭제 및 재구성 / EASEUS Partition Master 16 [9] 무월 1512 29 07-14
4372 소프트웨어| 간단한 크롬(Chrome) 팁 12개 정리 [15] 컴알못러 6687 29 01-28
4371 윈 도 우| 외장 SSD/HDD 에 멀티부팅 윈투고를 만들어 봅시다. [17] 디폴트 3985 29 10-20
4370 윈 도 우| PE 수정 스크립트 V3.21 [17] 히이이잌 3021 29 09-27
4369 윈 도 우| 나만의 복원 솔루션 만들기 -2부- (UEFI) [18] gooddew 4447 29 06-16
4368 윈 도 우| [UEFI] 부팅 PE 파티션 설치하기 [19] gooddew 6344 29 12-28
4367 윈 도 우| PESE로 기존 PE에 기능 추가하기(내용추가) [16] 히이이잌 2949 29 02-05
4366 윈 도 우| Win10 RS3 솔향PE USB 굽기와 UEFI 부팅하기 [33] 솔향 7165 29 01-02
4365 소프트웨어| DISM GUI 플래쉬 동영상 강좌... (통합,수정,편집 등...) [88] 아이언 17336 29 05-04
4364 기 타| 모든 영상을 순간으로 MP4 확장자로 변환. [18] 모네곰 2428 28 12-30
4363 윈 도 우| [2탄] install.wim 누적 업데이트 + 드라이버 통합 하기 (D... [9] 무월 1383 28 08-21
» 기 타| [팁] 유튜브 광고 차단 [14] 천경지위 7989 28 12-03
XE1.11.6 Layout1.4.8