Youtube Age Confirmation Bypass

Prevents you from having to sign in to view age restricted videos on YouTube

当前为 2017-05-20 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Youtube Age Confirmation Bypass
// @namespace   kneels
// @description Prevents you from having to sign in to view age restricted videos on YouTube
// @include     https://www.youtube.*/watch*
// @include     http://*.youtube.*/watch*
// @include     https://*.youtube.*/watch*
// @match       http://*.youtube.com/watch*
// @match       https://*.youtube.com/watch*
// @match       https://*.youtube.com/verify_age*
// @version     1.6
// @grant       none
// ==/UserScript==

var quality = 720; // Change this to the default quality of your preference
var currentUrl = decodeURIComponent(window.location.href);

function getEmbedUrl(videoID) {
    return "https://www.youtube.com/embed/" + videoID;
}

function getVideoID(url) {
    url = url.substr(url.indexOf("v=") + 2);
    var junk = url.indexOf("&");
    if (junk != -1) {
        url = url.substr(0, junk);
    }
    return url;
}

function createEmbedString() {
    var embedString = "<iframe width=\"100%\" height=\"100%\" src='" +
        getEmbedUrl(getVideoID(currentUrl)) + "?autoplay=1&vq=hd" +
        quality + "' frameborder=\"0\" allowfullscreen></iframe>";

    return embedString;
}

window.addEventListener('load', function() {
    // Redirect to the regular video page if we're on a "verify age" page
    if (currentUrl.indexOf("verify_age?next_url=/") != -1) {
        window.location = currentUrl.replace("verify_age?next_url=/", "");
        return;
    }

    // Check a couple of times to see if the required DOM element is available. If it is and the 
    // age restricted message appears to be not hidden, replace the regular player with an embedded player.
    var attempts = 0;
    var check = setInterval(function() {
        // New Youtube layout
        var el = document.getElementById('error-screen');
        if (null != el && !el.hasAttribute('hidden')) {
            document.querySelector('#player.ytd-watch').innerHTML = createEmbedString();
            clearInterval(check);
            return;
        }
        // Old Youtube layout
        el = document.getElementById('player-unavailable');
        if (null != el && !el.classList.contains('hid')) {
            document.getElementById('player-unavailable').innerHTML = createEmbedString();
            clearInterval(check);
            return;
        }

        if (++attempts > 3) {
            clearInterval(check);
        }
    }, 300);

}, false);