Greasy Fork is available in English.
Bypass all youtube ads including in video ads, skippable and non-skippable Ads
当前为
// ==UserScript==
// @name Youtube Ad Cleaner(Include Non-Skippable Ads- works)
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
// @namespace http://tampermonkey.net/
// @version 1.27
// @description Bypass all youtube ads including in video ads, skippable and non-skippable Ads
// @author BjDanny
// @match https://www.youtube.com/*
// ==/UserScript==
// The script runs in the backgound, monitoring all youtube ads.
// When non-skipable ads are found, the script will redirect the browser to previous page and then revisits the current URL.
// Depends on the amount of non-skipable ads, the browser may refresh couple times automatically.
//What's new in version 1.26:
//Fixed window refreshing loops.
var checkTimers;
var videoOnPauseState;
var atHome;
setInterval(killAd, 4000);
setInterval(isAtHome, 4000);
checker();
function videoOnPause(){
var pauseOrNot;
$(document).ready(function(){ pauseOrNot =document.querySelector('.ytp-play-button.ytp-button').getAttribute('title');});
atHome = isAtHome(); //must include this statement, otherwise the return result will be wrong
if (pauseOrNot == "Play (k)" && atHome === false ){
return true ;
}
else {
return false;
}
}
function isAtHome(){
if(window.location.href == 'https://www.youtube.com/'){
return true;
}
else{
return false;
}
}
function checker(){
setInterval(mainTimer, 1000);
setInterval(directSkipAd, 2000);
// setInterval(logMsg, 1000);
}
function logMsg(){
atHome = isAtHome(); //must include this statement, otherwise the return result will be wrong
checkTimers = mainTimer(); //must include this statement,otherwise the return result will be wrong
// console.log('Main timers running is ' + checkTimers);
// console.log('video paused is ' + videoOnPauseState);
// console.log('At Home page is ' + atHome);
// console.log('Current Url is ' + window.location.href);
if (checkTimers === false){
console.log('3 timers are stopped');
}
else{
console.log('All timers are running');
}}
function mainTimer(){
var timer1 = setInterval(KillNoSkipAd, 1000);
var timer2 = setInterval(killInVideoAd, 1000);
var timer3 = setInterval(chkCfmBtn, 1000);
videoOnPauseState = videoOnPause(); //must include this statement, otherwise the return result will be wrong
atHome = isAtHome(); //must include this statement, otherwise the return result will be wrong
if(atHome === true || videoOnPauseState ===true) {
clearInterval(timer1);
clearInterval(timer2);
clearInterval(timer3);
return false;
}
else{
return true;
}
}
function killAd(){
if ($(".videoAdUiRedesign")[0] !==undefined){
$(".video-stream").attr("src", "");
}
$("#player-ads").remove();
$("#masthead-ad").remove();
$("#offer-module").remove();
$(".video-ads").remove();
$("#pyv-watch-related-dest-url").remove();
}
function chkCfmBtn(){
try{
if (document.querySelector('.style-scope.yt-button-renderer.style-blue-text.size-default').textContent ==='Yes') {
document.querySelector('.style-scope.yt-button-renderer.style-blue-text.size-default').click();}
}catch(err){
return;
}
if($('#toast')){$('#toast').remove();}
}
function KillNoSkipAd(){
atHome = isAtHome(); //must include this statement, otherwise the return result will be wrong
var ytplayer = document.getElementById("movie_player");
var adChannelName = $('.ytp-title-channel-name')[0].text;
var VTime = Math.round(ytplayer.getCurrentTime());
var VideoURL = ytplayer.getVideoUrl();
if(!atHome){
if ($('.ad-showing') [0] !== undefined || adChannelName !==""){
ytplayer.cancelPlayback();
setTimeout(ytplayer.playVideo(), 2000);
// window.location = VideoURL;
}
}
}
function killInVideoAd(){
if ($(".video-ads")[0] !== undefined){
console.log('An in-video ad was removed');
$(".video-ads").remove();
}
}
function directSkipAd(){
if( document.querySelector('.ytp-ad-text.ytp-ad-skip-button-text') !== null ){
document.querySelector('.ytp-ad-text.ytp-ad-skip-button-text').click();
}
}