Last active
June 4, 2018 21:06
-
-
Save bre7/e615d385e72444e1e9e9a6ded2d875b2 to your computer and use it in GitHub Desktop.
WWDC unblocker for Chrome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name WWDC unblocker for Chrome | |
| // @description Allows volume control with mouse wheel // Pplay/pause with space bar // Disables auto play // Sets default volume to 20% // Double click to enter/exit fullscreen mode | |
| // @version 1.0.2 | |
| // @author You | |
| // @match https://developer.apple.com/videos/play/* | |
| // @match https://developer.apple.com/wwdc/live/* | |
| // @grant none | |
| // @updateURL https://gist.githubusercontent.com/bre7/e615d385e72444e1e9e9a6ded2d875b2/raw | |
| // ==/UserScript== | |
| $(document).ready( function() { | |
| unblockVideo(); | |
| bindings(); | |
| }); | |
| function unblockVideo() { | |
| // Source https://github.com/jrejaud/WWDChrome/blob/master/content_script.js | |
| var optionsLink = document.getElementsByClassName("options")[0]; | |
| var optionsLinkItems = optionsLink.getElementsByTagName("li"); | |
| //Get the first a element inside the ul (first element inside the li) | |
| var hdVideoElement = optionsLinkItems[0].getElementsByTagName("a")[0]; | |
| var hdVideoURL = hdVideoElement.getAttribute("href"); | |
| //Get the video element | |
| var bustedAssVideo = document.getElementsByClassName("video center")[0]; | |
| bustedAssVideo.getElementsByTagName("source")[1].remove(); | |
| //This is the url of the video that you will be shown if using Chrome | |
| var badVideoUrl = bustedAssVideo.getElementsByTagName("source")[0].getAttribute("src"); | |
| //Replace the video URL | |
| bustedAssVideo.setAttribute("src", hdVideoURL); | |
| bustedAssVideo.volume = 0.2; | |
| bustedAssVideo.autoplay = false; | |
| } | |
| function bindings() { | |
| $(document).on("keydown", function(event) { | |
| var video = document.getElementsByClassName("video center")[0]; | |
| var stride = 5; // seconds | |
| if (event.which == 32) { // Space bar | |
| event.preventDefault(); | |
| if (video.paused === true) { | |
| video.play(); | |
| } else { | |
| video.pause(); | |
| } | |
| } else if (event.which == 37) { // Left arrow | |
| event.preventDefault(); | |
| if(video.currentTime > 0 + stride) video.currentTime -= stride; | |
| } else if (event.which == 39) { // Right arrow | |
| event.preventDefault(); | |
| if(video.currentTime < 1 - stride) video.currentTime += stride; | |
| } | |
| }); | |
| $("#main > .bg-dark").on("mousewheel DOMMouseScroll", function(event) { | |
| var video = document.getElementsByClassName("video center")[0]; | |
| var stride = 0.05; | |
| event.preventDefault(); | |
| if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) { | |
| // scroll up | |
| if(video.volume < 1 - stride) video.volume += stride; | |
| } else { | |
| // scroll down | |
| if(video.volume > 0 + stride) video.volume -= stride; | |
| } | |
| }); | |
| $('video').on("click", function(event) { | |
| if (this.paused === true) | |
| this.play(); | |
| else | |
| this.pause(); | |
| }).on("dblclick", function(event) { | |
| var isFullScreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen; | |
| if (isFullScreen) { | |
| if (this.exitFullscreen) { | |
| this.exitFullscreen(); | |
| } //fullscreen for safari/chrome/opera | |
| else if (this.webkitExitFullscreen) { | |
| this.webkitExitFullscreen(); | |
| } //fullscreen for Firefox | |
| else if (this.mozExitFullScreen) { | |
| this.mozExitFullScreen(); | |
| } //fillscreen for IE11 | |
| else if (this.msExitFullscreen) { | |
| this.msExitFullscreen(); | |
| } | |
| } else { | |
| if (this.requestFullscreen) { | |
| this.requestFullscreen(); | |
| } //fullscreen for safari/chrome/opera | |
| else if (this.webkitRequestFullscreen) { | |
| this.webkitRequestFullscreen(); | |
| } //fullscreen for Firefox | |
| else if (this.mozRequestFullScreen) { | |
| this.mozRequestFullScreen(); | |
| } //fillscreen for IE11 | |
| else if (this.msRequestFullscreen) { | |
| this.msRequestFullscreen(); | |
| } | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment