z87 / IEEE Spectrum

// ==UserScript==
// @name        IEEE Spectrum
// @namespace   local
// @include     http://spectrum.ieee.org/*
// @version     1
// @grant       none
// ==/UserScript==

// interstitial
if (window.splashpage && window.splashpage.launch) window.splashpage.closeit();

// tracking
if (typeof window.initGAEventTracking == 'function') window.initGAEventTracking = function(){};

// sticky top
if (typeof window.initGlobalNavMenus == 'function') {
	var real_initGlobalNavMenus = window.initGlobalNavMenus;
	window.initGlobalNavMenus = function(headerInteractions) {
		headerInteractions.stickyTop = function(){};
		real_initGlobalNavMenus.apply(this, arguments);
		real_initGlobalNavMenus = null;
		window.initGlobalNavMenus = null;
	};
}

// isotope ads
$('.ad-item, .ad-item-related, .ad-module, .facebook-module').remove();

// switch jwplayer to html5
if (typeof window.jwplayer == 'function') window.jwplayer().on('ready', function() {
	for (let container of document.getElementsByClassName('jwplayer')) {
		let config = window.jwplayer(container.id).getConfig(),
			src = { height: 0 };
		if (config.primary != 'flash') continue;
		for (let item of config.playlist[0].allSources)
			if (item.type == 'mp4' && Math.abs(item.height - config.containerHeight) < Math.abs(src.height - config.containerHeight)) src = item;
		if (src.file) {
			config.autostart = 'false';
			config.primary = 'html5';
			config.playlist[0].sources = [src];
			window.jwplayer(container.id).setup(config);
		}
	}
});