Bitcointalk Mention Autocomplete

a tool for Bitcointalk Mention Autocomplete

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/593467/1915978/Bitcointalk%20Mention%20Autocomplete.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Bitcointalk Mention Autocomplete
// @namespace    https://greasyfork.org/users/gakjahat
// @version      0.1
// @description  Fitur autocomplete mention untuk username Bitcointalk langsung dari thread tanpa database.
// @author       gakjahat
// @match        https://bitcointalk.org/*
// @include      https://bitcointalk.org/*
// @grant        none
// ==UserScript==

(function() {
    'use strict';

    function getThreadUsernames() {
        const userLinks = document.querySelectorAll('td.postercol b a, .mirrored b a');
        const usernames = new Set();

        userLinks.forEach(link => {
            if (link.textContent) {
                usernames.add(link.textContent.trim());
            }
        });

        return Array.from(usernames);
    }

    const textarea = document.querySelector('textarea[name="message"]');

    if (textarea) {
        textarea.addEventListener('input', () => {
            const text = textarea.value;
            const cursorPosition = textarea.selectionStart;
            const lastWord = text.slice(0, cursorPosition).split(/\s+/).pop();

            if (lastWord && lastWord.startsWith('@')) {
                const query = lastWord.slice(1).toLowerCase();
                const availableUsers = getThreadUsernames();
                const matches = availableUsers.filter(user =>
                    user.toLowerCase().startsWith(query)
                );
                console.log('Rekomendasi Username:', matches);
            }
        });
    }
})();