-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
219 lines (189 loc) · 7.76 KB
/
Copy pathscript.js
File metadata and controls
219 lines (189 loc) · 7.76 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// --- Data Configuration ---
const chapters = [
{
id: 13, name: "ALIPUR",
video: "https://drive.google.com/file/d/15ep3wbj92XNFoB-3WMk5Ayro6j8xr1AW/preview",
pdf: "https://drive.google.com/file/d/1Kr2o33yzxIX0nrdIMc4azZz5SqT8gLdf/preview",
dl: "https://drive.google.com/uc?export=download&id=1Kr2o33yzxIX0nrdIMc4azZz5SqT8gLdf"
},
{
id: 14, name: "MEMARI VM",
video: "https://drive.google.com/file/d/1xcZ6MBx0SkR0icYNzYQSR432Uoll71-t/preview",
pdf: "https://drive.google.com/file/d/15A2BGbE94hBC-RjNb9bf8iYdOFVLpPYe/preview",
dl: "https://drive.google.com/uc?export=download&id=15A2BGbE94hBC-RjNb9bf8iYdOFVLpPYe"
},
{
id: 15, name: "BANKURA CHRISTIAN",
video: "https://drive.google.com/file/d/1dGwmXW24N5R8v4ciuHSaDOI9048sAoxX/preview",
pdf: "https://drive.google.com/file/d/1Niw7qutrHlftvmY9LIQZ4yXZnF7UQBH-/preview",
dl: "https://drive.google.com/uc?export=download&id=1Niw7qutrHlftvmY9LIQZ4yXZnF7UQBH-"
},
{
id: 16, name: "JALPAIGURI",
video: "https://drive.google.com/file/d/1z8X3qdERSuwViD59k1R38D_Z_IxUSgqy/preview",
pdf: "https://drive.google.com/file/d/1Pfxd58Ci-kinsIg7km_U698uEs-O3eeF/preview",
dl: "https://drive.google.com/uc?export=download&id=1Pfxd58Ci-kinsIg7km_U698uEs-O3eeF"
},
{
id: 17, name: "NIMPITH",
video: "https://drive.google.com/file/d/1Alx9Tz2wlpd8tAyoIj5OvQQzKwERWfzq/preview",
pdf: "https://drive.google.com/file/d/1t_nnJxBTKk2JPuwQt7fi7ZjDXjBEV4Y5/preview",
dl: "https://drive.google.com/uc?export=download&id=1t_nnJxBTKk2JPuwQt7fi7ZjDXjBEV4Y5"
},
{
id: 18, name: "SILIGURI",
video: "https://drive.google.com/file/d/1bYHO6alTyoEuYBQyKHO0guQmKRsmgrSv/preview",
pdf: "https://drive.google.com/file/d/1tml81LYmxWlpdIuvVnxeSqQrJ8zjyDP6/preview",
dl: "https://drive.google.com/uc?export=download&id=1tml81LYmxWlpdIuvVnxeSqQrJ8zjyDP6"
}
];
// --- Initialization ---
document.addEventListener('DOMContentLoaded', () => {
initStars(); // Load saved stars
renderChapterList();
handleRouting(); // Check current URL
});
window.addEventListener('hashchange', handleRouting);
// --- Routing (The Fix for Back Button) ---
function handleRouting() {
const hash = window.location.hash;
// Hide all views first
document.querySelectorAll('.page-view').forEach(v => v.classList.add('hidden'));
document.getElementById('nav-title').innerText = "Home";
closeAllDropdowns();
if (!hash || hash === '#home') {
document.getElementById('view-home').classList.remove('hidden');
document.getElementById('nav-title').innerText = "Chapter List";
}
else if (hash.startsWith('#chapter/')) {
const id = parseInt(hash.split('/')[1]);
showChapterDetail(id);
}
else if (hash.startsWith('#player/')) {
// format: #player/video/13 or #player/pdf/13
const parts = hash.split('/');
const type = parts[1];
const id = parseInt(parts[2]);
showPlayer(type, id);
}
}
// --- Render Home List ---
function renderChapterList() {
const list = document.getElementById('chapter-list');
list.innerHTML = '';
chapters.forEach((chap) => {
const isStarred = localStorage.getItem(`star_${chap.id}`) === 'true';
const card = document.createElement('div');
card.className = `chapter-card ${isStarred ? 'starred' : ''}`;
card.id = `card-${chap.id}`;
card.innerHTML = `
<div class="card-left" onclick="location.hash='#chapter/${chap.id}'">
<span class="chap-id">CHAPTER ${chap.id}</span>
<div class="chap-name">${chap.name}</div>
</div>
<span class="material-icons star-indicator">star</span>
<div class="menu-btn" onclick="toggleDropdown(event, ${chap.id})">
<span class="material-icons">more_vert</span>
</div>
<div class="dropdown" id="dd-${chap.id}">
<div class="dd-item" onclick="window.open('${chap.dl}', '_blank')">Download PDF</div>
<div class="dd-item" onclick="toggleStar(${chap.id})">
${isStarred ? 'Unstar' : 'Star Mark'}
</div>
</div>
`;
list.appendChild(card);
});
}
// --- Detail View Logic ---
function showChapterDetail(id) {
const chap = chapters.find(c => c.id === id);
if (!chap) return;
document.getElementById('view-chapter').classList.remove('hidden');
document.getElementById('nav-title').innerText = `${chap.id}. ${chap.name}`;
// Setup buttons
document.getElementById('btn-open-pdf').onclick = () => {
location.hash = `#player/pdf/${id}`;
};
document.getElementById('btn-open-video').onclick = () => {
location.hash = `#player/video/${id}`;
};
}
// --- Player Logic ---
function showPlayer(type, id) {
const chap = chapters.find(c => c.id === id);
const playerView = document.getElementById('view-player');
const iframe = document.getElementById('main-frame');
const title = document.getElementById('player-title');
playerView.classList.remove('hidden');
if (type === 'video') {
title.innerText = "Video: " + chap.name;
iframe.src = chap.video;
} else {
title.innerText = "Solution: " + chap.name;
iframe.src = chap.pdf;
}
// Nav Buttons
const currentIndex = chapters.findIndex(c => c.id === id);
document.getElementById('prev-chap-btn').onclick = () => {
if (currentIndex > 0) {
location.hash = `#player/${type}/${chapters[currentIndex - 1].id}`;
} else alert("First Chapter");
};
document.getElementById('next-chap-btn').onclick = () => {
if (currentIndex < chapters.length - 1) {
location.hash = `#player/${type}/${chapters[currentIndex + 1].id}`;
} else alert("Last Chapter");
};
}
// --- Features ---
// Star Feature
function initStars() {
// Just ensures storage is ready, no explicit action needed
}
function toggleStar(id) {
const key = `star_${id}`;
const current = localStorage.getItem(key) === 'true';
localStorage.setItem(key, !current);
renderChapterList(); // Re-render to update UI
}
// Sidebar
function toggleSidebar() {
document.getElementById('sidebar').classList.toggle('active');
const overlay = document.getElementById('overlay');
overlay.style.display = overlay.style.display === 'block' ? 'none' : 'block';
}
// Dropdowns
function toggleDropdown(e, id) {
e.stopPropagation();
closeAllDropdowns();
document.getElementById(`dd-${id}`).classList.add('show');
}
function closeAllDropdowns() {
document.querySelectorAll('.dropdown').forEach(el => el.classList.remove('show'));
}
window.onclick = function(event) {
if (!event.target.closest('.menu-btn')) {
closeAllDropdowns();
}
};
// Landscape
function toggleLandscape() {
document.getElementById('player-wrapper').classList.toggle('landscape');
}
// Info Modals
const infoContent = {
info: { title: "App Info", body: "Version 2.0<br>Built for Class 11 Semester 2 Math." },
about: { title: "About", body: "This tool helps students access Ray & Martin solutions quickly and efficiently without lag." },
creator: { title: "Creator", body: "Created by: <b>Faltu Chele</b><br>Dedication to learning." }
};
function showModal(type) {
toggleSidebar();
const data = infoContent[type];
document.getElementById('modal-title').innerHTML = data.title;
document.getElementById('modal-body').innerHTML = data.body;
document.getElementById('info-modal').classList.remove('hidden');
}
function closeModal() {
document.getElementById('info-modal').classList.add('hidden');
}