ExtendYouPorn

Remove ads, enlarges video, stops autoplay keeping buffering, fixes the overhaul style & block pop-ups

Tính đến 29-11-2015. Xem phiên bản mới nhất.

// ==UserScript==
// @author			Jack_mustang
// @version			3.15
// @name			ExtendYouPorn
// @description		Remove ads, enlarges video, stops autoplay keeping buffering, fixes the overhaul style & block pop-ups
// @date			2015 November 29
// @include			*youporn.com/*
// @include			*youporngay.com/*
// @run-at			document-start
// @grant			none
// @license			Public Domain
// @icon			https://gmgmla.dm2301.livefilestore.com/y2pYluU8jK3EnLV1U8D92pYCC9wU5O04Il4j64Ft_pjKGpUG_I5L0fUHrsLpUB4oDCLIJdWp9Bwmr0RPMdhJhl5Bo362RwjatCFUpNjEdMosGA/EYP-logo.jpg
// @namespace		14fac5d83892686b90beea51d35d1d7dbcfe49b6
// ==/UserScript==
var ExtendYP = function ExtendYouPorn(){
	// Pop-up killer, we trick YP to think we are old Presto Opera, this kills the pop-ups
	if (!window.opera)
		window.opera = true

	addStyle()

	window.addEventListener('DOMContentLoaded', function(){
		// Remove ads functions
		function removeQuery(query) {
			var ifr = document.querySelectorAll(query)
			if(ifr.length > 0)
				for(var i=0; i < ifr.length; i++)
					ifr[i].parentNode.removeChild(ifr[i])
		}
		// Remove iframes because they are ads
		removeQuery("iframe")

		// Set tooltips for the titles
		var titles = document.getElementsByClassName('videoTitle')
		if(titles.length > 0)
			for(i=0; i < titles.length; i++)
				titles[i].setAttribute('title', titles[i].innerHTML)

		/* Video page */
		if(document.getElementById('videoContainer')) {
			var rightColumn = document.querySelector('.right-column'),
				videoWrapper = document.getElementById('videoWrapper')
			if (rightColumn !== null) {
				rightColumn.setAttribute('class', 'right-column large')
				videoWrapper.setAttribute('class', 'large')
			} else // compatible page for older browsers
				document.querySelector('.playWrapper').setAttribute('class', 'playWrapper sixteen-column')

			// Change player
			var player = document.getElementById('videoWrapper'),
			newflashvars = document.createElement("script")
			newflashvars.setAttribute("type", "text/javascript")
			newflashvars.id = "EYP-newflashvars"
			newflashvars.innerHTML =
			'autoplay = false;'+
			'autoload = true;'+
			'disablePauseroll = true;'
			player.insertBefore(newflashvars, player.childNodes[0])
			
			autoplay = false

			// Scroll and extra manipulation only after the elements exist
			videoStuff()
		}
	},false)

	function videoStuff() {
		if (!(document.querySelector("#videoContainer embed") || document.querySelector("#videoContainer video") || document.querySelector("#videoContainer object")))
			return setTimeout(videoStuff, 50)

		// Delete duplicate video element
		var video = document.querySelectorAll('video')
		if (video.length > 0) {
			for (var i = video.length - 1; i >= 1; i--)
				video[i].parentNode.removeChild(video[i])
			if (navigator.userAgent.search("Firefox/") === -1) {
				video[0].setAttribute("onclick", "var vid = event.target;if(vid.paused)vid.play();else vid.pause()")
				video[0].setAttribute("onmouseover", "event.target.controls = true")
				video[0].setAttribute("onmouseout", "event.target.controls = false")
				video[0].addEventListener("play", function(){
					console.log("haha")
				})
			}
		}

		// Scroll video to middle of page
		function scrollthere() {
			var player = document.getElementById('videoContainer'),
				vh = (document.getElementById('videoWrapper').getAttribute('class') == 'large')? 640 : player.offsetHeight,
				vd = (player.parentNode.offsetTop == 0)? ((document.querySelector('#studioCanvas'))? document.querySelector('.grid_8.alpha').offsetTop : document.querySelector('.watchWrapper').offsetTop+document.querySelector('#videoCanvas').offsetTop ) : player.parentNode.offsetTop,
				fh = window.innerHeight;
			sc = vd-((fh-vh)/2)
			scrollTo(0, sc)
			console.info("** ExtendYouPorn **\ntop: "+vd+", height: "+vh+", scrolled: "+sc+", window: "+fh)
		}
		// Inject this function to page
		var script = document.createElement("script")
		script.setAttribute("type", "text/javascript")
		script.innerHTML = scrollthere.toString() + "scrollthere();"
		script.id = "EYP-scrollVid"
		document.body.appendChild(script)

		// Include button in right corner to center video on screen
		var node = document.createElement("div")
		node.setAttribute("style","position: fixed; bottom: 0; right: 0; cursor: pointer; border-top-left-radius: 10px; color: #fff; text-shadow: 1px 1px 1px #292929; font-weight: 700; background: url('http://cdn1.static.youporn.phncdn.com/cb/bundles/manwinyoupornwebfront/images/sprite-watch-bg.png?v=1358797378') 0px -42px repeat-x transparent; text-align: center; font-size: 1.2em; padding: 7px;z-index: 999999;")
		node.setAttribute("onclick", "scrollthere();")
		node.innerHTML = "Center video"
		node.id = "EYP-scroll"
		document.body.appendChild(node)
	}

	function addStyle() {
		// While <head> is not loaded we keep trying
		if (!document.querySelector("head"))
			return setTimeout(addStyle, 50)

		// We create an object and start including its content to include in DOM at the end
		var eypcss =
		// Hide ads while we can't remove them, the last hides the HTML5 player in-vid ads
		".trafficjunky-video-being-watched-section, .trafficjunky-ad, .trafficjunky-float-right, .sideBarAd, .sideBarAdLink, #adblock_1, .footer-ad-container {\n\
			display: none !important;\n\
		}\n\
		#pb_top_bar, #pb_content {\n\
			display: none !important;\n\
		}\n\
		#pb_block {\n\
			background: none !important;\n\
			height: 25% !important;\n\
		}\n" +
		// Fix ::selection
		"::selection {\n\
			background: #FFACC0;\n\
			color: #fff;\n\
		}\n\
		::moz-selection {\n\
			background: #FFACC0;\n\
			color: #fff;\n\
		}\n" +
		// Videos in one line where ads were
		".container>.row:first-child+.row:after {\n\
			display: inline !important;\n\
		}\n\
		#recommended-videos-first-row>.row {\n\
			width: 1000px;\n\
		}\n" +
		// Video page
		"video {\n\
			position: absolute;\n\
		}\n\
		#no_flash_player_message {\n\
			display: block !important;\n\
		}\n" +
		// User pages - Dashboard
		".wrapTitle.grid_9 {\n\
			width: 100% !important;\n\
		}\n" +
		// Fix last element non-clickable on festive skins
		"#watchBottom {\n\
			position: relative;\n\
			z-index: 1;\n\
		}\n" +
		/* Channel pages */
		"#channelCanvas .grid_3 {\n\
			width: 25% !important;\n\
		}\n"

		// Inject created CSS
		var eypnode = document.createElement("style")
			eypnode.type = "text/css"
			eypnode.id = "EYP-style"
			eypnode.appendChild(document.createTextNode(eypcss))
		document.head.appendChild(eypnode)
	}
}();