「🏗️」 wip: work in progress, not done yet.
This commit is contained in:
BIN
site/favicon.ico
Normal file
BIN
site/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
15
site/fetchf.php
Normal file
15
site/fetchf.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// Créer une connexion à la base de données SQLite
|
||||
$db = new SQLite3('/var/www/db/pressf.db');
|
||||
|
||||
// Ouvrir une nouvelle connexion pour récupérer le compteur actuel
|
||||
$result = $db->query('SELECT count FROM respect_count WHERE id = 1');
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$current_count = $row['count'];
|
||||
|
||||
// Fermer la connexion
|
||||
$db->close();
|
||||
|
||||
// Afficher la valeur actuelle du compteur
|
||||
echo $current_count;
|
||||
?>
|
108
site/index.html
Normal file
108
site/index.html
Normal file
@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Press F to Pay Respect</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
background-color: #f4f4f4;
|
||||
color: #333;
|
||||
}
|
||||
h1 {
|
||||
color: #555;
|
||||
}
|
||||
.image-container {
|
||||
margin: 20px;
|
||||
}
|
||||
.kanel {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 20%;
|
||||
}
|
||||
.button {
|
||||
font-size: 20px;
|
||||
padding: 10px 20px;
|
||||
background-color: #333;
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
margin-top: 30px;
|
||||
}
|
||||
.button:focus {
|
||||
outline: none;
|
||||
}
|
||||
.disabled {
|
||||
background-color: #777;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Press F to Pay Respect</h1>
|
||||
|
||||
<div class="image-container">
|
||||
<img src="kanel.jpg" alt="Kanel" class="kanel">
|
||||
</div>
|
||||
|
||||
<p>Current count: <span id="countDisplay"></span></p>
|
||||
|
||||
<button class="button" id="payRespectButton">Press F</button>
|
||||
<div id="error-message" style="color: red; margin-top: 20px;"></div>
|
||||
|
||||
<script>
|
||||
// Fonction pour envoyer à la base de données
|
||||
function sendToDatabase() {
|
||||
fetch('pressf.php')
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
updateCount(data); // Mettre à jour le compteur affiché
|
||||
});
|
||||
}
|
||||
|
||||
// Fonction pour mettre à jour le compteur affiché
|
||||
function updateCount(newCount) {
|
||||
document.getElementById('countDisplay').innerText = newCount;
|
||||
}
|
||||
|
||||
// Fonction pour désactiver le bouton et empêcher le spam
|
||||
function disableButton() {
|
||||
const button = document.getElementById("payRespectButton");
|
||||
button.disabled = true;
|
||||
button.classList.add("disabled");
|
||||
|
||||
setTimeout(() => {
|
||||
button.disabled = false;
|
||||
button.classList.remove("disabled");
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// Gestion du clic sur le bouton
|
||||
document.getElementById("payRespectButton").addEventListener("click", function() {
|
||||
sendToDatabase();
|
||||
disableButton(); // Désactiver le bouton après un clic
|
||||
});
|
||||
|
||||
// Gestion de la touche "F"
|
||||
document.addEventListener("keydown", function(event) {
|
||||
if ((event.key === "f" || event.key === "F") && !document.getElementById("payRespectButton").disabled) {
|
||||
sendToDatabase();
|
||||
disableButton(); // Désactiver le bouton après un clic
|
||||
}
|
||||
});
|
||||
|
||||
// Initialisation de la page : récupérer et afficher le compteur
|
||||
window.onload = function() {
|
||||
fetch('fetchf.php')
|
||||
.then(response => response.text())
|
||||
.then(data => updateCount(data));
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
BIN
site/kanel.jpg
Normal file
BIN
site/kanel.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 244 KiB |
51
site/pressf.php
Normal file
51
site/pressf.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
session_start(); // Start the session
|
||||
|
||||
$timeout_duration = 10; // Timeout period in seconds (adjustable)
|
||||
|
||||
if (isset($_SESSION['last_click_time'])) {
|
||||
$time_diff = time() - $_SESSION['last_click_time']; // Time difference since last click
|
||||
|
||||
if ($time_diff < $timeout_duration) {
|
||||
// If the time difference is less than the cooldown period, deny the action
|
||||
die("Please wait a moment before clicking again.");
|
||||
}
|
||||
}
|
||||
|
||||
// Créer une connexion à la base de données SQLite
|
||||
$db = new SQLite3('/var/www/db/pressf.db');
|
||||
|
||||
// Créer la table si elle n'existe pas
|
||||
$db->exec('CREATE TABLE IF NOT EXISTS respect_count (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
count INTEGER NOT NULL DEFAULT 0
|
||||
)');
|
||||
|
||||
// Vérifier si le premier enregistrement existe, sinon l'insérer
|
||||
$result = $db->query('SELECT * FROM respect_count WHERE id = 1');
|
||||
if (!$result->fetchArray(SQLITE3_ASSOC)) {
|
||||
// Si le record avec id = 1 n'existe pas, on l'insère
|
||||
$db->exec('INSERT INTO respect_count (id, count) VALUES (1, 0)');
|
||||
}
|
||||
|
||||
// Mettre à jour le nombre dans la base de données
|
||||
$db->exec('UPDATE respect_count SET count = count + 1 WHERE id = 1');
|
||||
|
||||
// Fermer la connexion
|
||||
$db->close();
|
||||
|
||||
// Ouvrir une nouvelle connexion pour afficher le compteur
|
||||
$db = new SQLite3('/var/www/db/pressf.db');
|
||||
$result = $db->query('SELECT count FROM respect_count WHERE id = 1');
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$current_count = $row['count'];
|
||||
$db->close();
|
||||
|
||||
|
||||
// Store the current time in the session after the action is completed
|
||||
|
||||
$_SESSION['last_click_time'] = time();
|
||||
|
||||
// Afficher la valeur actuelle du compteur
|
||||
echo $current_count;
|
||||
?>
|
Reference in New Issue
Block a user