<!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="stylesheet" href="css/inside.css">
    <link rel="icon" type="image/gif" href="https://i.imgur.com/gTvafyQ.gif">
    <script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-app-compat.js"></script>
    <script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-auth-compat.js"></script>
    <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);
const auth = firebase.auth();

window.onload = function() {
    const isLoggedIn = localStorage.getItem('isLoggedIn');
    if (isLoggedIn !== 'true') {
        document.body.innerHTML = '<div style="text-align: center; padding: 50px;"><h2>請先登入！</h2><p>您必須先登入才能進入體育器材管理系統。<br><a href="index.html">前往登入頁面</a></p></div>';
    }
};
function logout() {
    auth.signOut()
        .then(() => {
            alert('已成功登出！');
            localStorage.removeItem('userEmail');
            localStorage.removeItem('isLoggedIn');
            document.cookie = "userEmail=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
            window.location.href = 'index.html';
        })
        .catch((error) => {
            console.error('登出失敗', error);
            alert('登出時發生錯誤：' + error.message);
        });
}

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>
    <script src="java/indexntubsyspeo.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="button-group">
            <a href="personalback.html">個人借還</a>
            <a href="groupback.html">圖體借還</a>
            <a href="borrowingback.html">場地借用登記</a>
            <a href="clubback.html">單位社團學會登記</a>
        </div>
        <a href="index.html" class="logout-button" onclick="logout()">登出</a>
    </div>
    <footer>
        Copyright &copy; 2024 <span>NTUB</span> 國立臺北商業大學. All rights reserved.
    </footer>
</body>
</html>
