FapFun

Userscript for Motherless.com . Provide direct links for pictures and video files.

Stan na 25-12-2014. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        FapFun
// @namespace   https://greasyfork.org/scripts/7156-fapfun/code/FapFun.user.js
// @description Userscript for Motherless.com . Provide direct links for pictures and video files.
// @require		https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
// @include     htt*://motherless.com*
// @version     2
// @grant       GM_xmlhttpRequest
// @grand 		UnsafeWindow
// @author		sodomgomora
// ==/UserScript==

// Some of this script based on Pornifier2 script by Jesscold 
// This script is realesed under GPL v3

// Globals
var debug = false;
var sp = new singlePreview();
var images = [];

// Start the magic
main();

function fapLog(log){
	if(debug === true){
		console.log(log);
	}
}
function main(){

	fapLog("entered main");
	
	// try to become Premium
	// setTimeout(function(){
		// unsafeWindow.__is_premium = true; //really motherless?
	// }, 500);
	
	// create Buttons
	var inputList=document.createElement("input");
	inputList.type="button";
	inputList.value="Images URLs";
	inputList.onclick = getImageList;
	inputList.setAttribute("style","font-size:18px;position:fixed;top:100px;right:40px;z-index:10000;");
	document.body.appendChild(inputList);
	
	var inputVideo=document.createElement("input");	
	inputVideo.type="button";
	inputVideo.value="Video URLs";
	inputVideo.onclick = getVideoUrl;
	inputVideo.setAttribute("style","font-size:18px;position:fixed;top:140px;right:40px;z-index:10000;");
	document.body.appendChild(inputVideo);
	
	sp.addSinglePreview();
	
	// fapLog("Premium: " + unsafeWindow.__is_premium.toSource());
}
		
function getImageList(){
	fapLog("getImageList: pressed");
	sp.getImages();
}

function getVideoUrl(){
	alert("not jet implemented!");
}

//-- handler for Overlay (jquery)
$(function () {
    $("body").click(function () {
        if ($("#overlay").length > 0) {
            removeOverlay();
        }
    });
});

function removeOverlay() {
    $("#overlay").remove();
}

// Get url for full image and add url under thumbnail
function singlePreview(){	
	this.addSinglePreview = function(){
		var data = [];
		var i = 0;
		var imgs = $('img[src^="http://thumbs.motherlessmedia.com/thumbs/"]');
		
		fapLog("image urls found: " + imgs.length);
	
		imgs.each(function(){
			var $wrap = $(this);
			if($wrap.data('p2-preview')){
				return;
			}
			$wrap.data('p2-preview', 'yep');
			var $a = $wrap.closest("a");
			var vid = $wrap.attr("src").match("thumbs/([^.]+).\\w");
			// test for video preview and not an image
			var vlink = vid[1];
			var n = vlink.indexOf("-");
			vlink = vlink.substring(n,vlink.length);
		
			fapLog("vlink: " + vlink);
			
			// is a video
			if(vlink == "-small"){
				var videoClicky = $("<a href='javascript;' class='p2-single-preview'>Video URL</a>");
				$a.after(videoClicky);
				var href = $a.attr('href').match(/\.com\/(\w)(\w+)/) ? [RegExp.$1, RegExp.$2] : false;
				videoClicky.click(function(e, single){
					var $this = $currentSingle = $(this);
					$this.text("loading...");
					var id = $wrap.attr("data-strip-src").match("thumbs/([^.]+).\\w");
					var vl = id[1];
					var n = vl.indexOf("-");
					id[1] = vl.substring(0,n);
					
					fapLog("found url for video: " + id[1]);
									
					if(!id){
						$this.text("cant load :P");
						return;
					}
					var timer = setTimeout(function(){
						$this.text("cant load :P");
					}, 8000);
					sp.findVideoSrc(id[1], function(src){
						$this.text("Show Video");
						clearTimeout(timer);
						if(single){
							data = [src];
						} else {
							data.unshift(src);
						}
						fapLog("video src: " + src.toSource());
						
						displayOverlay(data, "video");
					});
					return false;
				});
			}
			else{
				var id = $wrap.attr("data-strip-src").match("thumbs/([^.]+).\\w");
				images[i] = id[1];
				i++;
				fapLog("fill images: image=" + images[i-1] + " index=" + i);
				var imageClicky = $("<a href='javascript;' class='p2-single-preview'>View full size</a>");
				$a.after(imageClicky);
				var href = $a.attr('href').match(/\.com\/(\w)(\w+)/) ? [RegExp.$1, RegExp.$2] : false;
				imageClicky.click(function(e, single){
					var $this = $currentSingle = $(this);
					$this.text("loading...");
					//var id = $wrap.attr("data-strip-src").match("thumbs/([^.]+).\\w");
					
					fapLog("found url for image: " + id[1]);
					
									
					if(!id){
						$this.text("cant load :P");
						return;
					}
					var timer = setTimeout(function(){
						$this.text("cant load :P");
					}, 8000);
					sp.findImgSrc(id[1], function(src){
						$this.text("View full size");
						clearTimeout(timer);
						if(single){
							data = [src];
						} else {
							data.unshift(src);
						}
						fapLog("image src: " + src.toSource());
						
						displayOverlay(data, "image");
					});
					return false;
				});
			}
			
		});
	};
	
	this.getImages = function() {
		fapLog("getImages: images.length=" + images.length);
		imagesUrl = [];
		if(images.length > 0){
			parralelizeTask(images, loopFindImageSource, function(){
				fapLog("getImages: iamgesUrl= " + imagesUrl.toSource());
				displayOverlay(imagesUrl, "images");
			});
		}
	};
	
	this.findVideoSrc = function(id, cb) {
		var href = "http://motherless.com/"+id;
		sneakyXHR(href, function(d){
			fapLog("sneaky request all: " + d.toSource());
			
			var url = d.match(/"http:([^"]+).mp4"/mi) ? RegExp.$1 : null;
			if(url){
				cb({url:"http:" + url + ".mp4"});
			}
		}, "get", {
			'Range': 'bytes=0-3000' //grab first 3k
		});
	};
	
	this.findImgSrc = function(id, cb){
		var href = "http://motherless.com/"+id+"?full";
		sneakyXHR(href, function(d){
			var img = d.match(/property="og:image" content="([^"]+)"/mi) ? RegExp.$1 : null;
			if(img){
				cb({url:img});
			}
		}, "get", {
			'Range': 'bytes=0-3000' //grab first 3k
		});
	};
}

// show the full image as overlay and shrink it to screen resolution
function displayOverlay(data, type) {
	var mywidht = window.screen.width - 50;
	var myheight = window.screen.height - 120;
	var html = "";
	
	fapLog("monitor resolution: " + mywidht + ":" + myheight);
	
	if (type=="image"){
		html="<table id='overlay'><tbody><tr><td><img src='" + data[0].url + "' style='width:auto; hight:100%; max-height:" + myheight +"px; max-width:" + mywidht + "px'></td></tr></tbody></table>";
	}
	if (type=="video"){
		html="<a id='overlay' href='" + data[0].url + "'>Video Link</a>";
	}
	if (type=="images"){
		html = "<table id='overlay'><tbody><tr><td>";
		data.forEach(function(value){
			html += value + "<br>";
		});
		html += "</td></tr></tbody></table>";
		
	}
	if (type=="videos"){
		
	}
    $(html).css({
        "position": "fixed",
        "top": 0,
        "left": 0,
        "width": "90%",
        "height": "900px",
        "background-color": "rgba(0,0,0,.5)",
        "z-index": 10000,
        "vertical-align": "middle",
        "text-align": "center",
        "color": "#fff",
        "font-size": "30px",
        "font-weight": "bold",
		"overflow": "hidden",
        "cursor": "auto"
    }).appendTo("body");
}

function sneakyXHR(url, cb, method, headers) {
    method = method || "GET";
	
	fapLog("sneaky requesting: " + url);
	
    setTimeout(function() {
        GM_xmlhttpRequest({
            method: method,
            'url': url,
            headers: $.extend({}, {
                'User-agent': 'Mozilla/4.0',
                'Accept': 'application/atom+xml,application/xml,text/xml',
                'Cookie': document.cookie
            }, headers || {}),
            onload: function(responseDetails) {
                var text = responseDetails.responseText;
                cb(text, responseDetails);
            }
        });
    }, 1);
}

//function to parallelize the findImageSource function
function loopFindImageSource(doneTask, value) {
	sp.findImgSrc(value, function(src){
		data = [src];
		imagesUrl.push(data[0].url);
		doneTask();
	});
}

//helper function for parralelize functions
function parralelizeTask(arr, fn, done) {
	fapLog("parralelizeTask: arr= " + arr);
	var total = arr.length;
	fapLog("parralelizeTask: arr.lenght= " + total)
	doneTask = function(){
		if (--total === 0){
			done();
		}
	};
	arr.forEach(function(value){
		fn(doneTask, value);
	});
}