···11- // --- REDIRECTION SCRIPT ---
22-33- // Get DOM elements
44- const countdownElement = document.getElementById('countdown');
55- const destinationLinkElement = document.getElementById('destination-link');
66- const goNowButton = document.getElementById('go-now-button');
77- const redirectContainer = document.getElementById('redirect-container');
88- const errorContainer = document.getElementById('error-container');
99-1010- // Get the destination URL from the '?link=' parameter
1111- const params = new URLSearchParams(window.location.search);
1212- const destinationUrl = params.get('link');
1313-1414- // Function to perform the redirection
1515- const redirectToDestination = () => {
1616- if (destinationUrl) {
1717- window.location.href = destinationUrl;
1818- }
1919- };
2020-2121- // Validate the URL
2222- if (destinationUrl) {
2323- try {
2424- // Check if the URL is valid
2525- new URL(destinationUrl);
2626-2727- // Update the link on the page for user visibility
2828- destinationLinkElement.href = destinationUrl;
2929- destinationLinkElement.textContent = destinationUrl;
3030-3131- // Set initial countdown value
3232- let secondsLeft = 5;
3333-3434- // Set up the final redirect timer
3535- const redirectTimer = setTimeout(redirectToDestination, secondsLeft * 1000);
3636-3737- // Set up the interval to update the countdown display every second
3838- const countdownInterval = setInterval(() => {
3939- secondsLeft--;
4040- countdownElement.textContent = secondsLeft;
4141- if (secondsLeft <= 0) {
4242- clearInterval(countdownInterval);
4343- }
4444- }, 1000);
4545-4646- // Add event listener for the "Go Now" button
4747- goNowButton.addEventListener('click', () => {
4848- clearTimeout(redirectTimer); // Clear the scheduled redirect
4949- clearInterval(countdownInterval); // Stop the countdown
5050- redirectToDestination(); // Redirect immediately
5151- });
5252-5353- } catch (e) {
5454- // Handle invalid URL format
5555- redirectContainer.classList.add('hidden');
5656- errorContainer.classList.remove('hidden');
5757- }
5858- } else {
5959- // Handle case where '?link=' parameter is missing
6060- redirectContainer.classList.add('hidden');
6161- errorContainer.classList.remove('hidden');
6262- }
-4
script/main.js
···11-document.addEventListener('DOMContentLoaded', function() {
22- var currentYear = new Date().getFullYear();
33- document.getElementById('currentYear').textContent = currentYear;
44-});
-41
script/search.js
···11-/**
22- * This script adds search functionality to the page and updates the copyright year.
33- */
44-document.addEventListener('DOMContentLoaded', function() {
55- // --- Copyright Year Updater ---
66- // Finds the 'currentYear' span and sets its text to the current year.
77- const currentYearSpan = document.getElementById('currentYear');
88- if (currentYearSpan) {
99- currentYearSpan.textContent = new Date().getFullYear();
1010- }
1111-1212- // --- Search Functionality ---
1313- const searchInput = document.getElementById('projectSearch');
1414- const projectCards = document.querySelectorAll('.project-card'); // Select all project cards
1515-1616- // Listen for the 'input' event, which is more responsive than 'keyup' for this purpose.
1717- // It fires immediately when the value of the input element changes.
1818- searchInput.addEventListener('input', function() {
1919- // Get the search term and convert it to lowercase for case-insensitive matching.
2020- const searchTerm = searchInput.value.toLowerCase();
2121-2222- // Loop through each project card to see if it matches the search term.
2323- projectCards.forEach(card => {
2424- // Get the title and description elements within the current card.
2525- const titleElement = card.querySelector('.project-title-text');
2626- const descriptionElement = card.querySelector('.project-description');
2727-2828- // Extract text content and convert to lowercase for comparison.
2929- // If an element doesn't exist, default to an empty string.
3030- const titleText = titleElement ? titleElement.textContent.toLowerCase() : '';
3131- const descriptionText = descriptionElement ? descriptionElement.textContent.toLowerCase() : '';
3232-3333- // Check if the search term is found in either the title or description.
3434- if (titleText.includes(searchTerm) || descriptionText.includes(searchTerm)) {
3535- card.style.display = ''; // Show the project card if it matches.
3636- } else {
3737- card.style.display = 'none'; // Hide the project card if it doesn't match.
3838- }
3939- });
4040- });
4141-});