Last active
December 5, 2024 02:58
-
-
Save nuts-n-bits/e4f75ade0755070003ebccc0fdca40e1 to your computer and use it in GitHub Desktop.
ytp-skip-ad.js
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== | |
// @name New Userscript | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://www.youtube.com/* | |
// @icon https://www.google.com/s2/favicons?domain=youtube.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function skipAd() { | |
const htmlElements = document.getElementsByClassName("ytp-ad-skip-button") | |
if (htmlElements[0] === undefined) { return } | |
const buttons = [...htmlElements] | |
buttons.map(button => { | |
button.click() | |
console.log("clicked ad skip button for ya") | |
}) | |
} | |
let current_url = "" | |
function autoHD() { | |
const condition_0 = current_url !== location.href && location.href.indexOf("watch?v=") > 0 | |
const condition_1 = condition_0 && document.querySelector(".ytp-popup.ytp-settings-menu") | |
const condition_2 = condition_1 && condition_1.computedStyleMap().get("display").value === "none" | |
const condition_3 = condition_2 && [...document.getElementsByClassName("ytp-ad-skip-button")].length === 0 | |
const condition_4 = condition_3 && window.scrollY < 50 | |
const condition_5 = condition_4 && document.querySelector(".ytp-gradient-bottom") | |
const condition_6 = condition_5 && document.querySelector("#search").hasFocus === false | |
if(condition_6) { | |
current_url = location.href | |
console.log(`auto HD upgrade for video ${current_url} has been scheduled`) | |
setTimeout(makeHD, 5000) | |
} | |
} | |
function makeHD() { | |
try { | |
const save_style_display = document.querySelector(".ytp-gradient-bottom").style.display | |
document.querySelector(".ytp-gradient-bottom").style.display = "none" | |
document.querySelector(".ytp-button.ytp-settings-button").click() | |
document.querySelector(".ytp-popup.ytp-settings-menu>.ytp-panel>.ytp-panel-menu").lastElementChild.click() | |
document.querySelector(".ytp-quality-menu>.ytp-panel-menu").firstElementChild.click() | |
document.querySelector(".ytp-gradient-bottom").style.display = save_style_display | |
} | |
catch (something_went_wrong_error) { | |
clearInterval(autoHDIntId) | |
} | |
} | |
function captionsFontCustomizingCssInsert() { | |
if (document.getElementById("dev_projectuni_na_misc_ytskipadjs_457858hse")) { return } | |
document.head.insertAdjacentHTML("beforeend", `<style id="dev_projectuni_na_misc_ytskipadjs_457858hse"> .captions-text * { font-family: "筑紫B丸ゴシック", system-ui !important; } </style>`) | |
} | |
const skipAdIntId = setInterval(skipAd, 50) | |
const captionsIntId = setInterval(captionsFontCustomizingCssInsert, 5000) | |
// const autoHDIntId = setInterval(autoHD, 1500) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment