Skip to content

Commit 6116ee8

Browse files
added ui,ad and other area js files
1 parent 218ff05 commit 6116ee8

File tree

1 file changed

+69
-96
lines changed

1 file changed

+69
-96
lines changed

1991/javascripts/ui.js

Lines changed: 69 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,79 @@
1+
// 1. Mark the function as ASYNC
2+
async function renderPlaylist() {
3+
const urlParams = new URLSearchParams(window.location.search);
4+
const title = urlParams.get('title');
5+
const topic = urlParams.get('topic');
6+
7+
if(title) {
8+
$('#title').text(title);
9+
}
110

2-
// 2. The function to render the list
3-
function renderPlaylist() {
4-
5-
6-
7-
// 1. Get the query string (e.g., "?product=vanilla&id=42")
8-
const queryString = window.location.search;
11+
// 2. Map topics to their JSON files
12+
const topicFiles = {
13+
'listening': 'listening.json',
14+
'reading': 'reading.json',
15+
'writing': 'writing.json',
16+
'speaking': 'speaking.json',
17+
'basic-speaking': 'basic-speaking.json',
18+
'basic-english': 'basic-english.json'
19+
};
920

10-
// 2. Create the URLSearchParams object
11-
const urlParams = new URLSearchParams(queryString);
21+
const fileName = topicFiles[topic];
22+
if (!fileName) {
23+
console.error("Topic not found");
24+
return;
25+
}
1226

13-
// 3. Get specific values
14-
const title = urlParams.get('title');
15-
const topic = urlParams.get('topic');
16-
const country = urlParams.get('cn');
17-
18-
19-
if(title){
20-
$('#title').text(title);
21-
}
22-
23-
let url;
24-
let tutorials=[];
25-
26-
if(topic=='listening'){
27-
url = 'https://brainandbinary.github.io/1991/javascripts/listening.json';
28-
}
29-
30-
if(topic=='reading'){
31-
url = 'https://brainandbinary.github.io/1991/javascripts/reading.json';
32-
}
33-
34-
if(topic=='writing'){
35-
url = 'https://brainandbinary.github.io/1991/javascripts/writing.json';
36-
}
37-
38-
if(topic=='speaking'){
39-
url = 'https://brainandbinary.github.io/1991/javascripts/speaking.json';
40-
}
41-
42-
if(topic=='basic-speaking'){
43-
url = 'https://brainandbinary.github.io/1991/javascripts/basic-speaking.json';
44-
}
45-
46-
if(topic=='basic-english'){
47-
url = 'https://brainandbinary.github.io/1991/javascripts/basic-english.json';
48-
}
49-
50-
try{
51-
const response = await fetch(url);
52-
// 1. 'data' will be the array [ {className: ...}, {className: ...} ]
53-
tutorials = await response.json();
54-
}catch(e){
55-
console.log(e)
56-
}
57-
58-
59-
const container = document.getElementById('list-wrapper');
60-
61-
// Clear existing content (optional)
62-
container.innerHTML = '';
27+
// 3. Add cache busting version
28+
const version = new Date().getTime();
29+
const url = `https://brainandbinary.github.io/1991/javascripts/${fileName}?v=${version}`;
30+
31+
let tutorials = [];
6332

64-
tutorials.forEach((item, index) => {
65-
// Create the bar element
66-
const bar = document.createElement('div');
67-
bar.className = 'playlist-bar';
68-
bar.style.cssText = `
69-
display: flex;
70-
align-items: center;
71-
padding: 15px;
72-
margin-bottom: 10px;
73-
background-color: #2a2a2a;
74-
color: white;
75-
border-radius: 8px;
76-
cursor: pointer;
77-
transition: background 0.2s;
78-
font-family: sans-serif;
79-
`;
33+
try {
34+
// Now 'await' will work because the function is 'async'
35+
const response = await fetch(url);
36+
if (!response.ok) throw new Error("Network response was not ok");
37+
tutorials = await response.json();
38+
} catch(e) {
39+
console.log("Fetch Error: ", e);
40+
}
41+
42+
const container = document.getElementById('list-wrapper');
43+
if (!container) return;
44+
45+
container.innerHTML = '';
8046

81-
// Inner HTML for the bar (Icon + Title)
82-
bar.innerHTML = `
83-
<span style="margin-right: 15px; opacity: 0.5;">${index + 1}</span>
84-
<span style="flex-grow: 1; font-weight: 500;">${item.className}</span>
85-
<span style="font-size: 0.8em; color: #4CAF50;">▶ Play</span>
86-
`;
47+
tutorials.forEach((item, index) => {
48+
const bar = document.createElement('div');
49+
bar.className = 'playlist-bar';
50+
bar.style.cssText = `
51+
display: flex;
52+
align-items: center;
53+
padding: 15px;
54+
margin-bottom: 10px;
55+
background-color: #2a2a2a;
56+
color: white;
57+
border-radius: 8px;
58+
cursor: pointer;
59+
transition: background 0.2s;
60+
font-family: sans-serif;
61+
`;
8762

88-
// Hover effect
89-
bar.onmouseenter = () => bar.style.backgroundColor = '#383838';
90-
bar.onmouseleave = () => bar.style.backgroundColor = '#2a2a2a';
63+
bar.innerHTML = `
64+
<span style="margin-right: 15px; opacity: 0.5;">${index + 1}</span>
65+
<span style="flex-grow: 1; font-weight: 500;">${item.className}</span>
66+
<span style="font-size: 0.8em; color: #4CAF50;">▶ Play</span>
67+
`;
9168

92-
// Click event to load the video (e.g., into a main player area)
93-
bar.onclick = () => {
94-
console.log(`Loading: ${item.className}`);
95-
// You could append item.youtubeIframe to a #video-display div here
96-
};
69+
bar.onclick = () => {
70+
console.log(`Loading: ${item.className}`);
71+
// If you have a video display area:
72+
// $('#video-display').html(item.youtubeIframe);
73+
};
9774

98-
container.appendChild(bar);
99-
});
75+
container.appendChild(bar);
76+
});
10077
}
10178

102-
103-
document.addEventListener('DOMContentLoaded', renderPlaylist);
104-
105-
106-
79+
document.addEventListener('DOMContentLoaded', renderPlaylist);

0 commit comments

Comments
 (0)