YouTube Video Only

Hide video and only play audio on YouTube

  1. // ==UserScript==
  2. // @name YouTube Video Only
  3. // @name:en YouTube Video Only
  4. // @namespace https://greasyfork.org/users/44041
  5. // @include http://*youtube.*/*watch*
  6. // @include https://*youtube.*/*watch*
  7. // @version 1
  8. // @grant none
  9. // @description Hide video and only play audio on YouTube
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
  11. // @locale
  12. // ==/UserScript==
  13.  
  14. $('video').ready(function() {
  15. //$('video').css('display','none');
  16. console.log('video ready');
  17.  
  18. var video = document.getElementsByTagName("video")[0];
  19. if(video) {
  20. video.addEventListener("playing", function() {
  21. //$('video').css('z-index','-9999');
  22. //$('video').css('width','0');
  23. wallPattern.init();
  24. $('#canvas').ready();
  25. //$('.html5-video-container').css('display','none');
  26. console.error("playing");
  27. })
  28. } else {
  29. console.error("Video element not found");
  30. }
  31. });
  32.  
  33. jQuery(function($){
  34. //$('video').css('width','0');
  35. var _highest = 0;
  36.  
  37. $("div").each(function() {
  38. var _current = parseInt($(this).css("zIndex"), 10);
  39. if(_current > _highest) {
  40. _highest = _current + 1;
  41. }
  42. });
  43. //$('.html5-video-container').append('<div style="position:absolute;z-index:'+_highest+';background:#ecebeb;border:1px solid #333;border-radius:5px;height:360px;width:640px;background-image: url("http://i.imgur.com/iZHYO4N.jpg");"> </div>');
  44. $('.html5-video-container').append('<canvas id="canvas" onload="wallPattern.init();" style="position:absolute;z-index:'+_highest+';border-radius:5px;height:360px;width:640px;"> </div>');
  45.  
  46. $('#canvas').ready(function() {
  47. console.log('loaded');
  48. wallPattern.init();
  49. });
  50. });
  51.  
  52. var wallPattern = {
  53. // Settings
  54. spacingX: 55,
  55. spacingY: 35,
  56. offsetVariance: 13,
  57. baseRadius: 55,
  58. // Other Globals
  59. points: [],
  60. canvas: null,
  61. context: null,
  62. init: function() {
  63. console.log('init');
  64. this.canvas = document.getElementById( 'canvas' );
  65. this.context = canvas.getContext( '2d' );
  66. this.canvas.width = 640;
  67. this.canvas.height = 360;
  68. this.preparePoints();
  69. this.createPattern();
  70. this.drawTitle();
  71. },
  72. drawTitle: function() {
  73. var rawtitletext = $('#eow-title').text().trim();
  74. var titletext = $('#eow-title').text().trim();
  75. //var titletext = rawtitletext.replace(/(.{1,32})(?:\n|$| )/g, "$1\n");
  76. //var titletext = "The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog";
  77.  
  78. this.context.fillStyle = "white";
  79. this.context.font = "bold 30px Helvetica";
  80. //this.context.fillText(titletext, (canvas.width / 2) - 17, (canvas.height / 2) + 8);
  81. this.context.textAlign = 'center';
  82. this.context.fillText(titletext, (canvas.width / 2), (canvas.height / 2));
  83. },
  84. preparePoints: function() {
  85. var width, height, i, j, k, offsetX, offsetY;
  86. var maxVariance = this.offsetVariance * 2;
  87. // Vertical spacing
  88. for ( i = this.spacingY; i < this.canvas.height; i += this.spacingY ) {
  89. var pointSet = [];
  90. // Horizontal spacing
  91. for(j = this.spacingX; j < this.canvas.width; j += this.spacingX ) {
  92. offsetX = Math.round((Math.random() * maxVariance) - this.offsetVariance);
  93. offsetY = Math.round((Math.random() * maxVariance) - this.offsetVariance);
  94. var offsetR = Math.round((Math.random() * maxVariance) - this.offsetVariance);
  95. pointSet.push( {x: j + offsetX, y: i + offsetY, radius: this.baseRadius + offsetR} )
  96. }
  97. this.points.push( this.shuffleArray( pointSet ) );
  98. }
  99. },
  100.  
  101. createPattern: function() {
  102. this.context.beginPath();
  103. this.context.rect(0, 0, 640, 360);
  104. this.context.fillStyle = "black";
  105. this.context.fill();
  106. var i, j, k, currentPoints, currentPoint;
  107. for ( i = 0; i < this.points.length; i++ ) {
  108. currentPoints = this.points[i];
  109. for ( j = 0; j < currentPoints.length; j++ ) {
  110. currentPoint = currentPoints[j];
  111. for ( k = currentPoint.radius; k > 0; k-=10 ) {
  112. this.context.beginPath();
  113. this.context.arc(currentPoint.x, currentPoint.y, k ,0 , Math.PI*2, true);
  114. this.context.closePath();
  115. this.context.fillStyle='#000';
  116. this.context.strokeStyle='purple';
  117. this.context.fill();
  118. this.context.stroke();
  119. }
  120. }
  121. }
  122. },
  123. // Shuffle algorithm from: http://stackoverflow.com/questions/962802/is-it-correct-to-use-javascript-array-sort-method-for-shuffling
  124. shuffleArray: function( array ) {
  125. var tmp, current, top = array.length;
  126.  
  127. if(top) while(--top) {
  128. current = Math.floor(Math.random() * (top + 1));
  129. tmp = array[current];
  130. array[current] = array[top];
  131. array[top] = tmp;
  132. }
  133.  
  134. return array;
  135. }
  136. }
  137.  
  138. //wallPattern.init();