ExHentai Viewed gallery fade and tag hider

Fades Viewed gallerys and Remove Flagged Tags

As of 2017-12-13. See the latest version.

// ==UserScript==
// @name        ExHentai Viewed gallery fade and tag hider
// @namespace   https://greasyfork.org/users/25356
// @description Fades Viewed gallerys and Remove Flagged Tags
// @version     1.1

// @include     https://exhentai.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 insertGalidInDB() {
        
        if (document.URL.match(/^https:\/\/(g\.e-|e[^-])hentai\.org\/g\/.*$/)) { //gallery case
            //record visited galleries to local DB
            var gal_idx = document.URL.match(/^https:\/\/(?:g\.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 alphaThumb($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:\/\/(g\.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:\/\/(?:g\.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)) {
                            alphaThumb($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() {
        insertGalidInDB();
        fadeViewedGal();
        removeBadTags();
    }
    
    addEventListener('DOMContentLoaded', runEhpr, false);
})();