Hide Signatures on IGN Boards

Hide Signatures on IGNBoards

目前为 2024-07-17 提交的版本。查看 最新版本

// ==UserScript==
// @name         Hide Signatures on IGN Boards
// @namespace    https://www.ignboards.com/members/magof.5211856/
// @version      0.1
// @author       Magof
// @description  Hide Signatures on IGNBoards
// @match        https://www.ignboards.com/threads/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    // Function to hide a user's signature in all posts in the thread
    function hideUserSignature(user) {
        var posts = document.querySelectorAll('.message');
        posts.forEach(function(post) {
            var authorElement = post.querySelector('.message-userExtras');
            var authorText = authorElement ? authorElement.textContent.trim() : '';
            var postUser = authorText.split(',')[0];
            if (postUser === user) {
                var signature = post.querySelector('.message-signature');
                if (signature) {
                    signature.style.display = 'none';
                    var button = post.querySelector('.signature-toggle-button');
                    if (button) {
                        button.innerHTML = '<i class="fas fa-eye"></i>'; // Eye icon
                        button.title = 'Show this user\'s signature';
                    }
                }
            }
        });
    }

    // Function to show a user's signature in all posts in the thread
    function showUserSignature(user) {
        var posts = document.querySelectorAll('.message');
        posts.forEach(function(post) {
            var authorElement = post.querySelector('.message-userExtras');
            var authorText = authorElement ? authorElement.textContent.trim() : '';
            var postUser = authorText.split(',')[0];
            if (postUser === user) {
                var signature = post.querySelector('.message-signature');
                if (signature) {
                    signature.style.display = 'block';
                    var button = post.querySelector('.signature-toggle-button');
                    if (button) {
                        button.innerHTML = '<i class="fas fa-eye-slash"></i>'; // Eye slash icon
                        button.title = 'Hide this user\'s signature';
                    }
                }
            }
        });
    }

    // Function to toggle between hiding and showing the signature in all posts in the thread and update the button icon
    function toggleUserSignature(user) {
        var hiddenUsers = JSON.parse(GM_getValue('hiddenUsers', '[]'));
        var index = hiddenUsers.indexOf(user);
        if (index === -1) {
            hiddenUsers.push(user);
            GM_setValue('hiddenUsers', JSON.stringify(hiddenUsers));
            hideUserSignature(user);
        } else {
            hiddenUsers.splice(index, 1);
            GM_setValue('hiddenUsers', JSON.stringify(hiddenUsers));
            showUserSignature(user);
        }
    }

    // Function to create and add the signature toggle buttons to the posts
    function addButtons() {
        var posts = document.querySelectorAll('.message');
        posts.forEach(function(post) {
            var signature = post.querySelector('.message-signature');
            if (signature) {
                var authorElement = post.querySelector('.message-userExtras');
                var authorText = authorElement ? authorElement.textContent.trim() : '';
                var user = authorText.split(',')[0];
                var button = document.createElement('button');
                button.innerHTML = '<i class="fas fa-eye-slash"></i>'; // Eye slash icon (initially hidden)
                button.title = 'Hide this user\'s signature';
                button.classList.add('signature-toggle-button');
                button.classList.add('button--link');
                button.classList.add('button');
                button.classList.add('rippleButton');
                button.addEventListener('click', function() {
                    toggleUserSignature(user);
                });
                var avatar = post.querySelector('.message-avatar');
                if (avatar) {
                    avatar.parentNode.appendChild(button);
                }
            }
        });
    }

    // Function to check and hide the signatures of previously hidden users
    function hideSavedUsers() {
        var hiddenUsers = JSON.parse(GM_getValue('hiddenUsers', '[]'));
        hiddenUsers.forEach(function(user) {
            hideUserSignature(user);
        });
    }

    // Add the buttons and check saved preferences when the page finishes loading
    window.addEventListener('load', function() {
        addButtons();
        hideSavedUsers();
    });

    // CSS styles
    GM_addStyle(`
        .signature-toggle-button {
            margin-left: 50px;
            padding: 5px;
            background-color: transparent;
            border: none;
            cursor: pointer;
        }
        .signature-toggle-button:hover {
            background-color: rgba(0, 0, 0, 0.1);
        }
        .signature-toggle-button i {
            font-size: 1.2em;
        }
    `);

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址