Fort Presence

Fort presence script for The West

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

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

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.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

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!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

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

// ==UserScript==
// @name         Fort Presence
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Fort presence script for The West
// @author       Claw
// @license MIT
// @match        https://*.the-west.ro/game.php*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    setTimeout(() => {
        console.log("loaded")
        async function getFortProps(fortID) {
            return new Promise((resolve, reject) => {
                Ajax.remoteCallMode('fort_battlepage', 'index', { fort_id: fortID }, function (r) {
                    if (r.error) {
                        console.error(r.error);
                        reject(r.error);
                        return;
                    }
                    resolve(r);
                });
            });
        }

        async function getPresentPlayers(x, y) {
            return new Promise((resolve, reject) => {
                console.log(x,y);
                Ajax.remoteCallMode('players', 'get_data', {x:x,y:y}, function (r) {
                    console.log(r);
                    if (r.error) {
                        console.log(r.error);
                        reject(r.error);
                        return;
                    }
                    resolve(r.players);
                });
            });
        }

        let notificationBattle = document.querySelector('.fort_battle_notification');
        notificationBattle.addEventListener('click', async function(event) {
            var notificationClasses = notificationBattle.getAttribute('class');
            const fortID = notificationClasses.match(/\d+/g)[0];
            console.log(fortID);

            try {
                const fort = await getFortProps(fortID);
                var enroledPlayers = fort.playerlist;
                var fortCoords = fort.fortCoords;

                if (fortCoords) {
                    console.log("coords",fortCoords);
                    var presentPlayers = await getPresentPlayers(fortCoords.x, fortCoords.y);

                    var enroledPlayerNames = enroledPlayers.map(player => player.name);
                    var presentPlayerNames = presentPlayers.map(player => player.name);

                    // Find intersection
                    var alliedPresentPlayers = enroledPlayerNames.filter(name => presentPlayerNames.includes(name));

                    let paragraph = document.createElement('p');
                    paragraph.textContent="La fort: " + alliedPresentPlayers.length;
                    let anchor= document.querySelector('.show_players');
                    anchor.parentElement.insertBefore(paragraph, anchor.nextSibling);
                } else {
                    console.error('Fort coordinates are undefined.');
                }
            } catch (error) {
                console.error('Error fetching data:', error);
            }
        });
    }, 3000);
})();