OGLight - Ostats Link

Aggiunge il link Ostats nella barra dei link in alto a destra, accanto agli altri link OGLight

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         OGLight - Ostats Link
// @namespace    https://greasyfork.org/users/nicolagalassi
// @version      1.0
// @description  Aggiunge il link Ostats nella barra dei link in alto a destra, accanto agli altri link OGLight
// @author       galax
// @match        https://*.ogame.gameforge.com/game/index.php*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function addOstatsLink() {
        const linkBar = document.querySelector('div.fright.textRight');
        if (!linkBar || linkBar.querySelector('.ostats-link')) return;

        const mmorpgLink = linkBar.querySelector('a[href*="mmorpg-stat.eu"]');
        if (!mmorpgLink) return;

        const playerMatch = mmorpgLink.href.match(/ftr=(\d+)\.dat/);
        if (!playerMatch) return;

        const universe = window.location.hostname.split('.')[0];
        const playerId = playerMatch[1];
        const ostatsUrl = `https://ostats.eu/universes/${universe}/player/${playerId}`;

        const link = document.createElement('a');
        link.href = ostatsUrl;
        link.target = '_blank';
        link.textContent = 'Ostats';
        link.className = 'ostats-link';

        linkBar.appendChild(document.createTextNode('\n| '));
        linkBar.appendChild(link);
    }

    // OGLight inietta i propri link dopo il caricamento del DOM: aspettiamo che il link
    // mmorpg-stat (marker affidabile dell'iniezione OGLight) compaia nel div
    const observer = new MutationObserver(() => {
        const bar = document.querySelector('div.fright.textRight');
        if (bar && bar.querySelector('a[href*="mmorpg-stat.eu"]')) {
            observer.disconnect();
            addOstatsLink();
        }
    });

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