E-Hentai & ExHentai Viewed gallery fade and tag hider

Fades Viewed gallerys and Remove Flagged Tags on e-hentai and exhentai

Fra 15.12.2017. Se den seneste versjonen.

// ==UserScript==
// @name        E-Hentai & ExHentai Viewed gallery fade and tag hider
// @namespace   https://greasyfork.org/users/25356
// @description Fades Viewed gallerys and Remove Flagged Tags on e-hentai and exhentai
// @version     2

// @include     https://exhentai.org/*
// @include     https://e-hentai.org/*

// @grant		GM_getValue
// @grant		GM_setValue
// @grant       GM_listValues

// @run-at 		document-start

// @require		https://code.jquery.com/jquery-git.min.js
// @author      CoLdAsIcE
// ==/UserScript==

(function () {

    function isGalVisited(gid) {

        var md = GM_getValue("g_" + gid, 0);
        if (md == 1) {
            return true;
        }
        return false;
    }

    function visitGal(gid) {

        if (!isGalVisited(gid)) {
            GM_setValue("g_" + gid, 1);
        }
    }

    function saveViewedGal() {

        if (document.URL.match(/^https:\/\/(e-|e[^-])hentai\.org\/g\/.*$/)) { //gallery case
            console.log("here");
            //record visited galleries to local DB
            var gal_idx = document.URL.match(/^https:\/\/(?:e-|e[^-])hentai\.org\/g\/(\d*)\/.*$/);

            if (!isNaN(gal_idx[1])) {

                var gal_id = parseInt(gal_idx[1], 10);
                visitGal(gal_id);
                console.log(GM_listValues().length);
            }
        }
    }

    function fadeThumb($tag) {

        $p = $tag.closest('.id1'); //also fade title in gallery

        var $alpha = parseFloat(0.2);
        if (isNaN($alpha))
            $alpha = '0.2';

        $p.css('opacity', $alpha);

        $p.hover(
            function () {
                $(this).stop().fadeTo('fast', 1);
            },
            function () {
                $(this).stop().fadeTo('fast', $alpha);
            }
        );
    }

    function fadeViewedGal() {
        $('.itg > div.id1').each(function (ix) {
            $(this).find(".id44").each(function (index) {
                if (document.URL.match(/^https:\/\/(e-|e[^-])hentai\.org\/(?!s).*$/) && self == top) { //search / index case, exclude iframe
                    $tagContainer = $(this);
                    $div = $(this).closest('.id1');

                    var gal_href = $tagContainer.closest('.id1').find('div.id2 a').first().attr('href');

                    var gal_idx = gal_href.match(/^https:\/\/(?:e-|e[^-])hentai\.org\/g\/(\d*)\/.*$/);

                    if (!isNaN(gal_idx[1])) {
                        var gal_id = parseInt(gal_idx[1], 10);
                        $tagContainer.closest('.id1').find('.id2').addClass('vx');
                        if (isGalVisited(gal_id)) {
                            fadeThumb($tagContainer);

                        }
                    }
                }
            });
        });
    }

    function removeBadTags() {
        $('.itg > div.id1').each(function (ix) {

            $blankGif = $(this).find(".id3 img").attr('src');
            $image = $(this);
            if ($blankGif == "https://exhentai.org/img/blank.gif") {
                $image.hide();
            }
        });
    }

    function runEhpr() {

        saveViewedGal();
        fadeViewedGal();
        removeBadTags();
    }

    addEventListener('DOMContentLoaded', runEhpr, false);
})();