Youtube Age Confirmation Bypass

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

目前為 2017-05-20 提交的版本,檢視 最新版本

  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 https://www.youtube.*/watch*
  6. // @include http://*.youtube.*/watch*
  7. // @include https://*.youtube.*/watch*
  8. // @match http://*.youtube.com/watch*
  9. // @match https://*.youtube.com/watch*
  10. // @match https://*.youtube.com/verify_age*
  11. // @version 1.6
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. var quality = 720; // Change this to the default quality of your preference
  16. var currentUrl = decodeURIComponent(window.location.href);
  17.  
  18. function getEmbedUrl(videoID) {
  19. return "https://www.youtube.com/embed/" + videoID;
  20. }
  21.  
  22. function getVideoID(url) {
  23. url = url.substr(url.indexOf("v=") + 2);
  24. var junk = url.indexOf("&");
  25. if (junk != -1) {
  26. url = url.substr(0, junk);
  27. }
  28. return url;
  29. }
  30.  
  31. function createEmbedString() {
  32. var embedString = "<iframe width=\"100%\" height=\"100%\" src='" +
  33. getEmbedUrl(getVideoID(currentUrl)) + "?autoplay=1&vq=hd" +
  34. quality + "' frameborder=\"0\" allowfullscreen></iframe>";
  35.  
  36. return embedString;
  37. }
  38.  
  39. window.addEventListener('load', function() {
  40. // Redirect to the regular video page if we're on a "verify age" page
  41. if (currentUrl.indexOf("verify_age?next_url=/") != -1) {
  42. window.location = currentUrl.replace("verify_age?next_url=/", "");
  43. return;
  44. }
  45.  
  46. // Check a couple of times to see if the required DOM element is available. If it is and the
  47. // age restricted message appears to be not hidden, replace the regular player with an embedded player.
  48. var attempts = 0;
  49. var check = setInterval(function() {
  50. // New Youtube layout
  51. var el = document.getElementById('error-screen');
  52. if (null != el && !el.hasAttribute('hidden')) {
  53. document.querySelector('#player.ytd-watch').innerHTML = createEmbedString();
  54. clearInterval(check);
  55. return;
  56. }
  57. // Old Youtube layout
  58. el = document.getElementById('player-unavailable');
  59. if (null != el && !el.classList.contains('hid')) {
  60. document.getElementById('player-unavailable').innerHTML = createEmbedString();
  61. clearInterval(check);
  62. return;
  63. }
  64.  
  65. if (++attempts > 3) {
  66. clearInterval(check);
  67. }
  68. }, 300);
  69.  
  70. }, false);