<!-----//////////////////////////เริ่มส่วนของไว้อาลัย///////////////////////////////-------->
<?php
// --- ส่วน Backend (PHP) สำหรับรับค่าและบันทึก ---
if (isset($_POST['state'])) {
$state = $_POST['state'];
$folderName = 'mod';
// ตรวจสอบว่ามีโฟลเดอร์ mod หรือยัง ถ้ายังไม่มีให้สร้างขึ้นมา
if (!is_dir($folderName)) {
mkdir($folderName, 0755, true);
}
// สร้างและเขียนไฟล์ status.txt ในโฟลเดอร์ mod
$filePath = $folderName . '/status.txt';
if (file_put_contents($filePath, $state)) {
echo "Success ($state)";
} else {
echo "Failed to save";
}
// ใส่ exit; เพื่อหยุดการทำงานตรงนี้
exit;
}
?>
<style>
/* คลาสสำหรับทำหน้าเว็บให้เป็นสีเทา */
.mourning-mode {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
}
/* ตั้งค่าริบบิ้นมุมซ้ายบน */
#black-ribbon {
position: fixed;
top: 0;
left: 0;
z-index: 99999;
pointer-events: none;
display: none;
}
/* ถ้าระบบเปิดโหมดไว้อาลัย ให้แสดงริบบิ้น */
.mourning-mode-active #black-ribbon {
display: block;
}
/* ปุ่มเปิด-ปิดมุมซ้ายล่าง */
#toggle-mourning-btn {
position: fixed;
bottom: 15px;
left: 15px;
z-index: 99999;
padding: 5px 10px;
font-size: 12px;
cursor: pointer;
background: #333;
color: #fff;
border: 1px solid #000;
border-radius: 4px;
opacity: 0.7;
}
#toggle-mourning-btn:hover {
opacity: 1;
}
</style>
<!-- ริบบิ้นและปุ่ม -->
<img id="black-ribbon" src="https://cdn.nuuneoi.com/images/blog/884/black_ribbon_top_left.png" alt="Black Ribbon">
<button id="toggle-mourning-btn">เปิด/ปิด โหมดไว้อาลัย</button>
<!-- JavaScript -->
<script>
document.addEventListener("DOMContentLoaded", function() {
const btn = document.getElementById("toggle-mourning-btn");
const htmlElement = document.documentElement;
// ดึงค่าเริ่มต้นจาก LocalStorage
let isMourning = localStorage.getItem("mourning_state") !== "off";
function applyState() {
if (isMourning) {
htmlElement.classList.add("mourning-mode");
document.body.classList.add("mourning-mode-active");
} else {
htmlElement.classList.remove("mourning-mode");
document.body.classList.remove("mourning-mode-active");
}
}
// โหลดการแสดงผลครั้งแรก
applyState();
// เมื่อกดปุ่ม
btn.addEventListener("click", function() {
isMourning = !isMourning;
let stateText = isMourning ? "on" : "off";
// บันทึกในเครื่องผู้ใช้
localStorage.setItem("mourning_state", stateText);
applyState();
// ส่งค่าไปบันทึก
fetch('', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'state=' + stateText
})
.then(response => response.text())
.then(data => console.log("System Status: " + data))
.catch(error => console.error('Error:', error));
});
});
</script>
<!-----//////////////////////////สิ้นสุดส่วนของไว้อาลัย///////////////////////////////-------->
|