FANDOM


//
//javascript:(function(){var n=document.createElement('script');n.setAttribute('src','http://fewfre.wikia.com/load.php?mode=articles&articles=url:fewfre.wikia.com:User:Fewfre/Fox.com.js&only=scripts&action=purge');document.body.appendChild(n);}());
var few = few || {};
(function(few){
	var removalList;
	few.init = function(){
		_initRemovalList();
		_updateNav();
		_addStyle();
		_removeShows();
 
		// Watch for changes
		/*var targ = document.querySelector('.Shows_screen_3dtIQ')
		few.runGenerator(function* tCheckForChanges() {
			console.log("starting");
			var mutations = yield few.startObservable(targ);
			console.log("done");
			console.log(mutations);
			_removeShows();
 
			few.runGenerator(tCheckForChanges);
		});*/
	};
 
	function _initRemovalList() {
		removalList = [
			"zzzzzzzzzzzzzzzzz",
			"zzzzzzzzzzzzzzzzz",
			"zzzzzzzzzzzzzzzzz",
			"zzzzzzzzzzzzzzzzz",
			"zzzzzzzzzzzzzzzzz",
			"LA To Vegas",
			"Gordon Ramsay’s 24 Hours To Hell & Back",
			"The Four",
			"A Christmas Story Live",
			"9-1-1",
			"EIF Presents: XQ Super School Live",
			"Who Shot Biggie & Tupac?",
			"RENT",
			"A CHRISTMAS STORY",
			"LOVE CONNECTION",
			"KICKING AND SCREAMING",
			"KICKING & SCREAMING",
			"THE F WORD",
			"BEAT SHAZAM",
			"HYPNOTIZE ME",
			"KICKING & SCREAMING",
			"MY KITCHEN RULES",
			"American Country Countdown Awards",
			"The Following",
			"Cause For Paws",
			"MasterChef Junior",
			"Hotel Hell",
			"Hell's Kitchen",
			"World's Funniest Fails",
			"Kitchen Nightmares",
			"American Idol",
			"Sleepy Hollow",
			"Wayward Pines",
			"World's Funniest",
			"Bullseye",
			"So You Think You Can Dance",
			"MasterChef",
			"Are You Smarter Than A 5th Grader",
			"BOOM!",
			"Beat The Champions",
			"Home Free",
			"Knock Knock Live",
			"Teen Choice",
			"67th Emmy Awards",
			"Scream Queens",
			"The All-Star Dog Rescue Celebration",
			"Taraji and Terrence's White Hot Holidays",
			"American Country Countdown's Top 10 Stories of 2015",
			"Specials On FOX",
			"Miss Universe",
			"Superhuman",
			"MasterChef Celebrity Showdown",
			"Party Over Here",
			"Animation Domination High-Def",
			"The Passion",
			"American Grit",
			"Houdini And Doyle",
			"Coupled",
			"Megyn Kelly presents",
			"MISS USA",
			"STRIDE GUM PRESENTS HEAVEN SENT",
			"STAND UP TO CANCER",
			"THE EXORCIST",
			"THE ROCKY HORROR PICTURE SHOW",
			"NATIONAL GEOGRAPHIC PRESENTS - MARS",
			"NATIONAL GEOGRAPHIC PRESENTS - KILLING REAGAN",
			"SHOWTIME AT THE APOLLO",
			"NATIONAL GEOGRAPHIC PRESENTS - BEFORE THE FLOOD",
			"TARAJI'S WHITE HOT HOLIDAYS",
			"COMIC CON",
			"THE BREAKTHROUGH PRIZE",
 
			// Not bad, but just don't care enough
			"EMPIRE",
			"STAR",
			"SHOTS FIRED", // Based on the actors, likely as meh as above 2
			"zzzzzzzzzzzzzzzzz",
		];
		for (i = 0; i < removalList.length; i++) { removalList[i] = removalList[i].toLowerCase(); }
		Object.freeze(removalList);
	}
 
	function _addStyle() {
		few.$New("style", { innerHTML:""
			+".main-title, #fox-adobe-pass-mvpd, .main-footer { display:none !important; }"
			// Fox episode list edit (highlight to show visted)
			+".field-content>a { box-sizing: content-box; }"
			+".views-field-field-image-thumb a, .views-field-title:not(.show-title) a { border:5px solid orange; width: 100%; }"
			+".views-field-field-image-thumb a:visited, .views-field-title a:visited { border-color:#13181c; }" /* #1a84dd */
			+".video-lock { background:rgba(210,120,230,0.75); position: absolute !important; top: 0; left: 0; right: 0; width: calc(100% + 10px) !important; }"
			+".view-full-episodes-landing .track { height: auto !important; }"
			+".fox-now-devices { display:none !important; }"
			// Custom Episode List (highlight to show visted)
			+".few-episodes-cont { border: 1px solid #13181c; margin: 2px 4px; padding: 3px; }"
			+".few-episodes-cont:empty:after { content:'No Episodes'; }"
			+".few-ep { display:inline-block; position: relative; margin: 2px; }"
 
			+".few-ep a { border:5px solid orange; display: inline-block; line-height: 0; min-width:30px; min-height:30px; }"
			+".few-ep a:visited { border-color:green; }"
			+".few-ep .few-locked { background:rgba(210,0,0,1); position: absolute !important; top: 0; left: 0; right: 0; width:100%; height: 100%; pointer-events: none; }"
		}, document.body);
	}
 
	function _updateNav() {
		if(few.$("#fewf-nav-a")) { return; }
		// few.$Remove(few.$(".main-header"));
		few.$New("a", { innerHTML:"[Script]", href: "http://fewfre.wikia.com/wiki/Fox.com?action=edit", className:"Header_categoryItem_2_wKp", id:"fewf-nav-a" }, few.$(".Header_categories_3zGkq>div"));
	}
 
	function _removeShows() {
		var shows = few.$All(".Tile_tile_3qaLc");
		for (i = 0; i < shows.length; i++) {
			if(shows[i].checked) { return; } shows[i].checked = true;
			var show = shows[i];
			// var showH = few.$(".show-title", show);
			var showHa = few.$(".Tile_title_2XOxg", show);
			var tShowTitle = few.$("span, div", showHa).innerHTML.replace(/\(\d*\)$/g, "").trim(); // Remove "(#)"
			tShowTitle = _htmlToText(tShowTitle);
 
			if(removalList.contains(tShowTitle.toLowerCase())) {
				show.style.display = "none";
			} else {
				_initShowData(showHa.href, show);
			}
		}
	}
 
	function _initShowData(pHref, pAppendLoc) {
		fetch(pHref, { method:"GET" })
		.then(function(response) { return response.text(); })
		.then(function(text){
			var episodes = few.$New("div", { innerHTML:text }).querySelectorAll(".SeriesDetail_tabContent_3UcX5 .Tile_tile_3qaLc");
			var episodesTray = few.$New("div", { className:"few-episodes-cont" });
			for (i = 0; i < episodes.length; i++) {
				var episodeData = episodes[i];//.querySelector(".field-content");
				//console.log(episodeData);
				var href = episodeData.querySelector("a").href;
				var imgSrc = (episodeData.querySelector("a .Tile_image_19KoQ") || {}).src;
				var epLocked = !!episodeData.querySelector(".Tile_lock_1ClJ6");
 
				var episodeCont = few.$New("div", { className:"few-ep" }, episodesTray);
				var a = few.$New("a", { href:href, target:"_blank" }, episodeCont);
				few.$New("img", { src:imgSrc, width:50 }, a);
				if(epLocked) { few.$New("div", { className:"few-locked" }, episodeCont); }
			}
			pAppendLoc.appendChild(episodesTray);
		})
		;
	}
 
	/********************
	* Helper Methods
	*********************/
	few.$ = function(query, parent){ return (parent != undefined ? parent : document).querySelector(query); }
	few.$All = function(query, parent){ return (parent != undefined ? parent : document).querySelectorAll(query); }
	few.$Remove = function(elem){ return elem.parentNode.removeChild(elem); }
	few.$New = function(tag, attributes, parent) {
		var element = document.createElement(tag);
		if(attributes != undefined) {
			for(var key in attributes)
				element[key] = attributes[key];
		}
		if(parent != undefined) parent.appendChild(element);
		return element;
	}
	// https://stackoverflow.com/a/39579241/1411473
	/*few.startObservable = function(domNode) {
		var targetNode = domNode;
		var observerConfig = { subtree: true, childList: true, characterData: true }; // https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
 
		return new Promise(function(resolve) {
			var observer = new MutationObserver(function (mutations) {
				// For the sake of...observation...let's output the mutation to console to see how this all works
				// mutations.forEach(function (mutation) { console.log(mutation.type); });
				resolve(mutations)
			});
			observer.observe(targetNode, observerConfig);
		})
	}
	few.runGenerator = function(g) {
		var it = g(), ret;
		// asynchronously iterate over generator
		(function iterate(val){
			ret = it.next( val );
			if (!ret.done) {
				if ("then" in ret.value) { // poor man's "is it a promise?" test
					ret.value.then( iterate ); // wait on the promise
				} else { // immediate value: just send right back in
					// avoid synchronous recursion
					setTimeout( function(){ iterate( ret.value ); }, 0 );
				}
			}
		})();
	}*/
 
	Array.prototype.contains = function(obj) {
		var i = this.length;
		while (i--) {
			if (this[i] === obj) {
				return true;
			}
		}
		return false;
	}
 
	// Replaces amp codes with text - https://stackoverflow.com/a/3700369/1411473
	function _htmlToText(html) {
		var elem = document.createElement('textarea');
		elem.innerHTML = html;
		return elem.value;
	}
 
	few.init();
})(few);
//