-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (57 loc) · 1.97 KB
/
Copy pathscript.js
File metadata and controls
69 lines (57 loc) · 1.97 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
const videoPlayer = document.getElementById("videoPlayer");
const qualitySelect = document.getElementById("qualitySelect");
const commentsList = document.getElementById("commentsList");
const commentInput = document.getElementById("commentInput");
let userCity = '';
let userState = '';
const videoSources = {
"320p": "videos/sample-320p.mp4",
"480p": "videos/sample-480p.mp4",
"720p": "videos/sample-720p.mp4",
"1080p": "videos/sample-1080p.mp4"
};
qualitySelect.addEventListener("change", () => {
videoPlayer.src = videoSources[qualitySelect.value];
videoPlayer.load();
});
function postComment() {
const text = commentInput.value.trim();
if (!/^[a-zA-Z0-9\s.,?!]+$/.test(text)) {
alert("Comment contains invalid characters.");
return;
}
const li = document.createElement("li");
li.innerHTML = `
<p><strong>${userCity}:</strong> ${text}</p>
<button onclick="like(this)">👍 <span>0</span></button>
<button onclick="dislike(this)">👎 <span>0</span></button>
<button onclick="alert('Translated: ${text}')">Translate</button>
`;
commentsList.appendChild(li);
commentInput.value = '';
}
function like(btn) {
const span = btn.querySelector("span");
span.innerText = parseInt(span.innerText) + 1;
}
function dislike(btn) {
const span = btn.querySelector("span");
const count = parseInt(span.innerText) + 1;
span.innerText = count;
if (count >= 2) {
btn.closest("li").remove();
}
}
async function getLocationThemeAndOtp() {
const res = await fetch("https://ipapi.co/json");
const data = await res.json();
userCity = data.city;
userState = data.region.toLowerCase();
const hour = new Date().getHours();
const isSouth = ['tamil nadu', 'kerala', 'karnataka', 'andhra pradesh', 'telangana'].includes(userState);
const theme = (hour >= 10 && hour < 12 && isSouth) ? "light" : "dark";
document.body.className = theme;
const otpMethod = isSouth ? "Email" : "SMS";
alert(`OTP sent via: ${otpMethod}`);
}
getLocationThemeAndOtp();