YouTube Improver

Remove ads and improves some stuff

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         YouTube Improver
// @namespace    -
// @version      2.1
// @description  Remove ads and improves some stuff
// @author       Carolina Reaper
// @match        *://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @run-at       document-start
// @connect      googlevideo.com
// @grant        none
// ==/UserScript==
// Start Injection
let inject1 = Date.now();
console.log("Injecting Script, YouTube Improver.");

// Prevent video loading from a timestamp
if (location.href.includes("&t=")) {
    location.href = location.href.split("&t=")[0];
};

// Set classes to remove
let classes = ["ytd-banner-promo-renderer-background", "style-scope ytd-banner-promo-renderer"];

// Create a new interval
setInterval(function() {
    // Increase transparancy on captions
    let captions = document.getElementsByClassName("caption-window");
    for (let e = 0; e < captions.length; e++) captions[e].style.backgroundColor = "rgba(0, 0, 0, 0)";

    // Remove classes
    classes.forEach(function(currentClass) {
        let elements = document.getElementsByClassName(currentClass);
        for (let e = 0; e < elements.length; e++) elements[e].remove();
    });

    // Remove on main page
    let ads = document.getElementsByTagName("ytd-ad-slot-renderer");
    for (let e = 0; e < ads.length; e++) ads[e].remove();
});

// Skip ads on videos
function closeAd() {
    let css = '.video-ads, .video-ads .ad-container .adDisplay,#player-ads, .ytp-ad-module, .ytp-ad-image-overlay { display: none!important; }';
    let head = document.head || document.getElementsByTagName('head')[0];
    let style = document.createElement('style');

    style.type = 'text/css';
    if (style.styleSheet) style.styleSheet.cssText = css;
    else style.appendChild(document.createTextNode(css));

    head.appendChild(style);
};

let skipInterval, skipAd = function() {
    let skipButton = document.querySelector(".ytp-ad-skip-button.ytp-button") || document.querySelector(".videoAdUiSkipButton ");
    if (skipButton) {
        skipButton = document.querySelector(".ytp-ad-skip-button.ytp-button") || document.querySelector(".videoAdUiSkipButton ");
        skipButton.click();
        if (skipInterval) clearTimeout(skipInterval);
        skipInterval = setTimeout(skipAd, 5e2);
    } else {
        if (skipInterval) clearTimeout(skipInterval);
        skipInterval = setTimeout(skipAd, 5e2);
    };
};

closeAd();
skipAd();

// Complete Injection
let injectionTime = Date.now() - inject1;
console.log("Injection Complete, YouTube Improver.\nInjection Time: " + injectionTime + "ms");