PM Username flags

Affiche le drapeau du pays à côté des pseudos

スクリプトをインストールするには、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         PM Username flags
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Affiche le drapeau du pays à côté des pseudos
// @author       Danatru
// @match        https://platesmania.com/*
// @grant        GM_xmlhttpRequest
// @connect      https://platesmania.com/*
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const JSON_URL = "https://gist.githubusercontent.com/danatro/5b0e938537862ff628501b580d36a2db/raw/2e7f9866317a3ba581c5182ad583efe5b217da89/pm.json";
    let countryMap = {};

    function getFlagImg(code) {
        if (!code || code.length !== 2) return "";
        const lower = code.toLowerCase();
        return `https://flagcdn.com/w20/${lower}.png`;
    }

    function addFlags() {
        const players = document.querySelectorAll('a[href^="/user"]');

        players.forEach(player => {
            if (player.dataset.flagAdded) return;

            const pseudo = player.textContent.trim();
            const countryCode = countryMap[pseudo];

            if (countryCode) {
                const img = document.createElement("img");
                img.src = getFlagImg(countryCode);
                img.alt = countryCode;
                img.style.width = "24px";
                img.style.height = "18px";
                img.style.marginLeft = "6px";
                img.style.verticalAlign = "middle";

                player.appendChild(img);
                player.dataset.flagAdded = "true";
            }
        });
    }

    function observeDOM() {
        const observer = new MutationObserver(() => {
            addFlags();
        });

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

    function loadJSON() {
        GM_xmlhttpRequest({
            method: "GET",
            url: JSON_URL,
            onload: function(response) {
                try {
                    countryMap = JSON.parse(response.responseText);
                    addFlags();
                } catch (e) {
                    console.error("Erreur JSON:", e);
                }
            }
        });
    }

    loadJSON();
    observeDOM();

})();