Skip to content

Instantly share code, notes, and snippets.

@bamchoh
Last active February 12, 2024 15:26
Show Gist options
  • Save bamchoh/8a063cf7fff6e07c406dccfbe0ecaf85 to your computer and use it in GitHub Desktop.
Save bamchoh/8a063cf7fff6e07c406dccfbe0ecaf85 to your computer and use it in GitHub Desktop.
Youtube Ad Blocker

インストールの方法

適当なフォルダを作成し content.js, manifest.json を配置

chrome://extensions/ にアクセスし、「パッケージ化されていない拡張機能を読み込む」をクリックし、作成したフォルダを選択すると完了。

拡張を作るのに参考にしたサイト

const host_url = location.host;
if (host_url === "www.youtube.com") {
setInterval(function () {
//バナー広告の閉じるボタン取得
let element = document.querySelector(
"div.ytp-ad-overlay-close-container > button"
);
if (element) {
//閉じるボタンが取得できたのでクリック
element.click();
console.log("ad closed");
return;
}
//動画広告のスキップボタン取得
element = document.querySelector(".ytp-ad-skip-button");
if (element) {
//スキップボタンが取得できたのでクリック
element.click();
console.log("ad skiped");
return;
}
//動画広告のスキップボタン取得
element = document.querySelector(".ytp-ad-skip-button-modern");
if (element) {
//スキップボタンが取得できたのでクリック
element.click();
console.log("ad skiped");
return;
}
element = document.querySelector("span.ytp-ad-preview-container");
if (element) {
console.log("動画はまもなく再生されます", element);
const videoElement = document.querySelector("video");
if (videoElement) {
console.log("videoElement.playbackRate", videoElement.playbackRate);
videoElement.playbackRate = 16;
console.log("videoElement.playbackRate", videoElement.playbackRate);
}
return;
}
}, 1000);
}
{
"name": "Sample",
"version": "1.0.0",
"manifest_version": 3,
"description": "Sample Chrome Extension",
"content_scripts": [
{
"matches": ["https://*/*"],
"js": ["content.js"]
}
],
"permissions": ["activeTab"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment