<!DOCTYPE html>
<html lang="zh-TW">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>國立臺北商業大學 登入頁面</title>
    <link rel="icon" type="image/gif" href="https://i.imgur.com/gTvafyQ.gif">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="css/login.css">
    <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
</head>
<body>
    <header>
        <div class="logo-container">
            <img src="https://i.imgur.com/gTvafyQ.gif" alt="NTUB Logo">
            <img src="https://i.imgur.com/pMsu4BK.gif" alt="NTUB Logo" class="large-logo">
        </div>
        <h1>登入頁面</h1>
    </header>
    <div class="container">
        <p class="intro">請使用您的帳號登入國立臺北商業大學體育器材管理系統</p>
        <div class="login-form">
            <input type="email" id="email" placeholder="電子郵件">
            <input type="password" id="password" placeholder="密碼">
            <button class="login-button" onclick="login()">登入</button>
        </div>
    </div>
    <footer>
        Copyright &copy; 2024 <span>NTUB</span> 國立臺北商業大學. All rights reserved.
    </footer>
    <script>
        const firebaseConfig = {
    apiKey: "AIzaSyCgs6j97oCJerFvnZ1penbVIMhxzSMIEao",
    authDomain: "ntubpeo.firebaseapp.com",
    projectId: "ntubpeo",
    storageBucket: "ntubpeo.firebasestorage.app",
    messagingSenderId: "106907057442",
    appId: "1:106907057442:web:35e0193bdc2a3747faf97b",
    measurementId: "G-CKE0E1XM9L"
  };
firebase.initializeApp(firebaseConfig);


function login() {
    const email = document.getElementById('email').value;
    const password = document.getElementById('password').value;

    firebase.auth().signInWithEmailAndPassword(email, password)
        .then((userCredential) => {
            const user = userCredential.user;
            localStorage.setItem('userEmail', user.email);
            localStorage.setItem('isLoggedIn', 'true');
            alert('登入成功！歡迎回來 ' + user.email);
            window.location.href = "indexntubsyspeo.html";
        })
        .catch((error) => {
            alert('登入失敗：' + error.message);
        });
}

window.onload = function() {
    const isLoggedIn = localStorage.getItem('isLoggedIn');
    if (isLoggedIn === 'true') {
        window.location.href = "indexntubsyspeo.html";
    }
};
document.addEventListener('contextmenu', event => event.preventDefault());
document.onkeydown = function(e) {
    if (e.key === "F12" || 
        (e.ctrlKey && e.shiftKey && (e.key === "I" || e.key === "J" || e.key === "C")) || 
        (e.ctrlKey && e.key === "U")) {
        e.preventDefault();
        return false;
    }
};
function isMobileDevice() {
    return /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
}

function detectWebDriver() {
    if (isMobileDevice()) {
        console.log("行動裝置或 iOS 檢測中，豁免某些檢測以避免誤判。");
        return; 
    }

    const userAgent = navigator.userAgent.toLowerCase();

    if (navigator.webdriver) {
        alert("偵測到自動化工具，操作已被封鎖！");
        window.location.href = "about:blank";
        return;
    }
    if (userAgent.includes("headless") || userAgent.includes("puppeteer")) {
        alert("偵測到自動化工具，操作已被封鎖！");
        window.location.href = "about:blank";
        return;
    }

    if (navigator.languages === "" || navigator.plugins.length === 0) {
        alert("偵測到自動化工具，操作已被封鎖！");
        window.location.href = "about:blank";
        return;
    }
}

window.onload = function() {
    detectWebDriver();
};

document.addEventListener('keydown', (e) => {
    if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === 'i') {
        e.preventDefault();
        window.location.href = 'about:blank';
    }
});


document.addEventListener('contextmenu', (e) => {
    e.preventDefault();

});


function detectDevTools() {
    const threshold = 160;
    const isMobile = /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);

    if (!isMobile) {
        const isDevToolsOpen = window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold;

        if (isDevToolsOpen) {
            window.location.href = 'about:blank';
        }
    }
}

document.addEventListener('keydown', (e) => {
    if (e.key === 'F12') {
        e.preventDefault();
        window.location.href = 'about:blank';
    }
});
document.addEventListener('keydown', (e) => {
    if ((e.ctrlKey || e.metaKey) && e.key === 's') {
        e.preventDefault();
    }
});

document.addEventListener('keydown', (e) => {
    if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === 'i') {
        e.preventDefault();
        window.location.href = 'about:blank';
    }
});

setInterval(detectDevTools, 50);
    </script>
</body>
</html>