E-H Visited

Marks visited galleries.

Versione datata 19/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\/.*/
// @grant          GM_setValue
// @grant          GM_getValue
// @icon           https://i.imgur.com/pMMVGRx.png
// @version        1.1
// ==/UserScript==
//fork of https://sleazyfork.org/en/scripts/22270-exvisited

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:#222 !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 = $(".it5");
	var thumb = $(".id1");

	// regular list
	if (list.length > 0) {
		$("table.itg tbody tr:first-child()").append("<th>Last viewed</th>");
		$("div.it5").css("max-width", "570px");
		for (i = 0; i < list.length; i++) {

			(function (tmp) {
				var d = $(list[tmp]).find("a").attr("href").split("/");
				var galleryId = d[4] + "." + d[5];

				if (vis["data"][galleryId] != undefined) {
					var d = new Date(vis["data"][galleryId]);
					$(list[tmp]).parent().parent().parent().addClass("gv");
					$(list[tmp]).parent().parent().parent().append("<td style='font-size:9px; text-align:left; width:80px'>" + timeDifference(Date.now(), vis["data"][galleryId]) + "<br>" + d.getHours().pad0(2) + ":" + d.getMinutes().pad0(2) + " " + d.getDate() + "/" + (d.getMonth() + 1) + "</td>");
				} else {
					$(list[tmp]).parent().parent().parent().append("<td style='font-size:9px; text-align:left; width:80px'>Never</td>");
				}

			})(i);

		}
	}

	// thumbnails
	if (thumb.length > 0) {
		for (var i = 0; i < thumb.length; i++) {
			var d = $(thumb[i]).find("a").attr("href").split("/");
			var c = d[4] + "." + d[5];
			$(thumb[i]).css("padding-bottom", "25px");
			if (vis["data"][c] != undefined) {
				var d = new Date(vis["data"][c]);
				$(thumb[i]).addClass("gv");
				$(thumb[i]).append("<br><div style='font-size:11px; margin-top:-5px; text-align:center'>" + timeDifference(Date.now(), vis["data"][c]) + " (" + d.getHours().pad0(2) + ":" + d.getMinutes().pad0(2) + " " + d.getDate() + "/" + (d.getMonth() + 1) + ")</div>")
			}
		}
	}
}

$(function () {
	$("<style>.gv{" + 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'>" + len + " visited galleries, " + " hidden. <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 visited gallery 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:\nCustom visited gallery CSS.", css);
			if (c) {
				GM_setValue("css", c);
				location.reload();
			}
		});

		ExHide();
	}
});