NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Detector de silencio // @namespace http://taringa.net/Incasoft // @version 0.1 // @description enter something useful // @author You // @match http://www.youtube.com/* // @match https://www.youtube.com/* // @match http://youtube.com/* // @match https://youtube.com/* // @include http://www.youtube.com/* // @include https://www.youtube.com/* // @include http://youtube.com/* // @include https://youtube.com/* // @grant none // ==/UserScript== var silence = 0; var seconds = 3; if (!Date.now) { Date.now = function() { return new Date().getTime(); }; } var silenceSince = false; var videoPlaying=false; var processor; var videoElement; window.addEventListener('load',function(){ console.log('Init Youtube silence detector'); window.onYouTubePlayerReady = onYouTubePlayerReady = function(ytplayerobj){ videoPlaying=true; ytplayerobj.addEventListener('onStateChange', function(e){ videoPlaying= 1===e; }, false); }; var context = new webkitAudioContext(); videoElement = document.querySelector('video'); var mediaSourceNode = context.createMediaElementSource(videoElement); processor = context.createScriptProcessor(); mediaSourceNode.connect(processor); mediaSourceNode.connect(context.destination); processor.connect(context.destination); window.ii=window.i=0; processor.onaudioprocess=function(e){ if(videoPlaying&&videoElement.volume>0&&false===videoElement.muted){ left=e.inputBuffer.getChannelData(0); for(var i in left){ if((left[i]/videoElement.volume) > silence){ silenceSince = false; return true; } } right=e.inputBuffer.getChannelData(1); for(i in right){ if((right[i]/videoElement.volume) > silence){ silenceSince = false; return true; } } console.log('silence'); if(false!==silenceSince){ if((silenceSince+seconds*1000)<=Date.now()){ console.log('siguiente'); document.querySelector('.ytp-button-pause').click(); videoPlaying=false; silenceSince=false; document.querySelector('.ytp-button-next').click(); } }else{ silenceSince=Date.now(); } return true; } } });