Bypass COPPA Miniplayer

Re-enable YouTube Miniplayer on COPPA-flagged (supposedly kids) videos.

当前为 2020-03-03 提交的版本,查看 最新版本

// ==UserScript==
// @name         Bypass COPPA Miniplayer
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Re-enable YouTube Miniplayer on COPPA-flagged (supposedly kids) videos.
// @author       jaytohe
// @include      https://www.youtube.com/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  var waitforvid = window.setInterval(function() { //continually check if user has loaded up a video.
      var vid = document.getElementsByClassName("html5-main-video")[0]; //find video element in page.
      //console.log("Type is : "); DEBUG
      //console.log(typeof vid); DEBUG
      if (typeof vid !== "undefined") {
          console.log("Video Found! Injecting...");
          var minibtn = document.getElementsByClassName("ytp-miniplayer-button")[0]; //find miniplayer button.
          var unpause = function u() {
              vid.play();
          };
      /* START OF UNBLOCK FUNCTION */
      var unblock = function () {
        vid.onpause = unpause; //ignore any pause video requests. Just continue playing the damn video.
        var oldHeight = vid.clientHeight; //get height of current video element.
          var wmini = window.setInterval(function() { //continuously check if height has changed i.e. miniplayer bottom right window has appeared?
              if (oldHeight !== vid.clientHeight) {
                  allowcontrols();
                  clearInterval(wmini);
                  vid.onpause = null; //re-allow pausing of video on miniplayer.
                  var old_url = vid.src;
                  var play_btn = document.getElementsByClassName("ytp-play-button")[0];
                  checkminivideo(old_url, play_btn);
              }
          }, 1000);
      };
      /* END OF UNBLOCK FUNCTION */
      minibtn.addEventListener("click", unblock, false); //hijack miniplayer button.
      clearInterval(waitforvid); //cease checking if any video has loaded up.
  }
      function allowcontrols() { //re-enables miniplayer controls on kids videos.
          var controls = document.getElementById("blocking-container");
          if (!controls.hasAttribute("hidden")) {
              controls.setAttribute("hidden", "");
          }
      }
       function checkminivideo(old_url, play_btn) {
        window.setInterval(function() { //check if another video loads up on the miniplayer.
            if (old_url != vid.src && vid.src !== "") { //if true
                //console.log(vid.src); DEBUG OUTPUT
                console.log("Video change detected. Re-injecting...");
                vid.onpause = unpause; //prevent yt from pausing "kid" video.
                var t = setInterval(function(){
                  if (vid.paused === true) {
                    console.log("Clicking video to unpause...");
                    play_btn.click(); //hacky solution in case onpause doesn't prevent yt from pausing kid video.
                    vid.play();
                  } else {clearInterval(t);}
                }, 800);
                allowcontrols();
                setTimeout(function() { vid.onpause=null;}, 1500); //re-allow pausing of video after 1.5 seconds
                old_url = vid.src;
            }
        },500);
    }
  }, 1000); //check if a video has loaded up every second.

}) ();