Skip to content

Instantly share code, notes, and snippets.

@Yonezpt
Last active August 29, 2015 14:18
Show Gist options
  • Save Yonezpt/f9ae0de1376ae89cd2e8 to your computer and use it in GitHub Desktop.
Save Yonezpt/f9ae0de1376ae89cd2e8 to your computer and use it in GitHub Desktop.
Forces the transparent player on YouTube for testing purposes
// ==UserScript==
// @version 1
// @name YouTube transparent player
// @namespace none
// @description Forces the transparent player on YouTube for testing purposes
// @match *://www.youtube.com/*
// @run-at document-start
// @grant none
// @noframes
// ==/UserScript==
(function () {
'use strict';
function switchPlayer(event) {
var ytConfig,
script = 'https://s.ytimg.com/yts/jsbin/html5player-new-vflkiLxkD/html5player-new.js',
style = 'https://s.ytimg.com/yts/cssbin/www-player-new-vfl2ujh_c.css';
if (event.target.getAttribute('name') === 'html5player/html5player' && event.target.src !== script) {
event.preventDefault();
event.stopPropagation();
}
if (event.target.textContent.split('var ytplayer = ytplayer').length > 1) {
event.preventDefault();
event.stopPropagation();
if (window.location.href.split('/watch').length > 1) {
ytConfig = event.target.textContent.match(/ytplayer\.config = \{([\w\W]*?)\};/)[1];
window.ytplayer = window.ytplayer || {};
window.ytplayer.config = JSON.parse('{' + ytConfig + '}');
window.ytplayer.config.html5 = true;
window.ytplayer.config.assets.css = style;
window.ytplayer.config.assets.js = script;
}
}
}
window.addEventListener('beforescriptexecute', switchPlayer);
//window.matchMedia = false; //Enable this to allow proper resizing of the player and its contents
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment