Bitcointalk Mention Autocomplete

a tool for Bitcointalk Mention Autocomplete

لا ينبغي أن لا يتم تثبيت هذا السكريت مباشرة. هو مكتبة لسكبتات لتشمل مع التوجيه الفوقية // @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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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