block let user

屏蔽 lowendtalk 指定用户的帖子,支持点击用户名屏蔽

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         block let user
// @namespace    yournamespace
// @version      1.1
// @description  屏蔽 lowendtalk 指定用户的帖子,支持点击用户名屏蔽
// @author       ayasetan
// @match        https://lowendtalk.com/categories/offers*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 从存储中获取屏蔽用户列表,如果没有则使用默认空数组
    let blockedUsers = JSON.parse(GM_getValue('blockedUsers', '[]'));

    // 主功能:屏蔽帖子
    function hideBlockedUsers() {
        const items = document.querySelectorAll('.ItemDiscussion');  // 获取所有帖子的元素

        items.forEach(item => {
            const authorLink = item.querySelector('.DiscussionAuthor a');
            if (!authorLink) return;

            const username = authorLink.textContent.trim();

            if (blockedUsers.includes(username)) {
                item.style.display = 'none';  // 隐藏被屏蔽用户的帖子
            } else {
                // 添加点击事件监听器
                authorLink.addEventListener('click', function(e) {
                    e.preventDefault();
                    e.stopPropagation();

                    if (confirm(`是否要屏蔽用户 ${username} 的所有帖子?`)) {
                        if (!blockedUsers.includes(username)) {
                            blockedUsers.push(username);
                            GM_setValue('blockedUsers', JSON.stringify(blockedUsers));
                            alert(`已屏蔽用户 ${username}`);
                            hideBlockedUsers(); // 重新执行屏蔽
                        }
                    }
                });
            }
        });
    }

    // 初始执行
    hideBlockedUsers();


})();