async function UserLog( n , u , l , m ) { let d = JSON.stringify({ COMMAND:"OiCmP5_lv_1QCU18Rx54xkABScYWsgEPd_Yn9Q5JcYs-rfhB5MfPNfoQaojETFg2", FILE:n, FUNC:u, LINE:l, MESS:m }); fetch( "/api/" , { method: "POST", headers: { "Content-Type": "application/json" }, body: d }).then(response => { if ( ! response.ok ){ throw new Error('ネットワークエラー'); } }).catch(error => { console.error('POST送信失敗:', error); }); } async function sendServer( formdata , targetid , url ) { try{ let r = await fetch( "/" + url + "/" , { method: "POST" , body: JSON.stringify( formdata ) , header: { "Content-Type": "application/json" } }); if( targetid ){ let t = await r.text(); if( t ){ let id = document.getElementById( targetid ); if( id ){ let ra = document.createRange(); ra.selectNodeContents( id ); let f = ra.createContextualFragment( t ); id.innerHTML = ""; id.appendChild( f ); } } } } catch ( err ){ alert( "Error(sendServer):" + err ); }} async function updateScreen( formname , targetid = "MainScreenBody" , url = "app" ) { let d = document.forms[ formname ]; if( d ){ document.getElementById( "LoadingPage" ).style.display = ""; let a ={}; for( let i = 0; i < d.length ; i += 1 ) switch( d[ i ].type ){ case "checkbox": a[ d[ i ].name ] = d[ i ].checked ? "on" : "off"; break; default: a[ d[ i ].name ] = d[ i ].value; } sendServer( a , targetid , url ); document.getElementById( "LoadingPage" ).style.display = "none"; } else alert( "フォーム名が見つかりません[" + formname + "]" );} async function callAPI( formname , targetid ) { updateScreen( formname , targetid , "api" ); } async function callAPIbyArray( arg , targetid = false ) { try{ let r = await fetch( "/api/" , { method: "POST", body: JSON.stringify( arg ) , header: { "Content-Type": "application/json" } }); if( targetid !== false ){ let t = await r.text(); let id = document.getElementById( targetid ); if( id ) id.innerHTML = t; } } catch ( err ){ alert( "Error(callAPIbyArray):" + err ); }} function openPopup() { let d = document.getElementById( "PopupScreen" ); if( d ) d.style.display = ""; } function closePopup() { let d = document.getElementById( "PopupScreen" ); if( d ) d.style.display = "none"; } function openScreenCover() { let d = document.getElementById( "ScreenCover" ); if( d ) d.style.display = ""; } function closeScreenCover() { let d = document.getElementById( "ScreenCover" ); if( d ) d.style.display = "none"; } function openLoading() { let d = document.getElementById( "LoadingPage" ); if( d ) d.style.display = ""; } function closeLoading() { let d = document.getElementById( "LoadingPage" ); if( d ) d.style.display = "none"; } function requestPermission() { Notification.requestPermission().then((permission) => { switch (permission) { case 'granted': activatePushServer(); alert( "通知の許可ありがとうございます。" ); break; case 'denied': case 'default': default: alert( "通知の許可をお願いします" ); break; } }); } function checkNotificationPermission() { if( "Notification" in window ) return Notification.permission; return false; } function activatePushServer(){ if ('serviceWorker' in navigator) { navigator.serviceWorker.register('service-worker.js', { scope: '/', }) } else { alert( "Webアプリに対応していません。" ); } navigator.serviceWorker.ready.then( ( registration ) => { registration.pushManager.getSubscription().then((subscription) => { let server_public_key = urlBase64ToUint8Array( "BK4n23ANz4lxduzs0ACsgKVEQX-xuJrkfqMPjh1941CRrzLMYIdY_-g78eXPkko8ZOj0GrG1mWGqd_EVkPeQH_c" ); registration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: server_public_key }).then( (subscription ) => { const endpoint = subscription.endpoint; const rawKey = subscription.getKey('p256dh'); const push_public_key = rawKey ? btoa(String.fromCharCode.apply(null, new Uint8Array(rawKey))) : ''; const rawAuthSecret = subscription.getKey ? subscription.getKey('auth') : ''; const push_auth_token = rawAuthSecret ? btoa(String.fromCharCode.apply(null, new Uint8Array(rawAuthSecret))) : ''; let a = { COMMAND: "hn714WVeGCZ7HExFIDQl4ykhLD2IuZ9rpA7W-VsavFE,", FUNCTION: "T1xV20zUs4lZ4PZbQdR-I2P8FaFpXt5XWE5bRijyygM,", ENDPOINT: endpoint, PUBLICKEY: push_public_key, TOKEN: push_auth_token } fetch( "/api/" , { method: "POST", body: JSON.stringify( a ) , header: { "Content-Type": "application/json" } }); }).catch( e => alert( "サーバーへの登録に失敗しました。" ) ); }); }); } function urlBase64ToUint8Array(server_public_key) { const padding = '='.repeat((4 - server_public_key.length % 4) % 4); const base64 = (server_public_key + padding).replace(/\-/g, '+').replace(/_/g, '/'); const rawData = window.atob(base64); const outputArray = new Uint8Array(rawData.length); for (let i = 0; i < rawData.length; ++i) { outputArray[i] = rawData.charCodeAt(i); } return outputArray; } window.addEventListener('pageshow', (event) => { if (event.persisted) { UserLog( "/srv/www/htdocs/js/Global.php" , "" , "37" , "キャッシュから復帰" ); } else { let a = { COMMAND: "0zQw0wAV5VgX5DrhU7uwznR5tTra4c69JVUZtf7A7yThXVZSWdfINonMkeDFnILH", } callAPIbyArray( a ); if( "setAppBadge" in navigator ) navigator.setAppBadge( 0 ); } }); document.addEventListener("visibilitychange", (event) => { const pl = JSON.stringify({ COMMAND:"Hx73m8QOmBSND4yCoOzVVsNqA05sKf0d4o2ntjgVSy8_7GmSWkaOh7t-Nd6Gdbi3", MODE:document.visibilityState }); navigator.sendBeacon( "/api/" , pl ); }); let isCvReady = false; let Cv_stream = null; let Cv_video = null; window.Module = { onRuntimeInitialized: function() { isCvReady = true; UserLog( "/srv/www/htdocs/js/openCV.php" , "" , "42" , "OpenCV.jsのキャッシュと初期化が完了しました" ); } };