Youtube Age Confirmation Bypass

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

  1. // ==UserScript==
  2. // @name Youtube Age Confirmation Bypass
  3. // @namespace kneels
  4. // @description Prevents you from having to sign in to view age restricted videos on YouTube
  5. // @include http://www.youtube.com/*
  6. // @include https://www.youtube.com/*
  7. // @exclude http://www.youtube.com/embed/*
  8. // @exclude https://www.youtube.com/embed/*
  9. // @version 1.65
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. var quality = 720; // Change this to the default quality of your preference
  14.  
  15. function getCurrentUrl() {
  16. return decodeURIComponent(window.location.href);
  17. }
  18.  
  19. function getEmbedUrl(videoID) {
  20. return "https://www.youtube.com/embed/" + videoID;
  21. }
  22.  
  23. function getVideoID(url) {
  24. url = url.substr(url.indexOf("v=") + 2);
  25. var junk = url.indexOf("&");
  26. if (junk != -1) {
  27. url = url.substr(0, junk);
  28. }
  29. return url;
  30. }
  31.  
  32. function createEmbedString() {
  33. var embedString = "<iframe width=\"100%\" height=\"100%\" src='" +
  34. getEmbedUrl(getVideoID(getCurrentUrl())) + "?autoplay=1&vq=hd" +
  35. quality + "' frameborder=\"0\" allowfullscreen></iframe>";
  36.  
  37. return embedString;
  38. }
  39.  
  40. var target = document.body;
  41. var title = "";
  42.  
  43. var observer = new MutationObserver(function(mutations) {
  44. // Check if a new page was (dynamically) loaded
  45. if (title != document.title) {
  46.  
  47. // Redirect to the regular video page if we're on a "verify age" page
  48. if (getCurrentUrl().indexOf("verify_age?next_url=/") != -1) {
  49. window.location = getCurrentUrl().replace("verify_age?next_url=/", "");
  50. return;
  51. }
  52.  
  53. // Check a couple of times to see if the required DOM element is available. If it is and the
  54. // age restricted message appears to be not hidden, replace the regular player with an embedded player.
  55. var attempts = 0;
  56. var check = setInterval(function() {
  57. // New Youtube layout
  58. var el = document.getElementById('error-screen');
  59. if (null != el && !el.hasAttribute('hidden')) {
  60. document.querySelector('#player.ytd-watch').innerHTML = createEmbedString();
  61. clearInterval(check);
  62. return;
  63. }
  64. // Old Youtube layout
  65. el = document.getElementById('player-unavailable');
  66. if (null != el && !el.classList.contains('hid')) {
  67. document.getElementById('player-unavailable').innerHTML = createEmbedString();
  68. clearInterval(check);
  69. return;
  70. }
  71.  
  72. if (++attempts > 3) {
  73. clearInterval(check);
  74. }
  75. }, 300);
  76.  
  77. title = document.title;
  78. }
  79. });
  80.  
  81. var config = {
  82. attributes: true
  83. };
  84. observer.observe(target, config);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址