Wowhead Model ID

Extract model ID from wowhead pages

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

Advertisement:

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

})();