Sleazy Fork is available in English.

Chaturbate Full Page Video

Display the webcam video over the whole page, in the correct ratio.

Verzia zo dňa 14.05.2017. Pozri najnovšiu verziu.

// ==UserScript==
// @name         Chaturbate Full Page Video
// @namespace    http://www.JamesKoss.com/
// @version      1.0
// @description  Display the webcam video over the whole page, in the correct ratio.
// @author       James Koss
// @match        https://chaturbate.com/*/
// @supportURL   https://greasyfork.org/en/scripts/29745-chaturbate-full-page-video/feedback
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
	var vidHolder = null;
	var vid = null;
	var ratio;
	var first = true;
	var mode = true; // true is full page, false is normal.
	var resizeLimit = false;
	
    // Should run after page has loaded entirely.
	// DOMContentLoaded
	document.addEventListener('DOMContentLoaded', function() {
		// Add toggle button for script.
		var toggle = document.createElement("div");
		
		var img = document.createElement("img");
		img.setAttribute('src', 'http://i.imgur.com/cq6hDev.png');
		img.setAttribute('alt', 'Restore Video');
		img.setAttribute('title', 'Restore Video');
		img.setAttribute('height', '30');
		img.setAttribute('width', '30');
		toggle.appendChild(img);
		
		toggle.style.color = "white";
		toggle.style.backgroundColor = "black";
		toggle.style.opacity = "0.8";
		toggle.style.borderRadius = "0.25em";
		toggle.style.border = "1px solid pink";
		toggle.style.zIndex = 999999;
		toggle.style.position = "fixed";
		toggle.style.top = 0;
		toggle.style.right = 0;
		toggle.style.cursor = "pointer";
		toggle.style['user-select'] = 'none';
		toggle.style.width = "30px";
		toggle.style.height = "30px";
		toggle.style.padding = "2px";
		document.body.appendChild(toggle);
		
		toggle.addEventListener('mouseover', function(e) {
			toggle.style.opacity = "0.9";
		});
		toggle.addEventListener('mouseout', function(e) {
			toggle.style.opacity = "0.8";
		});
		toggle.addEventListener('click', function(e) {
			// Left click only.
			if (e.which !== 1) return;
			// Toggle full page video in toggled mode.
			mode = !mode;
			resizeVideo();
			if (mode) {
				img.setAttribute('src', 'http://i.imgur.com/cq6hDev.png');
				img.setAttribute('alt', 'Restore Video');
				img.setAttribute('title', 'Restore Video');
			} else {
				img.setAttribute('src', 'http://i.imgur.com/DqrmF75.png');
				img.setAttribute('alt', 'Enlarge Video');
				img.setAttribute('title', 'Enlarge Video');
			}
		});
		
		// Start by default.
		if (mode === true) resizeVideo();
	}, false);
	
	function resizeVideo() {
		// Get relevant elements.
		vidHolder = document.getElementById("player");
		vid = document.getElementById("xmovie");
		// Ignore unmatching pages.
		if (vidHolder === null) return;
		// Wait for loading.
		if (vid === null) {
			setTimeout(function() { resizeVideo(); }, 1000);
			return;
		}
		
		// Restore video size.
		if (!mode) {
			vid.style.position = "";
			vid.style.top = "";
			vid.style.left = "";
			vid.style.width = "";
			document.getElementById("blackCover").style.display = "none";
			document.body.style.overflow = "";
			return;
		}
		
		// Place over full page.
		// Element is already set as 100% height and width.
		vid.style.position = "fixed";
		vid.style.zIndex = 99999;
		vid.style.top = 0;
		vid.style.left = 0;
		
		// Keep width ratio.
		if (!ratio)
			ratio = vidHolder.clientWidth / vidHolder.clientHeight;
		
		var wWidth = window.innerWidth;
		var wHeight = window.innerHeight;
		
		vid.style.height = "100%";
		vid.style.top = 0;

		var correctWidth = vid.clientHeight * ratio;
		var correctMarginLeft = (wWidth - correctWidth) / 2;

		vid.style.width = correctWidth + 'px';
		vid.style.left = correctMarginLeft + 'px';

		// Decrease height if window less wide than video.
		if (correctMarginLeft < 1) {
			vid.style.width = "100%";
			vid.style.left = 0;

			var correctHeight = vid.clientWidth / ratio;
			var correctMarginTop = (wHeight - correctHeight) / 2;

			vid.style.height = correctHeight + "px";
			vid.style.top = correctMarginTop + 'px';
		}
		
		// Hide scrollbars in body.
		document.body.style.overflow = "hidden";
		
		// Hide background elements.
		if (first === true) {
			var d = document.createElement("div");
			d.id = "blackCover";
			d.style.backgroundColor = "black";
			d.style.zIndex = 999;
			d.style.position = "fixed";
			d.style.top = 0;
			d.style.left = 0;
			d.style.width = "100%";
			d.style.height = "100%";
			document.body.appendChild(d);
			first = false;
		}
		document.getElementById("blackCover").style.display = "";
	}
	window.addEventListener('resize', function() {
		// Script must be ready.
		if (vid === null) return;
		// Update sizes.
		if (!resizeLimit) {
			resizeLimit = true;
			setTimeout(function() {
				resizeVideo();
				resizeLimit = false;
			}, 500);
		}
	}, true);
})();