E/Ex-Hentai Exclude Uploader Button

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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();
    }
})();