Post
Topic
Board Project Development
Re: Hiding gambling in bitcointalk
by
rollinsweet
on 04/02/2025, 12:18:30 UTC
Although it is probably enough to just put the gambling section on hide

this is gem for me, thanks.

I have added a toggle (ON/OFF) near the nickname at the top of the site. Also, there is a pencil icon to add or delete keywords that will be blocked in signatures and small text.
Additionally, I found a way to hide the small text message without affecting the entire block.

Code:
// ==UserScript==
// @name         Bitcointalk Gambling Signature Blocker
// @namespace    https://bitcointalk.org/
// @version      1.1
// @description  Hides gambling-related signatures and personal text on Bitcointalk + filter control & keyword editor
// @author       YourName
// @match        https://bitcointalk.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const defaultKeywords = [
        'casino', 'bet', 'gambling', 'poker', 'slots', 'stake', '1xbit',
        'wager', 'bonus', 'free spins', 'sportsbook', 'betting', 'jackpot',
        'duelbits'
    ];
    let gamblingKeywords = JSON.parse(localStorage.getItem('gamblingKeywords')) || defaultKeywords;
    let isFilterActive = JSON.parse(localStorage.getItem('filterActive')) ?? true;

    function hideGamblingContent() {
        if (!isFilterActive) return;

        document.querySelectorAll('.signature, .quote, .smalltext').forEach(el => {
            if (gamblingKeywords.some(keyword => el.innerText.toLowerCase().includes(keyword))) {
                el.style.display = 'none';
            }
        });

        document.querySelectorAll('.signature a, .smalltext a').forEach(link => {
            if (gamblingKeywords.some(keyword => link.href.toLowerCase().includes(keyword))) {
                link.style.display = 'none';
            }
        });
    }

    function createNicknameControls() {
        const helloMemberSpan = document.getElementById('hellomember');
        if (!helloMemberSpan) return;

        // toggle button
        const toggleButton = document.createElement('button');
        toggleButton.textContent = isFilterActive ? 'Filter: ON' : 'Filter: OFF';
        toggleButton.style.marginLeft = '10px';
        toggleButton.style.padding = '2px 8px';
        toggleButton.style.fontSize = '12px';
        toggleButton.style.cursor = 'pointer';
        toggleButton.style.border = '1px solid #ccc';
        toggleButton.style.background = isFilterActive ? '#28a745' : '#dc3545';
        toggleButton.style.color = 'white';
        toggleButton.style.borderRadius = '5px';

        toggleButton.addEventListener('click', () => {
            isFilterActive = !isFilterActive;
            localStorage.setItem('filterActive', JSON.stringify(isFilterActive));
            toggleButton.textContent = isFilterActive ? 'Filter: ON' : 'Filter: OFF';
            toggleButton.style.background = isFilterActive ? '#28a745' : '#dc3545';
            hideGamblingContent();
        });

        // pencil
        const editButton = document.createElement('button');
        editButton.innerHTML = '✏️';
        editButton.style.marginLeft = '5px';
        editButton.style.padding = '2px 6px';
        editButton.style.fontSize = '12px';
        editButton.style.cursor = 'pointer';
        editButton.style.border = '1px solid #ccc';
        editButton.style.background = '#007bff';
        editButton.style.color = 'white';
        editButton.style.borderRadius = '5px';

        editButton.addEventListener('click', () => {
            const userInput = prompt('Edit blocked keywords (comma separated):', gamblingKeywords.join(', '));
            if (userInput !== null) {
                gamblingKeywords = userInput.split(',').map(word => word.trim().toLowerCase()).filter(word => word !== '');
                localStorage.setItem('gamblingKeywords', JSON.stringify(gamblingKeywords));
                hideGamblingContent();
                alert('Filter list updated!');
            }
        });

        helloMemberSpan.appendChild(toggleButton);
        helloMemberSpan.appendChild(editButton);
    }

    hideGamblingContent();

    const observer = new MutationObserver(hideGamblingContent);
    observer.observe(document.body, { childList: true, subtree: true });

    createNicknameControls();
})();