E-H Visited

Marks visited galleries.

Versione datata 20/03/2019. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name           E-H Visited
// @description    Marks visited galleries.
// @author         Hen Tie
// @homepage       https://hen-tie.tumblr.com/
// @namespace      https://greasyfork.org/en/users/8336
// @include        /https?:\/\/(e-|ex)hentai\.org\/.*/
// @require        https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js
// @grant          GM_setValue
// @grant          GM_getValue
// @icon           https://i.imgur.com/pMMVGRx.png
// @version        2.2
// ==/UserScript==
//fork of https://sleazyfork.org/en/scripts/22270-exvisited
//updated to work with March 2019 layout update

if (typeof (Storage) == "undefined") {
	alert("E-H Visited:\nYour browser does not support localStorage :(");
}

var storageName = "ehVisited";
var url = document.URL;
var sto = localStorage.getItem(storageName) ? localStorage.getItem(storageName) : '{"data":{}}';
var vis = JSON.parse(sto);
var spl = url.split("/");
var d1 = spl[3]
var d2 = spl[4];
var d3 = spl[5];
var css = GM_getValue("css") ? GM_getValue("css") : "background:rgba(2, 129, 255, .2) !important;";


vis["data"] = !vis["data"] ? Array() : vis["data"];

// Helper stuff
if (!Date.now) {
	Date.now = function () {
		return new Date().getTime();
	};
}

Number.prototype.pad0 = function (length) {
	var result = this.toString();
	while (result.length < length) result = "0" + result;
	return result;
}

Object.size = function (obj) {
	var size = 0,
		key;
	for (key in obj) {
		if (obj.hasOwnProperty(key)) size++;
	}
	return size;
};

function ExStore() {
	var c = d2 + "." + d3;
	vis["data"][c] = Date.now();
	localStorage.setItem(storageName, JSON.stringify(vis));
}

function timeDifference(current, previous) {

	var msPerMinute = 60 * 1000;
	var msPerHour = msPerMinute * 60;
	var msPerDay = msPerHour * 24;
	var msPerMonth = msPerDay * 30;
	var msPerYear = msPerDay * 365;

	var elapsed = current - previous;

	if (elapsed < msPerMinute) {
		return Math.round(elapsed / 1000) + " seconds ago";
	} else if (elapsed < msPerHour) {
		return Math.round(elapsed / msPerMinute) + " minutes ago";
	} else if (elapsed < msPerDay) {
		return Math.round(elapsed / msPerHour) + " hours ago";
	} else if (elapsed < msPerMonth) {
		return Math.round(elapsed / msPerDay) + " days ago";
	} else if (elapsed < msPerYear) {
		return Math.round(elapsed / msPerMonth) + " months ago";
	} else {
		return Math.round(elapsed / msPerYear) + " years ago";
	}
}

function ExHide() {

	var list = $("table.itg>tbody>tr");
	var thumb = $(".itg .gl1t");
	var gid;
	var d;
	var galleryId;

	// list views
	if (list.length > 0) {
		if ($('.gl1e').length) { //extended
			for (i = 0; i < list.length; i++) {
				gid = $(list[i]).find(".glname a").attr("href").split("/");
				galleryId = gid[4] + "." + gid[5];
				if (vis["data"][galleryId] != undefined) {
					d = new Date(vis["data"][galleryId]);
					$(list[i]).addClass("eh-visited");
					$(list[i]).find('.gldown').prepend("<div class='eh-visited-time'>" + timeDifference(Date.now(), vis["data"][galleryId]) + "<br>(" + d.getHours().pad0(2) + ":" + d.getMinutes().pad0(2) + " " + d.getDate() + "/" + (d.getMonth() + 1) + ")</div>")
				}
			}
		} else if ($('.gl1c').length) {
			$('table.itg tbody>tr:first-child').append('<th>Visited</th>');
			for (i = 1; i < list.length; i++) {
				gid = $(list[i]).find(".glname a").attr("href").split("/");
				galleryId = gid[4] + "." + gid[5];
				if (vis["data"][galleryId] != undefined) {
					d = new Date(vis["data"][galleryId]);
					$(list[i]).addClass("eh-visited");
					$(list[i]).append('<td class="eh-visited-cell"><span class="eh-visited-icon-compact" title="'+timeDifference(Date.now(), vis["data"][galleryId]) + "\n" + d.getHours().pad0(2) + ":" + d.getMinutes().pad0(2) + " " + d.getDate() + "/" + (d.getMonth() + 1)+'">&#128065Yes</span></td>');
				} else {
					$(list[i]).append('<td></td>');
				}
			}
		} else {
			for (i = 1; i < list.length; i++) {
				gid = $(list[i]).find(".glname a").attr("href").split("/");
				galleryId = gid[4] + "." + gid[5];
				if (vis["data"][galleryId] != undefined) {
					d = new Date(vis["data"][galleryId]);
					$(list[i]).addClass("eh-visited");
					$(list[i]).find('.gl2m').append('<span class="eh-visited-icon-minimal" title="'+timeDifference(Date.now(), vis["data"][galleryId]) + "\n" + d.getHours().pad0(2) + ":" + d.getMinutes().pad0(2) + " " + d.getDate() + "/" + (d.getMonth() + 1)+'">&#128065</span>')
				}
			}
		}
	}
	// thumbnail view
	if (thumb.length > 0) {
		for (var i = 0; i < thumb.length; i++) {
			gid = $(thumb[i]).find(".glname a").attr("href").split("/");
			var c = gid[4] + "." + gid[5];
			if (vis["data"][c] != undefined) {
				d = new Date(vis["data"][c]);
				$(thumb[i]).addClass("eh-visited");
				$(thumb[i]).children('.gl5t').after("<div class='eh-visited-time'>" + timeDifference(Date.now(), vis["data"][c]) + " (" + d.getHours().pad0(2) + ":" + d.getMinutes().pad0(2) + " " + d.getDate() + "/" + (d.getMonth() + 1) + ")</div>")
			}
		}
	}
}

$(function () {
	$("<style>.gl3e>div:nth-child(6){left:unset;width:100%;text-align:center;}.gl2m{width:144px;}.gl2m>div:nth-child(3){left:unset;right:4px;top:7px;}.eh-visited-icon-minimal{width:1em;line-height:1;font-size:15px;top:7px;right:23px;position:absolute;}.eh-visited-icon-compact{border-bottom:1px currentColor dotted;}.eh-visited-time{text-align:center;}.eh-visited{" + css + "}" + "modal button:hover{cursor:pointer;}modal button{all:unset;position:absolute;top:-1.5em;padding:.25em;line-height:1;color:#fff;text-shadow:0 0 6px #000,0 0 2px #000;}modal textarea:enabled:focus,modal textarea:enabled:hover{background:unset;}modal textarea{all:initial;font:inherit;word-break:break-word;overflow:auto;height:100%;width:100%;}modal{display:flex;align-items:center;justify-content:center;position:fixed;z-index:999;padding:.5em;box-sizing:border-box;width:600px;height:300px;left:50%;top:50%;line-height:1.3;font-size:18px;font-weight:400;font-family:sans-serif;border-radius:0.5em;opacity:0;color:transparent;transform:translate(-50%,0);background:rgba(255,255,255,0);box-shadow:0 0 0 rgba(0,0,0,0)}.animated{animation:slideUp 800ms cubic-bezier(0.645, 0.045, 0.355, 1) both, dropShadow 800ms cubic-bezier(0.55, 0.055, 0.675, 0.19) both, textColor 400ms cubic-bezier(0.645, 0.045, 0.355, 1) 400ms both}@keyframes slideUp{100%{transform:translate(-50%,-150px);opacity:1;background:rgba(255,255,255,1)}}@keyframes dropShadow{100%{box-shadow:0 3px 5px rgba(0, 0, 0, 0.1), 0 0 2px rgba(0, 0, 0, 0.1), 0 5px 15px rgba(0, 0, 0, 0.2)}}@keyframes textColor{100%{color:#000}}</style>").appendTo("head");
	if (d1 == "g") {
		ExStore();
	}
	if (d1.substr(0, 1) == "?" || d1.substr(0, 1) == "#" || d1.substr(0, 1) == "f" || d1.substr(0, 1) == "t" || !d1) {
		var len = Object.size(vis["data"]);
		$("#toppane").append("<div style='text-align:center'>Galleries visited: " + len + " (<a href='javascript:;' id='ExImport'>Import</a> / <a href='javascript:;' id='ExExport'>Export</a> / <a href='javascript:;' id='ExCss'>CSS</a>)</div>");

		$("#ExExport").click(function () {
			var e = "";
			for (var d in vis["data"]) {
				e += d + ":" + vis["data"][d] + ";";
			}
			if ($('modal').length) {
				$('modal').remove();
			}
			$('body').append("<modal class='animated'><textarea>" + e + "</textarea><button type='button'>Close</button></modal>");
		});

		$('body').on('click', 'modal button', function () {
			$('modal').remove();
		});

		$("#ExImport").click(function () {
			var c = prompt("E-H Visited:\nPaste exported data.");
			if (c) {
				var d = JSON.parse('{"data":{}}');
				var sp = c.split(";");
				for (var k in sp) {
					var s = sp[k].split(":");
					d["data"][s[0]] = parseInt(s[1]);
				}

				alert("Imported " + Object.size(d["data"]) + " entries.");
				localStorage.setItem(storageName, JSON.stringify(d))
				location.reload();

			}
		});

		$("#ExCss").click(function () {
			var c = prompt("E-H Visited:\nCSS to mark visited galleries. (enter a space for no styling)", css);
			if (c) {
				GM_setValue("css", c);
				location.reload();
			}
		});

		ExHide();
	}
});