E-H Visited

Marks visited galleries.

Verze ze dne 19. 03. 2019. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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.0
// ==/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: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;

	// minimal and compact list
	if (list.length > 0) {

		if ($('.gl1c, .gl1m').length) {
			$('table.itg tbody>tr:first-child').append('<th>Visited</th>');
		}
		if ($('.gl1e').length) {
			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('.gl3e').append("<div class='eh-visited-time'>" + timeDifference(Date.now(), vis["data"][galleryId]) + " (" + d.getHours().pad0(2) + ":" + d.getMinutes().pad0(2) + " " + d.getDate() + "/" + (d.getMonth() + 1) + ")</div>")
				}
			}
		} 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]).append('<td class="eh-visited-cell"><span class="eh-visited-icon" 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>');
				}
			}
		}
	}


	// thumbnails
	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>.eh-visited-icon{border-bottom:1px currentColor dotted;}.eh-visited-time{text-align:center;margin-bottom:3px;}.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 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();
	}
});