-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js.old
More file actions
105 lines (87 loc) · 3.02 KB
/
Copy pathscript.js.old
File metadata and controls
105 lines (87 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Multilingual Welcome Greeting Script
* Rotates through "Welcome" in multiple languages with fade-in/fade-out transitions
*/
(function() {
'use strict';
// Configuration constants
const TRANSITION_DURATION = 800; // Must match CSS transition duration (in ms)
const ROTATION_INTERVAL = 2500; // Time between greeting changes (in ms)
// Array of greetings in different languages
const greetings = [
{ text: 'Welcome', lang: 'en' }, // English
{ text: 'Bienvenue', lang: 'fr' }, // French
{ text: 'Ẹ káàbọ', lang: 'yo' }, // Yoruba
{ text: 'Barka da zuwa', lang: 'ha' }, // Hausa
{ text: 'مرحبا', lang: 'ar' }, // Arabic (Marhaba)
{ text: 'Bienvenido', lang: 'es' }, // Spanish
{ text: 'Willkommen', lang: 'de' }, // German
{ text: 'Benvenuto', lang: 'it' }, // Italian
{ text: 'स्वागत है', lang: 'hi' }, // Hindi (Swagat hai)
{ text: 'ようこそ', lang: 'ja' }, // Japanese (Yōkoso)
{ text: '欢迎', lang: 'zh' }, // Chinese (Huānyíng)
{ text: 'Добро пожаловать', lang: 'ru' }, // Russian (Dobro pozhalovat)
{ text: 'Karibu', lang: 'sw' }, // Swahili
{ text: 'Bem-vindo', lang: 'pt' } // Portuguese
];
let currentIndex = 0;
let greetingElement = null;
let rotationInterval = null;
/**
* Initialize the greeting rotation
*/
function init() {
// Find the greeting element
greetingElement = document.getElementById('dynamic-greeting');
if (!greetingElement) {
console.warn('Greeting element not found');
return;
}
// Set initial greeting
updateGreeting();
// Start rotation
rotationInterval = setInterval(rotateGreeting, ROTATION_INTERVAL);
}
/**
* Update the greeting text and language attribute
*/
function updateGreeting() {
if (!greetingElement) return;
const greeting = greetings[currentIndex];
// Remove visible class for fade-out
greetingElement.classList.remove('visible');
// Wait for fade-out, then update content
setTimeout(() => {
greetingElement.textContent = greeting.text;
greetingElement.setAttribute('lang', greeting.lang);
// Add visible class for fade-in
// Use requestAnimationFrame to ensure the DOM has updated
requestAnimationFrame(() => {
greetingElement.classList.add('visible');
});
}, TRANSITION_DURATION / 2);
}
/**
* Rotate to the next greeting
*/
function rotateGreeting() {
currentIndex = (currentIndex + 1) % greetings.length;
updateGreeting();
}
/**
* Clean up on page unload
*/
function cleanup() {
if (rotationInterval) {
clearInterval(rotationInterval);
}
}
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
// Cleanup on page unload
window.addEventListener('beforeunload', cleanup);
})();