Wowhead Model ID

Extract model ID from wowhead pages

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Advertisement:

// ==UserScript==
// @name         Wowhead Model ID
// @namespace    blep
// @version      1.0
// @description  Extract model ID from wowhead pages
// @match        https://www.wowhead.com/*
// @author       Blehssing
// @grant        none
// @license      Blehssing
// ==/UserScript==

(function () {
    'use strict';

    const src = document.documentElement.innerHTML;

    const patterns = [
        /displayId\s*=\s*(\d+)/,
        /"npcmodel"\s*:\s*(\d+)/,
        /displayId"\s*:\s*(\d+)/,
    ];

    let displayId = null;
    for (const re of patterns) {
        const m = src.match(re);
        if (m) { displayId = m[1]; break; }
    }

    const panel = document.createElement('div');
    panel.id = 'igm-displayid-panel';
    Object.assign(panel.style, {
        position:     'fixed',
        top:          '80px',
        right:        '20px',
        zIndex:       '2147483647',
        background:   '#1a1a2e',
        border:       '1px solid #4a4a8a',
        borderRadius: '8px',
        padding:      '10px 14px 10px 14px',
        fontFamily:   'monospace',
        fontSize:     '13px',
        color:        '#e0e0ff',
        boxShadow:    '0 4px 18px rgba(0,0,0,0.7)',
        userSelect:   'none',
        minWidth:     '180px',
        cursor:       'move',
    });

    const label = document.createElement('div');
    label.textContent = 'Display ID';
    Object.assign(label.style, {
        fontSize:     '10px',
        color:        '#8888bb',
        marginBottom: '4px',
        letterSpacing:'0.08em',
        textTransform:'uppercase',
    });

    const idLine = document.createElement('div');
    Object.assign(idLine.style, {
        display:    'flex',
        alignItems: 'center',
        gap:        '8px',
    });

    const idText = document.createElement('span');
    idText.textContent = displayId ?? '—';
    Object.assign(idText.style, {
        fontSize:   '20px',
        fontWeight: 'bold',
        color:      displayId ? '#7ec8e3' : '#666',
        flex:       '1',
    });

    const copyBtn = document.createElement('button');
    copyBtn.textContent = '⎘';
    copyBtn.title = 'Copier';
    Object.assign(copyBtn.style, {
        background:   '#2a2a5e',
        border:       '1px solid #5555aa',
        borderRadius: '4px',
        color:        '#aaaaff',
        cursor:       'pointer',
        fontSize:     '15px',
        lineHeight:   '1',
        padding:      '2px 6px',
        transition:   'background 0.15s',
    });

    if (!displayId) copyBtn.disabled = true;

    copyBtn.addEventListener('click', () => {
        if (!displayId) return;
        navigator.clipboard.writeText(displayId).then(() => {
            copyBtn.textContent = '✓';
            copyBtn.style.color = '#66ffaa';
            setTimeout(() => {
                copyBtn.textContent = '⎘';
                copyBtn.style.color = '#aaaaff';
            }, 1200);
        });
    });

    idLine.appendChild(idText);
    idLine.appendChild(copyBtn);
    panel.appendChild(label);
    panel.appendChild(idLine);

    if (!displayId) {
        const warn = document.createElement('div');
        warn.textContent = 'Introuvable sur cette page';
        Object.assign(warn.style, { fontSize: '10px', color: '#ff8888', marginTop: '4px' });
        panel.appendChild(warn);
    }

    document.body.appendChild(panel);

    let ox = 0, oy = 0, dragging = false;

    panel.addEventListener('mousedown', (e) => {
        if (e.target === copyBtn) return;
        dragging = true;
        ox = e.clientX - panel.getBoundingClientRect().left;
        oy = e.clientY - panel.getBoundingClientRect().top;
        e.preventDefault();
    });

    document.addEventListener('mousemove', (e) => {
        if (!dragging) return;
        panel.style.left   = (e.clientX - ox) + 'px';
        panel.style.top    = (e.clientY - oy) + 'px';
        panel.style.right  = 'auto';
    });

    document.addEventListener('mouseup', () => { dragging = false; });

})();