-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (62 loc) · 1.94 KB
/
script.js
File metadata and controls
72 lines (62 loc) · 1.94 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
document.addEventListener('DOMContentLoaded', function() {
// Function to scroll to an element
function scrollToElement(elementId) {
const element = document.getElementById(elementId);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
}
// Check URL parameters when page loads
const urlParams = new URLSearchParams(window.location.search);
const scrollTo = urlParams.get('scrollTo');
if (scrollTo) {
scrollToElement(scrollTo);
}
// QUOTE GENERATOR
const quotes = [
"Your future is built in the quiet hours no one applauds.",
"Discomfort is the tuition you pay for growth.",
"When you can’t see the whole path, take the step that’s in front of you."
];
function typeEffect(text, elementId, speed = 50) {
const element = document.getElementById(elementId);
element.innerHTML = "";
let i = 0;
function typing() {
if (i < text.length) {
element.innerHTML += text.charAt(i);
i++;
setTimeout(typing, speed);
}
}
typing();
}
window.onload = function () {
const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
typeEffect(randomQuote, 'quoteDisplay', 40); // You can adjust speed here
};
// QUOTE GENERATOR END
});
// VISITOR COUNTER
function displayCount(data) {
const counterElement = document.getElementById('visitor-count');
if (counterElement && data.count) {
counterElement.innerText = data.count;
}
}
// API CALL
const namespace = "muhais-olatundun"; //workspace
const key = "first-counter-2519"; //slug
fetch(`https://api.counterapi.dev/v1/${namespace}/${key}/up`)
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
})
.then(data => {
displayCount(data);
})
.catch(error => {
console.error('Counter Error:', error);
// Fallback text if the API fails
document.getElementById('visitor-count').innerText = "1";
});