ExtendYouPorn

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

Versão de: 19/08/2016. Veja: a última versão.

// ==UserScript==
// @author			Jack_mustang
// @version			4.6
// @name			ExtendYouPorn
// @description		Remove ads, enlarges video, stops autoplay keeping buffering, fixes the overhaul style & block pop-ups
// @date			2016 August 19
// @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==
// Block popups
var eypvsc = 0;
var eypcpc = 0;

function NoOpen(e){return 1}
parent.open=NoOpen;
this.open=NoOpen;
window.open=NoOpen;
open=NoOpen;
window.open = function(){return;}
open = function(){return;}
this.open = function(){return;}
parent.open = function(){return;}

// Block ads
window.__defineGetter__("page_params", function() {return null});
window.__defineSetter__("page_params", function() {return null});

window.g367CB268B1094004A3689751E7AC568F = {
	Core: "stop mouse tracking and popups"
};
window.__defineSetter__("f8CB2C22AA84415BA2272F8261AED24C", function() {
	return "Seriously, STOP!"
});

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()
	changePlayer()

	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")

		// Video page
		if(document.getElementById('videoContainer') || document.querySelector(".channelDetailWrapper")) {
			if (document.querySelector('.playWrapper'))
				document.querySelector('.playWrapper').setAttribute('class', 'playWrapper sixteen-column')

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

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

		// Scroll video to middle of page
		function scrollthere() {
			var player = document.getElementById('videoContainer'),
				vh = player.offsetHeight,
				vd = ((document.querySelector("#network-bar").offsetHeight > 0) ? 0 : 25) + ((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)
			scrollVid(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 = "window.scrollVid = window.scrollTo; " + scrollthere.toString() + " scrollthere();"
		script.id = "EYP-scrollVid"
		document.body.appendChild(script)

		// Keyboard Shortcut for centring
		window.addEventListener('keyup', function(e) {
			if(e.ctrlKey && e.altKey && (e.code === "KeyC" || (e.code === undefined && e.keyCode === 67)))
				scrollthere()
		}, false)

		// 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; color: #fff; text-transform: uppercase; background: #ec567c; text-align: center; font-size: 1.2em; padding: 7px;z-index: 999999;")
		node.setAttribute("onclick", "scrollthere();")
		node.setAttribute("title", "Use the keyboard shortcut Ctrl+Alt+C (For other keyboard layouts use the key where C should be on the QWERTY layout)")
		node.innerHTML = "Center video"
		node.id = "EYP-scroll"
		document.body.appendChild(node)
	}

	function changePlayer() {
		eypvsc ++;
		if (eypvsc > 100)
			return;
		if (!document.getElementById('videoWrapper'))
			return setTimeout(changePlayer, 50)

		var newflashvars = document.createElement("script")
		newflashvars.setAttribute("type", "text/javascript")
		newflashvars.id = "EYP-newflashvars"
		newflashvars.innerHTML =
			'page_params.video.playerParams.autoplay = false;'+
			'page_params.video.playerParams.autoload = true;'
		document.head.appendChild(newflashvars)
	}

	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
		"iframe, figure, aside," +
		// Ad spaces
		".row > .eight-column > div:not(.row), .trafficjunky-float-right," +
		// Remove Ads links, Ads by TrafficJunkie notice
		".ad-remove, .ad-bottom-text, .ad-links-text," +
		// Ad block message
		"#adblock_1," +
		// Pornstars page, pornstars in one line
		".nine-column .porn-star-list:last-child {\
			display: none !important;\
		}" +
		// vids in one line, on pornstars page
		"div.eight-column:not(.title-select), div.eight-column .row,\
		.nine-column, .nine-column .row {\
			width: 100% !important;\
		}" +
		// Remove ad space on pornstar page
		"body[data-current-action=pornstar] div.twelve-column > .row:first-child {\
			float: left;\
			width: auto;\
		}"

		// 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)
	}
}();