Greasy Fork is available in English.

OGLight - Ostats Link

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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 });
})();