User:Monster Domosed/common.js: Difference between revisionsGive feedback
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) { | |||
return; | |||
} | |||
const button = document.createElement('button'); | |||
button.className = 'mv-quality-toggle'; | |||
button.type = 'button'; | |||
const icon = document.createElement('img'); | |||
icon.src = LQ_ICON; | |||
icon.alt = ''; | |||
button.appendChild(icon); | |||
const buttonSize = Math.max( | |||
28, | |||
Math.min(56, Math.round(container.offsetWidth * 0.14)) | |||
); | |||
button.style.width = buttonSize + 'px'; | |||
button.style.height = buttonSize + 'px'; | |||
let isLQ = true; | |||
button.addEventListener('click', function () { | |||
if (isLQ) { | |||
viewer.src = hqUrl; | |||
icon.src = HQ_ICON; | |||
isLQ = false; | |||
} else { | |||
viewer.src = lqUrl; | |||
icon.src = LQ_ICON; | |||
isLQ = true; | |||
} | |||
}); | |||
container.appendChild(button); | |||
} | |||
function loadModel(preview) { | function loadModel(preview) { | ||