ExhTagHighlight

Highlight tags in gallery view according to 'My Tags' config in gallery for Exhentai and Ehentai

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         ExhTagHighlight
// @version      1.0
// @description  Highlight tags in gallery view according to 'My Tags' config in gallery for Exhentai and Ehentai
// @author       Caca ductile
// @match      https://exhentai.org/g/*
// @match      https://exhentai.org/mytags
// @match      https://e-hentai.org/g/*
// @match      https://e-hentai.org/mytags
// @license MIT
// @namespace https://greasyfork.org/users/979369
// ==/UserScript==

(function() {
    'use strict';

    const STORE_NAME = 'exhtaghighlight-settings';

    const exportMyTagsConfig = () => {
        const tagConfigs = document.querySelector("#usertags_outer");
        const config = {};
        for (const tagConfig of tagConfigs.children) {
            const tagLink = tagConfig.querySelector("a");
            if (!tagLink) continue;
            const tagName = tagLink.href;
            const tagValue = tagLink.firstChild.style.cssText;
            console.log(tagName, tagValue);
            config[tagName] = tagValue;
        }
        localStorage.setItem(STORE_NAME, JSON.stringify(config));
    };

    const appendExportButton = () => {
        document.querySelector("#tagsave").parentElement.insertAdjacentHTML('afterend', '<div><input type="button" id="tagExport" style="margin: 2px 2px 2px 4px;" value="Export"></div>');
        document.querySelector("#tagExport").addEventListener("click", exportMyTagsConfig);
    };

    const highlightTags = () => {
        const stringConfig = localStorage.getItem(STORE_NAME);
        if (!stringConfig) {
            console.warn("ExhTagHighlight : Go to 'My Tags' page and hit the export button to save tag config to cache in order for the script to work properly");
            return;
        }
        const config = JSON.parse(stringConfig);
        for (const [tag, tagValue] of Object.entries(config)) {
            const element = document.querySelector('#taglist a[href="' + tag + '"]');
            if (element) {
                element.parentElement.style = tagValue;
            }
        }
    };

    if (window.location.pathname === "/mytags" ) {
        appendExportButton();
    } else {
        highlightTags();
    }

})();