feat: propagate client screen size to web runtime
This commit is contained in:
@@ -100,6 +100,32 @@
|
||||
banner.style.display = 'none';
|
||||
});
|
||||
})();
|
||||
|
||||
(function () {
|
||||
function clamp(value, min, max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
function currentScreenParams() {
|
||||
const width = clamp(window.innerWidth || document.documentElement.clientWidth || 1280, 320, 7680);
|
||||
const height = clamp(window.innerHeight || document.documentElement.clientHeight || 720, 240, 4320);
|
||||
const sp = new URLSearchParams();
|
||||
sp.set('sw', String(width));
|
||||
sp.set('sh', String(height));
|
||||
return sp;
|
||||
}
|
||||
|
||||
document.querySelectorAll('a.tile[href^="/go/"]').forEach(function (link) {
|
||||
link.addEventListener('click', function () {
|
||||
try {
|
||||
const url = new URL(link.getAttribute('href'), window.location.origin);
|
||||
const params = currentScreenParams();
|
||||
url.search = params.toString();
|
||||
link.setAttribute('href', url.pathname + '?' + url.searchParams.toString());
|
||||
} catch (e) {}
|
||||
}, { capture: true });
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user