Wowhead Model ID

Extract model ID from wowhead pages

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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; });

})();