Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tallykatt/434d384cfad8a0db943a3ee43b8001e1 to your computer and use it in GitHub Desktop.
Save tallykatt/434d384cfad8a0db943a3ee43b8001e1 to your computer and use it in GitHub Desktop.
Lower CPU usage than Flash player with the benefits of bitrate stream switching.
// How to use:
// 1. Save the bookmarklet
// 2. Install the Allow-Control-Allow-Origin: * chrome / firefox extention
// 3. Go to a Giantbomb video page and click the Bookmarklet
// ## Bookmarklet
javascript:(function(){var el=document.createElement("script");el.addEventListener("load",function(){if(Hls.isSupported()){var e=new Hls;e.loadSource(videoData.videoStreams.m3u8_stream),e.attachMedia(videoEl),e.on(Hls.Events.MANIFEST_PARSED,function(){videoEl.currentTime=videoData.savePosition.savedTime,videoEl.play()})}},!1),el.src="https://cdn.rawgit.com/dailymotion/hls.js/master/dist/hls.min.js",document.body.appendChild(el);var vidWrapper=document.querySelector(".js-video-player"),videoData=JSON.parse(vidWrapper.dataset.video),videoEl=document.createElement("video");videoEl.controls=!0,videoEl.style="width:100%;height:100%;position:relative;z-index:999;",vidWrapper.parentNode.replaceChild(videoEl,vidWrapper);var d=new Date;d.setTime(d.getTime()+3456e5),videoEl.addEventListener("timeupdate",function(e){document.cookie=videoData.savePosition.cookieName+"="+videoEl.currentTime+";path=/;expires="+d.toString()});})();
// ## Allow cors
// Giantbomb's video serverse don't send Access-Control-Allow so we need to fake'em with
// with a Chrome extention called Allow-Control-Allow-Origin: *
// Chrome: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?utm_source=chrome-app-launcher-info-dialog
// Firefox: https://addons.mozilla.org/en-GB/firefox/addon/cors-everywhere/?src=search
// Original source code
var el = document.createElement('script');
el.addEventListener('load', function(){
if(Hls.isSupported()) {
var hls = new Hls();
hls.loadSource(videoData.videoStreams.m3u8_stream);
hls.attachMedia(videoEl);
hls.on(Hls.Events.MANIFEST_PARSED,function() {
videoEl.currentTime = videoData.savePosition.savedTime;
videoEl.play();
});
}
}, false);
el.src='https://cdn.rawgit.com/dailymotion/hls.js/master/dist/hls.min.js';
document.body.appendChild(el);
var vidWrapper = document.querySelector('.js-video-player');
var videoData = JSON.parse(vidWrapper.dataset['video']);
var videoEl = document.createElement('video');
videoEl.controls=true;
videoEl.style = 'width:100%;height:100%;position:relative;z-index:999;';
vidWrapper.parentNode.replaceChild(videoEl, vidWrapper);
var d = new Date();
d.setTime(d.getTime() + (96 * 60 * 60 * 1000));
videoEl.addEventListener('timeupdate', function(event) {
document.cookie = videoData.savePosition.cookieName + "=" + videoEl.currentTime + ";path=/;" + "expires=" + d.toString();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment