Skip to content

Commit 02bb27a

Browse files
Update script.js
1 parent df48568 commit 02bb27a

File tree

1 file changed

+61
-160
lines changed

1 file changed

+61
-160
lines changed

script.js

Lines changed: 61 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,54 @@
1+
<script>
12
document.addEventListener("DOMContentLoaded", () => {
23
const notebookList = document.getElementById("notebook-list");
34

45
// Reordered notebooks from basics to advanced
56
const notebooks = [
67
// Python Fundamentals
7-
{
8-
filename: "Python Lists.ipynb",
9-
url: "notebooks/Python Lists.ipynb"
10-
},
11-
{
12-
filename: "Python Tuples.ipynb",
13-
url: "notebooks/Python Tuples.ipynb"
14-
},
15-
{
16-
filename: "Python Dictionaries.ipynb",
17-
url: "notebooks/Python Dictionaries.ipynb"
18-
},
19-
{
20-
filename: "Functions.ipynb",
21-
url: "notebooks/Functions.ipynb"
22-
},
23-
{
24-
filename: "Iterators.ipynb",
25-
url: "notebooks/Iterators.ipynb"
26-
},
27-
{
28-
filename: "List Comprehension.ipynb",
29-
url: "notebooks/List Comprehension.ipynb"
30-
},
31-
{
32-
filename: "Lamda functions-Part1.ipynb",
33-
url: "notebooks/Lamda functions-Part1.ipynb"
34-
},
35-
{
36-
filename: "Lamda functions-Part2.ipynb",
37-
url: "notebooks/Lamda functions-Part2.ipynb"
38-
},
39-
{
40-
filename: "Python Exceptions.ipynb",
41-
url: "notebooks/Python Exceptions.ipynb"
42-
},
43-
{
44-
filename: "Python Files.ipynb",
45-
url: "notebooks/Python Files.ipynb"
46-
},
47-
{
48-
filename: "getcwd().ipynb",
49-
url: "notebooks/getcwd().ipynb"
50-
},
8+
{ filename: "Python Lists.ipynb", url: "notebooks/Python%20Lists.ipynb" },
9+
{ filename: "Python Tuples.ipynb", url: "notebooks/Python%20Tuples.ipynb" },
10+
{ filename: "Python Dictionaries.ipynb", url: "notebooks/Python%20Dictionaries.ipynb" },
11+
{ filename: "Functions.ipynb", url: "notebooks/Functions.ipynb" },
12+
{ filename: "Iterators.ipynb", url: "notebooks/Iterators.ipynb" },
13+
{ filename: "List Comprehension.ipynb", url: "notebooks/List%20Comprehension.ipynb" },
14+
{ filename: "Lamda functions-Part1.ipynb", url: "notebooks/Lamda%20functions-Part1.ipynb" },
15+
{ filename: "Lamda functions-Part2.ipynb", url: "notebooks/Lamda%20functions-Part2.ipynb" },
16+
{ filename: "Python Exceptions.ipynb", url: "notebooks/Python%20Exceptions.ipynb" },
17+
{ filename: "Python Files.ipynb", url: "notebooks/Python%20Files.ipynb" },
18+
{ filename: "getcwd().ipynb", url: "notebooks/getcwd().ipynb" },
5119

5220
// Object-Oriented Programming (OOP)
53-
{
54-
filename: "OOP1_Lecture1.ipynb",
55-
url: "notebooks/OOP1_Lecture1.ipynb"
56-
},
57-
{
58-
filename: "OOP_All_in_One.ipynb",
59-
url: "notebooks/OOP_All_in_One.ipynb"
60-
},
21+
{ filename: "OOP1_Lecture1.ipynb", url: "notebooks/OOP1_Lecture1.ipynb" },
22+
{ filename: "OOP_All_in_One.ipynb", url: "notebooks/OOP_All_in_One.ipynb" },
6123

6224
// Numerical Computing (NumPy)
63-
{
64-
filename: "Numpy_lec1-part-a.ipynb",
65-
url: "notebooks/Numpy_lec1-part-a.ipynb"
66-
},
67-
{
68-
filename: "Numpy_lec2-3.ipynb",
69-
url: "notebooks/Numpy_lec2-3.ipynb"
70-
},
71-
{
72-
filename: "Numpy_Functions.ipynb",
73-
url: "notebooks/Numpy_Functions.ipynb"
74-
},
25+
{ filename: "Numpy_lec1-part-a.ipynb", url: "notebooks/Numpy_lec1-part-a.ipynb" },
26+
{ filename: "Numpy_lec2-3.ipynb", url: "notebooks/Numpy_lec2-3.ipynb" },
27+
{ filename: "Numpy_Functions.ipynb", url: "notebooks/Numpy_Functions.ipynb" },
7528

7629
// Data Analysis (Pandas)
77-
{
78-
filename: "12-13-Pandas Intro.ipynb",
79-
url: "notebooks/12-13-Pandas Intro.ipynb"
80-
},
81-
{
82-
filename: "13 Dataframes Updated.ipynb",
83-
url: "notebooks/13-Dataframes-updated.ipynb"
84-
},
85-
{
86-
filename: "16 Summary Statistics.ipynb",
87-
url: "notebooks/16-Pandas%20Dataframes-Summary%20Statistics.ipynb"
88-
},
89-
{
90-
filename: "17-Selecting-Elements.ipynb",
91-
url: "notebooks/17-Selecting-Elements.ipynb"
92-
},
30+
{ filename: "12-13-Pandas Intro.ipynb", url: "notebooks/12-13-Pandas%20Intro.ipynb" },
31+
{ filename: "13-Dataframes-updated.ipynb", url: "notebooks/13-Dataframes-updated.ipynb" },
32+
{ filename: "16 Summary Statistics.ipynb", url: "notebooks/16-Pandas%20Dataframes-Summary%20Statistics.ipynb" },
33+
{ filename: "17-Selecting-Elements.ipynb", url: "notebooks/17-Selecting-Elements.ipynb" },
9334

9435
// Machine Learning & NLP
95-
{
96-
filename: "KNN.ipynb",
97-
url: "notebooks/KNN.ipynb"
98-
},
99-
{
100-
filename: "Spam_ClassificationP1-7-May-2025.ipynb",
101-
url: "notebooks/Spam_ClassificationP1-7-May-2025.ipynb"
102-
},
103-
{
104-
filename: "Spam_ClassificationP2-9-5-2025.ipynb",
105-
url: "notebooks/Spam_ClassificationP2-9-5-2025.ipynb"
106-
},
107-
{
108-
filename: "Spam_ClassificationP3-14-May.ipynb",
109-
url: "notebooks/Spam_ClassificationP3-14-May.ipynb"
110-
},
111-
{
112-
filename: "Spam_Classification-16-May.ipynb",
113-
url: "notebooks/Spam_Classification-16-May.ipynb"
114-
},
115-
{
116-
filename: "Spam_Classification-bigrams.ipynb",
117-
url: "notebooks/Spam_Classification-bigrams.ipynb"
118-
},
119-
{
120-
filename: "n_gram of spam classification.ipynb",
121-
url: "notebooks/n_gram of spam classification.ipynb"
122-
},
123-
{
124-
filename: "n_gram of urdu dataset.ipynb",
125-
url: "notebooks/n_gram of urdu dataset.ipynb"
126-
},
127-
{
128-
filename: "Deep_learning.ipynb",
129-
url: "notebooks/Deep_learning.ipynb"
130-
},
36+
{ filename: "KNN.ipynb", url: "notebooks/KNN.ipynb" },
37+
{ filename: "Spam_ClassificationP1-7-May-2025.ipynb", url: "notebooks/Spam_ClassificationP1-7-May-2025.ipynb" },
38+
{ filename: "Spam_ClassificationP2-9-5-2025.ipynb", url: "notebooks/Spam_ClassificationP2-9-5-2025.ipynb" },
39+
{ filename: "Spam_ClassificationP3-14-May.ipynb", url: "notebooks/Spam_ClassificationP3-14-May.ipynb" },
40+
{ filename: "Spam_Classification-16-May.ipynb", url: "notebooks/Spam_Classification-16-May.ipynb" },
41+
{ filename: "Spam_Classification-bigrams.ipynb", url: "notebooks/Spam_Classification-bigrams.ipynb" },
42+
{ filename: "n_gram of spam classification.ipynb", url: "notebooks/n_gram%20of%20spam%20classification.ipynb" },
43+
{ filename: "n_gram of urdu dataset.ipynb", url: "notebooks/n_gram%20of%20urdu%20dataset.ipynb" },
44+
{ filename: "Deep_learning.ipynb", url: "notebooks/Deep_learning.ipynb" },
13145

13246
// Datasets
133-
{
134-
filename: "spam.csv",
135-
url: "notebooks/spam.csv"
136-
},
137-
{
138-
filename: "English.csv",
139-
url: "notebooks/English.csv"
140-
},
141-
{
142-
filename: "imdb_urdu_reviews_train.csv",
143-
url: "notebooks/imdb_urdu_reviews_train.csv"
144-
},
145-
{
146-
filename: "imdb_urdu_reviews_test.csv",
147-
url: "notebooks/imdb_urdu_reviews_test.csv"
148-
},
149-
{
150-
filename: "Advanced Python Programming and Applications.pdf",
151-
url: "notebooks/Advanced Python Programming and Applications.pdf"
152-
}
47+
{ filename: "spam.csv", url: "notebooks/spam.csv" },
48+
{ filename: "English.csv", url: "notebooks/English.csv" },
49+
{ filename: "imdb_urdu_reviews_train.csv", url: "notebooks/imdb_urdu_reviews_train.csv" },
50+
{ filename: "imdb_urdu_reviews_test.csv", url: "notebooks/imdb_urdu_reviews_test.csv" },
51+
{ filename: "Advanced Python Programming and Applications.pdf", url: "notebooks/Advanced%20Python%20Programming%20and%20Applications.pdf" }
15352
];
15453

15554
if (notebookList) {
@@ -173,38 +72,40 @@ document.addEventListener("DOMContentLoaded", () => {
17372

17473
notebookList.appendChild(notebookItem);
17574
});
75+
} else {
76+
console.error("Element with id 'notebook-list' not found.");
17677
}
17778
});
17879

179-
function forceDownload(url, filename, btn) {
80+
// Modern async download function
81+
async function forceDownload(url, filename, btn) {
18082
const originalText = btn.textContent;
18183
btn.textContent = "Preparing...";
18284
btn.disabled = true;
18385

184-
fetch(url)
185-
.then(response => {
186-
if (!response.ok) throw new Error("File not found");
187-
return response.blob();
188-
})
189-
.then(blob => {
190-
const blobUrl = window.URL.createObjectURL(blob);
191-
const a = document.createElement('a');
192-
a.href = blobUrl;
193-
a.download = filename;
194-
document.body.appendChild(a);
195-
a.click();
196-
a.remove();
197-
window.URL.revokeObjectURL(blobUrl);
86+
try {
87+
const response = await fetch(encodeURI(url));
88+
if (!response.ok) throw new Error("File not found");
19889

199-
btn.textContent = "Downloaded!";
200-
setTimeout(() => {
201-
btn.textContent = originalText;
202-
btn.disabled = false;
203-
}, 1500);
204-
})
205-
.catch(error => {
206-
alert("Download error: " + error.message);
90+
const blob = await response.blob();
91+
const blobUrl = window.URL.createObjectURL(blob);
92+
const a = document.createElement('a');
93+
a.href = blobUrl;
94+
a.download = filename;
95+
document.body.appendChild(a);
96+
a.click();
97+
a.remove();
98+
window.URL.revokeObjectURL(blobUrl);
99+
100+
btn.textContent = "Downloaded!";
101+
setTimeout(() => {
207102
btn.textContent = originalText;
208103
btn.disabled = false;
209-
});
104+
}, 1500);
105+
} catch (error) {
106+
alert("Download error: " + error.message);
107+
btn.textContent = originalText;
108+
btn.disabled = false;
109+
}
210110
}
111+
</script>

0 commit comments

Comments
 (0)