PM Username flags

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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();

})();