diff options
| author | _Tradam <[email protected]> | 2025-05-23 00:36:49 +0900 |
|---|---|---|
| committer | _Tradam <[email protected]> | 2025-05-23 00:36:49 +0900 |
| commit | f8b28444c453ffaa390bd8f42fd27e6ba24e1175 (patch) | |
| tree | df61639b0d83f65f480843044891a43ef2e7490c | |
| parent | 21ca830685fa1a1037ff4d6f722b3d956cc3a858 (diff) | |
| download | teletilt-f8b28444c453ffaa390bd8f42fd27e6ba24e1175.tar.gz teletilt-f8b28444c453ffaa390bd8f42fd27e6ba24e1175.zip | |
fixed for android
| -rw-r--r-- | main.js | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -30,14 +30,7 @@ function animate() { } renderer.setAnimationLoop(animate); -if ( location.protocol != "https:" ) { -location.href = "https:" + window.location.href.substring( window.location.protocol.length ); -} -function permission () { - if ( typeof( DeviceMotionEvent ) !== "undefined" && typeof( DeviceMotionEvent.requestPermission ) === "function" ) { - // (optional) Do something before API request prompt. - DeviceMotionEvent.requestPermission() - .then( response => { +const motionEvent = (response) => { // (optional) Do something after API prompt dismissed. if ( response == "granted" ) { window.addEventListener("deviceorientation", (e) => { @@ -76,8 +69,22 @@ function permission () { document.getElementById("info").textContent=`x: ${Math.round(cube.position.x * 10)}, y: ${Math.round(cube.position.y * 10)}`; }); } - }) +} + +if ( location.protocol != "https:" ) { +location.href = "https:" + window.location.href.substring( window.location.protocol.length ); +} +function permission () { + if ( typeof( DeviceMotionEvent ) !== "undefined") { + // (optional) Do something before API request prompt. + if(typeof( DeviceMotionEvent.requestPermission ) === "function") { + DeviceMotionEvent.requestPermission() + .then(motionEvent) .catch( console.error ) + } + else { + motionEvent("granted"); + } } else { alert( "DeviceMotionEvent is not defined" ); } |
