Block New Player

No more s-tier post in General Discussion

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Block New Player
// @namespace    microbes.torn.blocknewplayer
// @version      0.1
// @description  No more s-tier post in General Discussion
// @author       Microbes
// @match        https://www.torn.com/forums.php*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// @license      MIT
// ==/UserScript==

let UID_LIMIT = parseInt(localStorage.getItem(`block_new_user_uid_limit`) || 3100000);

(function() {
    'use strict';

    // Start mutation observsor
    let currentUrl = window.location.href;

    function onUrlChange() {
        if (window.location.href == 'https://www.torn.com/forums.php' || window.location.href == 'https://www.torn.com/forums.php#/p=main') {
            waitForElementToExist('#updates').then((elm) => {
                $('#updates .update-wrap').prepend(`
                    <div class="dashboard w3" role="heading" aria-level="6">
                        <div class="title-black title-toggle active" role="button" aria-expanded="false">
                            <i class="arrow"></i>
                            Block New User Topic
                        </div>
                        <ul class="panel fm-list cont-gray bottom-round">
                            <li class="rating w3">
                                <label class='bold' for='block_uid_limit'>Starting From:</label> <input id="block_uid_limit" class="input-text" type="number" data-lpignore="true" value="${UID_LIMIT}">
                            </li>
                        </ul>
                    </div>

                    <hr class="delimiter-999 m-top10 m-bottom10">
                `);

                $('#block_uid_limit').change(() => {
                    UID_LIMIT = $('#block_uid_limit').val()
                    localStorage.setItem(`block_new_user_uid_limit`, UID_LIMIT);
                });
            });
        }
        else {
            waitForElementToExist('.forums-committee-wrap .pagination').then((elm) => {
                $('.starter .user').each((i, element) => {
                    var uid = $(element).prop('href').split('=')[1]

                    if (uid >= UID_LIMIT) {
                        $(element).parent().parent().parent().parent().remove();
                    }
                });
            });
        }
    }

    const observer = new MutationObserver(function(mutations) {
        if (currentUrl !== window.location.href) {
            currentUrl = window.location.href;
            onUrlChange();
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

    // Initial call
    onUrlChange();
})();

function waitForElementToExist(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(() => {
            if (document.querySelector(selector)) {
                resolve(document.querySelector(selector));
                observer.disconnect();
            }
        });

        observer.observe(document.body, {
            subtree: true,
            childList: true,
        });
    });
}