User:Monster Domosed/common.js: Difference between revisions

No edit summary
No edit summary
Line 35: Line 35:


     function addQualityButton(container, viewer, lqUrl, hqUrl) {
     function addQualityButton(container, viewer, lqUrl, hqUrl) {
        if (!hqUrl || lqUrl === hqUrl) {
    if (!hqUrl || lqUrl === hqUrl) {
            return;
        return;
        }
    }
 
        const button = document.createElement('button');
    const button = document.createElement('button');
        button.className = 'mv-quality-toggle';
    button.className = 'mv-quality-toggle';
        button.type = 'button';
    button.type = 'button';
 
        const icon = document.createElement('img');
    const icon = document.createElement('img');
        icon.src = LQ_ICON;
    icon.src = LQ_ICON;
        icon.alt = '';
    icon.alt = '';
 
        button.appendChild(icon);
    button.appendChild(icon);
 
        const buttonSize = Math.max(
    const buttonSize = Math.max(
            28,
        28,
            Math.min(56, Math.round(container.offsetWidth * 0.14))
        Math.min(56, Math.round(container.offsetWidth * 0.14))
        );
    );
 
        button.style.width = buttonSize + 'px';
    button.style.width = buttonSize + 'px';
        button.style.height = buttonSize + 'px';
    button.style.height = buttonSize + 'px';
 
        let isLQ = true;
    let isLQ = true;
 
        button.addEventListener('click', function () {
    button.addEventListener('click', function () {
            if (isLQ) {
        if (isLQ) {
                viewer.src = hqUrl;
            viewer.src = hqUrl;
                icon.src = HQ_ICON;
            icon.src = HQ_ICON;
            } else {
            isLQ = false;
                viewer.src = lqUrl;
        } else {
                icon.src = LQ_ICON;
            viewer.src = lqUrl;
            }
            icon.src = LQ_ICON;
 
            isLQ = true;
            isLQ = !isLQ;
        }
        });
    });
 
        container.appendChild(button);
    container.appendChild(button);
    }
}


     function loadModel(preview) {
     function loadModel(preview) {