Remove overlay messages on Youtube

Remove Youtube message about inappropriate or offensive content

  1. // ==UserScript==
  2. // @name Remove overlay messages on Youtube
  3. // @description Remove Youtube message about inappropriate or offensive content
  4. // @author MK
  5. // @namespace max44
  6. // @homepage https://greasyfork.org/en/users/309172-max44
  7. // @match *://*.youtube.com/*
  8. // @match *://*.youtu.be/*
  9. // @icon https://cdn.icon-icons.com/icons2/1488/PNG/512/5295-youtube-i_102568.png
  10. // @version 1.2
  11. // @license MIT
  12. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
  13. // @grant none
  14. // @run-at document-idle
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. var urlAtLastCheck = "";
  21. var divButtons = null;
  22. var divPlayer = null;
  23. var i;
  24.  
  25. //Check URL changes
  26. const rootCallback = function (mutationsList, observer) {
  27. var pathArray = window.location.pathname.split('/');
  28. var firstPath = pathArray[1];
  29. if (firstPath === "watch") {
  30. var urlNew = window.location.href.split("v=")[1].split("&")[0]; //Check whether it is new video
  31. if (urlAtLastCheck != urlNew) {
  32. urlAtLastCheck = urlNew;
  33. procErrorMessage();
  34. }
  35. }
  36. }
  37.  
  38. const rootNode = document.querySelector("body");
  39. if (rootNode != null) {
  40. const rootObserver = new MutationObserver(rootCallback);
  41. rootObserver.observe(rootNode, {childList: true, subtree: true});
  42. }
  43.  
  44. function procErrorMessage() {
  45. let waitError = setInterval(function() {
  46. divButtons = $( "yt-player-error-message-renderer div#button.yt-player-error-message-renderer > yt-button-renderer button" ); //New youtube design
  47. if (divButtons != null && divButtons.length > 0) {
  48. clearInterval(waitError);
  49. //console.log("new error button clicked");
  50. divButtons[0].click();
  51. }
  52.  
  53. divButtons = $( "div#button.style-scope.yt-player-error-message-renderer > yt-button-renderer > a[tabindex='-1'] > tp-yt-paper-button[aria-label][aria-disabled='false']" ); //Old youtube design
  54. if (divButtons != null && divButtons.length > 0) {
  55. clearInterval(waitError);
  56. //console.log("old error button clicked");
  57. divButtons[0].click();
  58. }
  59.  
  60. divPlayer = $( "ytd-player video" );
  61. if (divPlayer != null && divPlayer.length > 0) {
  62. for (i = 0; i < divPlayer.length; i++) {
  63. if (!divPlayer[i].paused) {
  64. //console.log("video is playing");
  65. clearInterval(waitError); //Stop waiting for error if video is playing
  66. break;
  67. }
  68. }
  69. }
  70. }, 100);
  71. }
  72.  
  73. })();