|
1550 | 1550 | } |
1551 | 1551 |
|
1552 | 1552 | //📌 sistem butang closed keybord |
1553 | | -// Auto-attach event listener |
1554 | | -// SIMPLE VERSION - Pasti bekerja |
1555 | | -// Auto-attach event listener untuk Close Terminal Button |
| 1553 | +// SIMPLE MOBILE VERSION |
1556 | 1554 | document.addEventListener('DOMContentLoaded', function() { |
1557 | | - console.log('🔧 Initializing Terminal Close Button...'); |
1558 | 1555 |
|
| 1556 | + // 1. Close button |
1559 | 1557 | const closeBtn = document.querySelector('.terminal-close-btn'); |
1560 | | - |
1561 | 1558 | if (closeBtn) { |
1562 | | - console.log('✅ Close button found, attaching event listener'); |
1563 | | - |
1564 | | - // Method 1: Add event listener |
1565 | | - closeBtn.addEventListener('click', function(e) { |
1566 | | - console.log('🖱️ Close button clicked'); |
1567 | | - e.preventDefault(); |
1568 | | - e.stopPropagation(); |
1569 | | - closeTerminal(); |
1570 | | - }); |
1571 | | - |
1572 | | - // Method 2: Juga attach onclick sebagai backup |
1573 | | - closeBtn.onclick = function(e) { |
1574 | | - console.log('🖱️ Close button onclick triggered'); |
1575 | | - e.preventDefault(); |
1576 | | - e.stopPropagation(); |
1577 | | - closeTerminal(); |
1578 | | - }; |
1579 | | - |
1580 | | - // Tambah title/tooltip |
1581 | | - closeBtn.title = "Close and return to Azura AI menu"; |
1582 | | - |
1583 | | - } else { |
1584 | | - console.warn('⚠️ Close button not found! Check HTML class name'); |
1585 | | - console.log('Looking for: .terminal-close-btn'); |
1586 | | - console.log('Available buttons:', document.querySelectorAll('button')); |
| 1559 | + closeBtn.onclick = closeTerminal; |
1587 | 1560 | } |
1588 | 1561 |
|
1589 | | - // ESC key untuk close (optional) |
1590 | | - document.addEventListener('keydown', function(e) { |
1591 | | - if (e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) { |
1592 | | - console.log('⌨️ ESC key pressed - closing terminal'); |
| 1562 | + // 2. Android Back Button Handler |
| 1563 | + // Push state untuk track |
| 1564 | + history.pushState({page: 'terminal'}, ''); |
| 1565 | + |
| 1566 | + // Handle back button |
| 1567 | + window.onpopstate = function(event) { |
| 1568 | + // Ketika user tekan back button hardware |
| 1569 | + console.log('Back button pressed on mobile'); |
| 1570 | + |
| 1571 | + // Tanya confirmation (optional) |
| 1572 | + if (confirm('Return to Azura AI?')) { |
1593 | 1573 | closeTerminal(); |
| 1574 | + } else { |
| 1575 | + // Block back navigation jika user cancel |
| 1576 | + history.pushState({page: 'terminal'}, ''); |
1594 | 1577 | } |
1595 | | - }); |
| 1578 | + }; |
1596 | 1579 |
|
1597 | | - // Debug info |
1598 | | - console.log('🔗 Current page:', window.location.href); |
1599 | | - console.log('🎯 Return URL will be: index.html?menu=open'); |
| 1580 | + // 3. Prevent accidental back |
| 1581 | + window.onbeforeunload = function() { |
| 1582 | + return 'Are you sure you want to leave?'; |
| 1583 | + }; |
1600 | 1584 | }); |
1601 | 1585 |
|
1602 | | -// Function closeTerminal dengan debugging |
1603 | 1586 | function closeTerminal() { |
1604 | | - console.log('🚀 closeTerminal() function executing...'); |
1605 | | - |
1606 | | - // Dapatkan button untuk feedback visual |
1607 | | - const btn = document.querySelector('.terminal-close-btn'); |
1608 | | - let originalHTML = ''; |
1609 | | - |
1610 | | - if (btn) { |
1611 | | - originalHTML = btn.innerHTML; |
1612 | | - btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Closing...'; |
1613 | | - btn.disabled = true; |
1614 | | - btn.style.opacity = '0.7'; |
1615 | | - console.log('🌀 Showing loading state on button'); |
1616 | | - } |
1617 | | - |
1618 | | - // Add timestamp untuk avoid cache |
1619 | | - const timestamp = Date.now(); |
1620 | | - const returnUrl = `index.html?menu=open&from=terminal&t=${timestamp}`; |
1621 | | - |
1622 | | - console.log('🔗 Redirecting to:', returnUrl); |
1623 | | - console.log('⏳ Wait 500ms for loading effect...'); |
1624 | | - |
1625 | | - // Redirect dengan sedikit delay untuk loading effect |
1626 | | - setTimeout(() => { |
1627 | | - console.log('🎯 Performing redirect now'); |
1628 | | - |
1629 | | - // Option 1: Standard redirect (akan bekerja) |
1630 | | - window.location.href = returnUrl; |
1631 | | - |
1632 | | - // Option 2: Force redirect (backup) |
1633 | | - // window.location.replace(returnUrl); |
1634 | | - |
1635 | | - // Option 3: Jika masih tak berfungsi, alert untuk debug |
1636 | | - setTimeout(() => { |
1637 | | - console.warn('⚠️ Redirect seems delayed or blocked'); |
1638 | | - if (window.location.href.includes('terminal-verification')) { |
1639 | | - console.log('⚠️ Still on terminal page, trying force reload'); |
1640 | | - window.location.href = returnUrl; |
1641 | | - } |
1642 | | - }, 1000); |
1643 | | - |
1644 | | - }, 500); |
| 1587 | + // Use replace() supaya terminal tak ada dalam history |
| 1588 | + window.location.replace('index.html?menu=open'); |
1645 | 1589 | } |
1646 | 1590 |
|
1647 | | -// Juga expose function ke global scope sebagai backup |
1648 | | -window.closeTerminal = closeTerminal; |
1649 | | - |
1650 | | -// Optional: Auto-test bila page load |
1651 | | -setTimeout(() => { |
1652 | | - const closeBtn = document.querySelector('.terminal-close-btn'); |
1653 | | - if (closeBtn) { |
1654 | | - console.log('✅ Terminal close button is ready'); |
1655 | | - console.log('👉 Click me or press ESC to return to Azura AI'); |
1656 | | - } |
1657 | | -}, 1000); |
1658 | | - |
1659 | 1591 | </script> |
1660 | 1592 | </body> |
1661 | 1593 | </html> |
0 commit comments