screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const [isLoading, setIsLoading] = useState(true); const [connectionType, setConnectionType] = useState(''); const [bandwidth, setBandwidth] = useState(''); useEffect(() => { const fetchData = async () => { try { if (navigator.connection) { await navigator.connection.ready; setConnectionType(navigator.connection.effectiveType); setBandwidth(navigator.connection.downlink.toFixed(2)); setIsLoading(false); } else { setConnectionType('Unknown'); setBandwidth('N/A'); setIsLoading(false); } } catch (error) { console.error('Error fetching data:', error); } }; fetchData(); }, []); return ( <div className='container'> <h3 className='title'>React Check Internet Speed</h3> {isLoading ? ( <p className='loading'>Loading...</p> ) : ( <p className={`connection-info ${connectionType === '4g' || connectionType === '5g' || bandwidth >= 10 ? 'fast' : 'slow'}`}> {connectionType === '4g' || connectionType === '5g' || bandwidth >= 10 ? ( `You are on a fast ${connectionType} connection (${bandwidth} Mbps).` ) : connectionType === '2g' || connectionType === '3g' || bandwidth < 1 ? ( `You are on a slow ${connectionType} connection (${bandwidth} Mbps).` ) : ( `Your internet connection is ${connectionType} (${bandwidth} Mbps).` )} </p> )} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; justify-content: center; } /* Title Styles */ .title { font-size: 24px; color: #333; margin-bottom: 20px; } /* Loading Styles */ .loading { font-size: 18px; color: #777; } /* Connection Info Styles */ .connection-info { font-size: 18px; margin-top: 20px; padding: 10px; border-radius: 5px; } /* Fast Connection Styles */ .fast { background-color: #4caf50; /* Green */ color: #fff; } /* Slow Connection Styles */ .slow { background-color: #f44336; /* Red */ color: #fff; } </style> </body> </html>