PM Username flags

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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();

})();