* はじめに [#ycc15613]
Youtubeではなく、ここに書いてあるのはYoutubuという架空のサイトの話です。気にしないでください。
このページは、どなたでも編集することが可能です
* chromeの拡張機能 [#b719ea6a]
https://chromewebstore.google.com/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=ja
* スニペット集 [#w3f99894]
https://roshi.tv/blog/20220718-tampermonkey-javascript-snippets/
* 見やすくする参考スクリプト [#qcaa5575]
https://greasyfork.org/ja/scripts/by-site/youtube.com
* あれのコード [#naba10b9]
使用しないでね。と書いておく。
つかったことがないので、動くかどうかわかりません。と書いておく。
広告を見たい長さを調節。
```
// ==UserScript==
// @name YouTube Ad Auto-Skipper
// @namespace http://tampermonkey.net/
// @version 0.8
// @description Automatically clicks the skip ad button on YouTube
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function clickSkipButton() {
const skipButton = document.querySelector('.ytp-ad-skip-button');
if (skipButton) {
skipButton.click();
}
}
// 広告スキップボタンを探して1秒ごとにクリックを試みる
setInterval(clickSkipButton, 1000);
})();
```
** ver0.6 [#x601e682]
// ==UserScript==
// @name YouTube Ad Skipper with Player Z-Index Fix
// @namespace http://tampermonkey.net/
// @version 0.6
// @description Automatically skips YouTube ads, resumes playback, and fixes player z-index
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let skipAttempted = false;
function clickSkipButton() {
const skipButton = document.querySelector('.ytp-ad-skip-button') ||
document.querySelector('.ytp-skip-ad-button') ||
document.querySelector('button[class*="ytp-ad-skip-button"]') ||
document.querySelector('button[class*="ytp-skip-ad-button"]');
if (skipButton && !skipButton.disabled) {
console.log('Skip button found and clicked');
skipButton.click();
skipAttempted = true;
setTimeout(resumePlayback, 5000); // 5秒後に再生を再開
} else {
console.log('No skip button found or button is disabled');
}
}
function resumePlayback() {
if (skipAttempted) {
const video = document.querySelector('video');
if (video) {
console.log('Attempting to resume playback');
video.click();
video.play().catch(e => console.log('Failed to resume playback:', e));
document.querySelector('ytd-watch-flexy[player-unavailable] #player-container-outer.ytd-watch-flexy').style.visibility = 'visible';
bringPlayerToFront();
}
skipAttempted = false;
}
}
function bringPlayerToFront() {
const player = document.querySelector('.html5-video-player');
if (player) {
player.style.zIndex = '2147483647'; // 最大のz-index値
console.log('Player brought to front');
} else {
console.log('Player not found');
}
}
// 1秒ごとにチェック
setInterval(clickSkipButton, 1000);
observer.observe(document.body, { childList: true, subtree: true });
console.log('YouTube Ad Skipper with Player Z-Index Fix script is running');
})();
* ボタンID調査例:右クリック無効 [#l04b6205]
F12を押し、コンソールに以下を入力.
document.addEventListener('contextmenu',function(e){e.stopPropagation();},true);
* 例のあれを非表示に [#gce0b1f9]
document.getElementById('error-screen').style.display = 'none';
* あれを表示させる [#l70a7521]
document.querySelector('ytd-watch-flexy[player-unavailable] #player-container-outer.ytd-watch-flexy').style.visibility = 'visible';
* 再生停止を観測 [#dd1019d1]
function checkPlayerState() {
const player = document.getElementById('movie_player');
const isPlaying = player.classList.contains('playing-mode');
if (!isPlaying) {
const playButton = player.querySelector('.ytp-play-button');
if (playButton) {
playButton.click();
}
}
}
setInterval(checkPlayerState, 1000); // 1秒ごとに状態をチェック
* 既存のfunctionをオーバーライド [#h1d109ab]
// ==UserScript==
// @name Website Code Override
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Overrides specific code on a website
// @match https://example.com/*
// @grant unsafeWindow
// ==/UserScript==
(function() {
'use strict';
// 1. 既存の関数や変数の再定義
if (typeof unsafeWindow.existingFunction === 'function') {
unsafeWindow.existingFunction = function() {
console.log('This function has been overridden');
// 新しい実装をここに記述
};
}
// 2. スクリプトインジェクション
function injectScript(func) {
const script = document.createElement('script');
script.textContent = `(${func.toString()})();`;
document.body.appendChild(script);
document.body.removeChild(script);
}
injectScript(function() {
// このコンテキストはページのグローバルスコープで実行されます
// 例: 既存の関数をオーバーライド
if (typeof window.anotherExistingFunction === 'function') {
const original = window.anotherExistingFunction;
window.anotherExistingFunction = function() {
console.log('Function called with arguments:', arguments);
return original.apply(this, arguments);
};
}
// 例: 新しい関数や変数を定義
window.newFunction = function() {
console.log('This is a new function added to the page');
};
// 例: イベントリスナーの追加や変更
document.addEventListener('click', function(e) {
console.log('Document clicked at:', e.clientX, e.clientY);
});
});
console.log('Website Code Override script is running');
})();
** あれがでたら、リロード [#y0ee5910]
// ==UserScript==
// @name YouTube Error Screen Reloader
// @namespace http://tampermonkey.net/
// @version 1.0
// @description YouTube のエラー画面が表示された場合に自動でリロードします。
// @author Your Name
// @match *://*.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// エラー画面の要素を取得する
const errorScreen = document.getElementById('error-screen');
// エラー画面が表示されたら自動でリロードするイベントリスナーを追加する
errorScreen.addEventListener('DOMNodeInserted', function() {
// エラー画面が表示された場合に実行される
// 関数の説明: エラー画面が表示された場合、自動的にリロードを行うように設定する
function reloadAutomatically() {
// リロードを実行する
location.reload();
}
// 1秒後に自動リロードを実行する
setTimeout(reloadAutomatically, 1000);
console.log('エラー画面表示確認。自動でリロードします。');
// エラー画面が非表示になったらイベントリスナーを削除する
errorScreen.addEventListener('DOMNodeRemoved', function() {
// イベントの説明: エラー画面が削除された場合に実行される
console.log('エラー画面が非表示になりました。');
});
});
})();
** ver0.8 [#u270e512]
// ==UserScript==
// @name Auto Skip YouTube Ads
// @name:vi Tự Động Bỏ Qua Quảng Cáo YouTube
// @name:zh-CN 自动跳过 YouTube 广告
// @name:zh-TW 自動跳過 YouTube 廣告
// @name:ja YouTube 広告を自動スキップ
// @name:ko YouTube 광고 자동 건너뛰기
// @name:es Saltar Automáticamente Anuncios De YouTube
// @name:ru Автоматический Пропуск Рекламы На YouTube
// @name:id Lewati Otomatis Iklan YouTube
// @name:hi YouTube विज्ञापन स्वचालित रूप से छोड़ें
// @namespace https://github.com/tientq64/userscripts
// @version 4.3.5
// @description Automatically skip YouTube ads instantly. Remove the ad blocker warning pop-up. Very lightweight and efficient.
// @description:vi Tự động bỏ qua quảng cáo YouTube ngay lập tức. Loại bỏ cửa sổ bật lên cảnh báo trình chặn quảng cáo. Rất nhẹ và hiệu quả.
// @description:zh-CN 自动立即跳过 YouTube 广告。删除广告拦截器警告弹出窗口。非常轻量且高效。
// @description:zh-TW 立即自動跳過 YouTube 廣告。刪除廣告攔截器警告彈出視窗。非常輕巧且高效。
// @description:ja YouTube 広告を即座に自動的にスキップします。広告ブロッカーの警告ポップアップを削除します。非常に軽量で効率的です。
// @description:ko YouTube 광고를 즉시 자동으로 건너뜁니다. 광고 차단 경고 팝업을 제거하세요. 매우 가볍고 효율적입니다.
// @description:es Omita automáticamente los anuncios de YouTube al instante. Elimine la ventana emergente de advertencia del bloqueador de anuncios. Muy ligero y eficiente.
// @description:ru Автоматически пропускайте рекламу YouTube мгновенно. Удалите всплывающее окно с предупреждением о блокировке рекламы. Очень легкий и эффективный.
// @description:id Lewati iklan YouTube secara otomatis secara instan. Hapus pop-up peringatan pemblokir iklan. Sangat ringan dan efisien.
// @description:hi YouTube विज्ञापनों को तुरंत स्वचालित रूप से छोड़ें। विज्ञापन अवरोधक चेतावनी पॉप-अप को हटाएँ। बहुत हल्का और कुशल।
// @author tientq64
// @icon https://cdn-icons-png.flaticon.com/64/2504/2504965.png
// @match https://www.youtube.com
// @match https://www.youtube.com/*
// @grant none
// @license MIT
// @compatible firefox
// @compatible chrome
// @compatible opera
// @compatible safari
// @compatible edge
// @noframes
// @homepage https://github.com/tientq64/userscripts/tree/main/scripts/Auto-Skip-YouTube-Ads
// @downloadURL https://update.greasyfork.org/scripts/498197/Auto%20Skip%20YouTube%20Ads.user.js
// @updateURL https://update.greasyfork.org/scripts/498197/Auto%20Skip%20YouTube%20Ads.meta.js
// ==/UserScript==
function skipAd() {
video = document.querySelector('#movie_player video.html5-main-video')
const adPlayer = document.querySelector('#movie_player.ad-showing')
if (adPlayer) {
const skipButton = document.querySelector(`
.ytp-skip-ad-button,
.ytp-ad-skip-button,
.ytp-ad-skip-button-modern
`)
if (skipButton) {
skipButton.click()
} else if (video) {
video.currentTime = 9999
}
}
const adBlockerWarningDialog = document.querySelector('tp-yt-paper-dialog:has(#dismiss-button)')
if (adBlockerWarningDialog) {
adBlockerWarningDialog.remove()
}
const playButton = document.querySelector('button.ytp-play-button')
if (playButton) {
playButton.addEventListener('click', allowPauseVideo)
}
fineScrubbing = document.querySelector('.ytp-fine-scrubbing')
if (video) {
video.addEventListener('pause', handlePauseVideo)
video.addEventListener('mouseup', allowPauseVideo)
}
}
function allowPauseVideo() {
isAllowPauseVideo = true
window.clearTimeout(allowPauseVideoTimeoutId)
allowPauseVideoTimeoutId = window.setTimeout(disallowPauseVideo, 500)
}
function disallowPauseVideo() {
isAllowPauseVideo = false
window.clearTimeout(allowPauseVideoTimeoutId)
}
function handlePauseVideo() {
if (isAllowPauseVideo) {
disallowPauseVideo()
return
}
if (fineScrubbing?.checkVisibility()) return
if (video) {
if (video.duration - video.currentTime < 0.1) return
video.play()
}
}
function handleGlobalKeyDownKeyUp(event) {
if (document.activeElement?.matches('input, textarea, select')) return
if (event.type === 'keydown') {
if (event.code === 'KeyK') {
allowPauseVideo()
}
} else {
if (event.code === 'Space') {
allowPauseVideo()
}
}
}
let video = null
let fineScrubbing = null
let isAllowPauseVideo = false
let allowPauseVideoTimeoutId = 0
if (window.MutationObserver) {
const observer = new MutationObserver(skipAd)
observer.observe(document.body, {
attributes: true,
attributeFilter: ['class', 'src'],
childList: true,
subtree: true
})
} else {
window.setInterval(skipAd, 500)
}
skipAd()
window.addEventListener('keydown', handleGlobalKeyDownKeyUp)
window.addEventListener('keyup', handleGlobalKeyDownKeyUp)
const style = document.createElement('style')
style.textContent = `
#player-ads,
#masthead-ad,
#panels:has(ytd-ads-engagement-panel-content-renderer),
ytd-ad-slot-renderer,
ytd-rich-item-renderer:has(.ytd-ad-slot-renderer),
ytd-reel-video-renderer:has(.ytd-ad-slot-renderer),
tp-yt-paper-dialog:has(#dismiss-button) {
display: none !important;
}`
document.head.appendChild(style)
** よくわからない [#pa5e12cb]
これもよくわかりません、ネットから拾ってきました。つかったことないです。
// ==UserScript==
// @name B9DM広告改善
// @namespace http://tampermonkey.net/
// @version 0.2
// @description B9DMの動画ページの広告を改善・緩和
// @author You
// @match https://b9dm.in/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 広告要素を削除
const commonAdSelectors = [
'.adsbygoogle', // Google AdSense
'[id^="div-gpt-ad"]', // Google Ad Manager
'.ad', // 一般的な広告クラス
'.advertisement', // 一般的な広告クラス
'.banner', // バナー広告
'.pop-up', // ポップアップ広告
'.interstitial', // インタースティシャル広告
];
// ページ固有の広告セレクタ (必要に応じて追加)
const pageSpecificAdSelectors = [
// 例: '#sidebar .widget' // サイドバーのウィジェットを削除
];
const allAdSelectors = commonAdSelectors.concat(pageSpecificAdSelectors);
// 広告要素を削除
function removeAds() {
for (const selector of allAdSelectors) {
const adElements = document.querySelectorAll(selector);
for (const adElement of adElements) {
adElement.remove();
}
}
}
// 意図しないジャンプを防ぐ
function preventRedirects() {
const links = document.querySelectorAll('a');
for (const link of links) {
// target="_blank"属性を削除または_selfに変更
if (link.target === "_blank") {
link.target = "_self"; // 同じタブで開く
// link.removeAttribute("target"); // target属性を完全に削除
}
}
}
// ページ読み込み時に広告を削除
removeAds();
// DOMの変更を監視し、新しい広告が挿入されたら削除
const observer = new MutationObserver(removeAds);
observer.observe(document.body, { childList: true, subtree: true });
// 意図しないジャンプを防ぐ
preventRedirects();
})();