YouTube ๊ด‘๊ณ , ๋ฉˆ์ถฐ!! ๐Ÿ–๐Ÿป

trevor.phยท2021๋…„ 6์›” 9์ผ
7

์˜์‹์˜ํ๋ฆ„๋Œ€๋กœ

๋ชฉ๋ก ๋ณด๊ธฐ
1/4
post-thumbnail

[0] TL;DR

setInterval ์„ ํ†ตํ•ด "Skip ad" ๋ฒ„ํŠผ์„ ๊ฐ•์ œ๋กœ triggerํ•˜๋Š”ย chrome extension ๊ฐœ๋ฐœ

[1] ๋„์ž… ๊ณ„๊ธฐ

youtube ๊ด‘๊ณ  ์ถœํ˜„ ๋นˆ๋„๊ฐ€ ๋†’์•„์ง€๊ณ , ๊ด‘๊ณ  ํ•˜๋‚˜๋‹น ์‹ค์งˆ์ ์œผ๋กœ 5์ดˆ ์ด์ƒ์˜ ์‹œ๊ฐ„์ด ์†Œ์š”

[2]ย Chrome Extension - getting started

chrome extension์€ ์—ฌ๋Ÿฌ component๋กœ ๊ตฌ์„ฑ(html, css, js)

  • background scripts
  • content scripts
  • options page
  • UI elements
  • chrome API

manifest.json

Extensions tab ์—์„œ ๊ด€๋ฆฌ ๊ฐ€๋Šฅ

content script

web page(youtube.com)์˜ context ์—์„œ ๋™์ž‘ํ•˜๋Š” script. manifest.json์— ์„ ์–ธ๋œ jsํŒŒ์ผ์„ ์ ์ ˆํ•œ ํƒ€์ด๋ฐ์— ์‹คํ–‰ํ•œ๋‹ค.ย 

์—ฌ๊ธฐ์„œ ๋ญ”๊ฐ€ ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋‹ค. ad skip์— ํ•„์š”ํ•œ ๋กœ์ง ์ž‘์„ฑ ์˜ˆ์ •

[3]ย ๊ตฌํ˜„

Main idea

"Skip ad" ๋ฒ„ํŠผ์„ content script๋ฅผ ํ†ตํ•ด ๊ฐ•์ œ๋กœ ํด๋ฆญ ํ•ด๋ณด์ž
๋ฒ„ํŠผ์ด ๋ณด์ด์ง€ ์•Š์•„๋„ css hidden์ฒ˜๋ฆฌ๋งŒ ๋˜์–ด์žˆ์„ ๋ฟ์ด์ง€ ํด๋ฆญ๊ฐ€๋Šฅํ•˜๋ฉฐ, ๊ด‘๊ณ  skip์ด ๋™์ž‘ํ•œ๋‹ค

Codeย 

skip ๋ฒ„ํŠผ์˜ DOM์„ querySelector๋กœ ์žก์•„ ์ผ์ • ์ฃผ๊ธฐ๋กœย skipButton.click() ํ˜ธ์ถœ

const skipBtnSelector = "div.ytp-ad-text.ytp-ad-skip-button-text"
const trigger = () => {
  const skipBtn = document.querySelector(skipBtnSelector);
  if (!skipBtn) return; // Not advertising now
  skipBtn.click();
  console.log("๋‹น์‹ ์˜ 5์ดˆ ์ ˆ์•ฝ๋˜์—ˆ๋‹ค");
}
setInterval(trigger, 1000);

์ตœ์ข… ๊ตฌํ˜„๋œ ์ฝ”๋“œ๋Š” ๋งํฌ ์ฐธ๊ณ 

์ค‘์•™ ํ•˜๋‹จ์— ๋œจ๋Š” ํŒ์—… ๋ฐฐ๋„ˆ

display: none ์ฒ˜๋ฆฌ

div#player-ads,
div.video-ads.ytp-ad-module,
div.ytp-ad-overlay-slot {
    display: none !important;
}

[4] ์ƒ๊ฐํ•ด ๋ณผ ๊ฑฐ๋ฆฌ

Result

  • 5์ดˆํ›„ skip ๋ฒ„ํŠผ์ด ๋œจ๋Š” ๊ด‘๊ณ  โœ…
  • ๋ฌด์กฐ๊ฑด ๋ณผ์ˆ˜๋ฐ–์— ์—†๋Š” 5์ดˆ์งœ๋ฆฌ ๊ด‘๊ณ  โ˜‘๏ธ
  • 10๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ ๋œจ๋Š” ๊ด‘๊ณ (๊ธด ์˜์ƒ) โ˜‘๏ธ
  • ๋™์˜์ƒ ์‹œ์ฒญ ์ค‘์— ํ•˜๋‹จ์— ๋œจ๋Š” ํŒ์—… โœ…
  • iframe ์— embeded๋œ youtube pageย โ˜‘๏ธ

TODO๋ฅผ ๋‹ค์„ฏ๊ฐ€์ง€ ์ •๋„๋กœ ์ •๋ฆฌํ•ด๋ณด์•˜๋Š”๋ฐ ์•„์ง ์•ˆ ๋˜๋Š” ์ผ€์ด์Šค๊ฐ€ ์žˆ๋‹ค.

๋‹ค๋ฅธ extension ์€ ์–ด๋–ป๊ฒŒ ํ•˜๋Š”์ง€

๋Œ€๊ฐœ skip ad ๋ฒ„ํŠผ์„ triggerํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋Š” ๋“ฏ. DOM์— "skip ad"๋ฒ„ํŠผ์ด ์žˆ๋Š”์ง€ ๊ฐ์ง€ํ•˜๋Š” ๊ธฐ๋ฒ•์ด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์žˆ๋Š”๋ฐ

1) setInterval & querySelector
2) mutationObesrver
3) onPageChanged API (extension์—์„œ ์ œ๊ณตํ•˜๋Š” page๋ณ€๊ฒฝ)
4) DOMSubtreeModified (deprecated)
(์ฐธ์กฐ ๋งํฌ)

https://github.com/squgeim/yt-ad-autoskipper/blob/master/skipad.js
https://github.com/pasupulaphani/adblock-youtube/blob/master/app/scripts/contentscript.js
https://github.com/nirojsapkota/youtube-skip-add/blob/master/skip.js

๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€ ์—†๋Š”์ง€

skip ad trigger ๋ง๊ณ  ๊ด‘๊ณ ๋ฅผ ๋„˜๊ธฐ๋Š” ํ•จ์ˆ˜๋ฅผ debugger๋ฅผ ํ†ตํ•ด ์ฐพ์•„ ์ง์ ‘ ํ˜ธ์ถœ

P.S.

๊ด‘๊ณ ๊ฐ€ ์–ธ์ œ ๋œฐ์ง€ ๋ชฐ๋ผ์„œ skip ๊ธฐ๋Šฅ ํ™•์ธ ํž˜๋“ฌ(์ƒ๊ฐ๋ณด๋‹ค ๊ด‘๊ณ ๊ฐ€ ์ž˜ ์•ˆ๋œฌ๋‹ค)

YouTube premium๐Ÿฅณ

profile
It's just a shot away

0๊ฐœ์˜ ๋Œ“๊ธ€