ACT metube code

//  ACT ME TUBE
/* ======================================= v 0.1.0
 @ resolution	string		(mq,hq,sd,maxres) the thumbnail resolution
 @ delay		  number		(seconds) the delay after the page load
   ======================================= */
function ACTmeTube( resolution, delay ){
	resolution = resolution || 'sd'; // (mq,hq,sd,maxres)
	delay = delay || 1;  // seconds
	
	setTimeout(function(){
		
		$('[class*="A-metube-"]').each(function(){
			
			// get video ID
			let videoId;
			$(this).attr('class').split(' ').forEach(clss =>{
				if ( $.trim( clss ).substr(0,9) == 'A-metube-' )
					videoId = $.trim( clss ).substr(9).split('::')[0]
					resolution = $.trim( clss ).substr(9).split('::')[1] || resolution;
			})
			if ( ! videoId ) return;
			
			
			let img = 'https://img.youtube.com/vi/' + videoId + '/' + resolution + 'default.jpg';
			let src = 'https://www.youtube.com/embed/' + videoId + '?ecver=1&iv_load_policy=1&rel=0&autoplay=1&autohide=2&color=red&showinfo=0&enablejsapi=1&version=3&playerapiid=ytplayer&width=640'

			
			
			let target = $(this);
			if ( target.find('.ACB-inner').length ) target = target.find('.ACB-inner');
			
			
			target.css({
				position: 'relative',
				width: 'calc(100% / 1.3)',
				'padding-top': 'calc(56.25% / 1.3)',
				margin: '0 auto',
			})

			
			let videoIframe = $('<iframe>')
				.css({
					position : 'absolute',
					top : 0,
					left : 0,
					width : '100%',
					height : '100%',
				})
				.attr('allow', 'autoplay; encrypted-media')
				.attr('frameborder', '0')
				.appendTo( target )
			
			$('<img>')
				.css({
					position : 'absolute',
					top : 0,
					left : 0,
					width : '100%',
					height : '100%',
				})
				.attr('src', img)
				.click(function(){
					videoIframe.attr('src', src)
					$(this).fadeOut(1000);
				})
				.appendTo( target )
			
		})
	}, delay * 500)
	

}

ACTmeTube();

Leave a Reply

Your email address will not be published. Required fields are marked *