E/Ex-Hentai Exclude Uploader Button

Adds "exclude" button next to uploaders name on gallery page for quickly adding them to Excluded Uploaders list

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        E/Ex-Hentai Exclude Uploader Button
// @author      vodka
// @namespace   https://greasyfork.org/en/users/1392773
// @version     1.0
// @match       https://e-hentai.org/g/*
// @match       https://exhentai.org/g/*
// @icon        https://e-hentai.org/favicon.ico
// @description Adds "exclude" button next to uploaders name on gallery page for quickly adding them to Excluded Uploaders list
// @run-at      document-end
// @license     WTFPL
// ==/UserScript==

(function() {
    'use strict';

    const baseUrl = location.origin + '/uconfig.php';

    const uploaderLink = document.querySelector('#gdn a:first-child');
    if (!uploaderLink) return;

    const uploader = uploaderLink.textContent.trim();

    const button = document.createElement('button');
    button.textContent = 'Exclude';
    button.style.marginLeft = '5px';
    button.onclick = () => {
        if (confirm('Exclude ' + uploader + '?')) excludeUploader(uploader);
    };

    uploaderLink.parentNode.insertBefore(button, uploaderLink.nextSibling);

    function excludeUploader(uploader) {
        const xhr = new XMLHttpRequest();
        xhr.open('GET', baseUrl, true);
        xhr.onload = () => {
            if (xhr.status !== 200) return alert('Error loading settings');

            const parser = new DOMParser();
            const doc = parser.parseFromString(xhr.responseText, 'text/html');

            const excludedTextarea = doc.querySelector('textarea#xu');
            if (!excludedTextarea) return alert('Excluded Uploaders field not found');

            let current = excludedTextarea.value.trim().split('\n').map(s => s.trim()).filter(Boolean);
            if (!current.includes(uploader)) {
                current.push(uploader);
                excludedTextarea.value = current.join('\n');
            }

            const form = excludedTextarea.closest('form');
            if (!form) return alert('Form not found');

            const formData = new FormData(form);
            formData.append('apply', 'Apply');

            const postXhr = new XMLHttpRequest();
            postXhr.open('POST', baseUrl, true);
            postXhr.onload = () => {
                alert(postXhr.status === 200 ? 'Success' : 'Error');
            };
            postXhr.send(formData);
        };
        xhr.send();
    }
})();