Last active
October 15, 2023 15:33
-
-
Save pida42/43a304ba7b944a5c0abf8169cfe4096f to your computer and use it in GitHub Desktop.
Tampermonkey: YouTube Script auto Adds skip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @id youtube-auto-adds-skip@pida42 | |
// @name YouTube Script auto Adds skip | |
// @description Automatically trigger click event on "Skip add" button. | |
// @namespace https://gist.github.com/pida42/43a304ba7b944a5c0abf8169cfe4096f | |
// @version 1.0.1 | |
// @author pida42 | |
// @include https://www.youtube.com/* | |
// @match https://www.youtube.com/* | |
// @require https://code.jquery.com/jquery-2.1.4.min.js | |
// @grant GM_addStyle | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
(function(jQuery) { | |
'use strict'; | |
var waitForElement = { | |
_i: null, | |
_c: 0, | |
_m: 3600, | |
wait: function(elementSelector, callback) { | |
if(null !== waitForElement._i) return false; | |
callback = callback || function(){}; | |
clearInterval(waitForElement._i); | |
waitForElement._i = null; | |
waitForElement._i = window.setInterval(function() { | |
waitForElement._c = waitForElement._c + 1; | |
var waitElement = jQuery(elementSelector); | |
if(document.location.pathname == '/watch' && waitElement.length) { | |
console.log('element exist'); | |
clearInterval(waitForElement._i); | |
waitForElement._i = null; | |
callback(waitElement); | |
} | |
if(waitForElement._c >= waitForElement._m) { | |
console.log('element DOESN\'T exist'); | |
clearInterval(waitForElement._i); | |
waitForElement._i = null; | |
callback(null); | |
return false; | |
} | |
}, 1000); | |
} | |
}; | |
var skipAdd = function() { | |
waitForElement.wait('.ytp-ad-skip-button', function(targetElement) { | |
if(typeof targetElement[0] !== 'undefined') { | |
jQuery(targetElement[0]).click(); | |
} | |
skipAdd(); | |
}); | |
}; | |
skipAdd(); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment