-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4simpleproblems-v5.html
More file actions
218 lines (193 loc) · 9.77 KB
/
4simpleproblems-v5.html
File metadata and controls
218 lines (193 loc) · 9.77 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
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>4SP - LOCAL CLIENT</title>
<base href="https://cdn.jsdelivr.net/gh/v5-4simpleproblems/v5@main/logged-in/">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
<style>
body { background-color: #040404; color: #c0c0c0; font-family: sans-serif; height: 100vh; margin: 0; display: flex; flex-direction: column; }
.center-box { margin: auto; padding: 2rem; background: #0d0d0d; border: 1px solid #333; border-radius: 1rem; max-width: 400px; width: 90%; text-align: center; }
.input-style { width: 100%; padding: 0.75rem; margin-bottom: 1rem; background: #111; border: 1px solid #333; color: white; border-radius: 0.5rem; text-align: center; letter-spacing: 2px; }
.btn-style { background: #4f46e5; color: white; padding: 0.75rem 1.5rem; border-radius: 0.5rem; font-weight: bold; cursor: pointer; border: none; width: 100%; }
.btn-style:hover { background: #4338ca; }
.error-msg { color: #ef4444; margin-top: 1rem; font-size: 0.875rem; }
#app-frame { width: 100%; height: 100%; border: none; display: none; flex-grow: 1; }
.hidden { display: none !important; }
#loading-text { color: #888; margin-top: 1rem; }
</style>
</head>
<body>
<div id="lock-screen" class="center-box">
<h1 class="text-2xl font-bold text-white mb-4">4SP v5 Local</h1>
<p class="text-gray-400 mb-6 text-sm">Enter your access code to unlock this secure file.</p>
<input type="text" id="codeInput" class="input-style" placeholder="XXXX-XXXX-XXXX">
<button id="unlockBtn" class="btn-style">Unlock</button>
<p id="lockMessage" class="error-msg"></p>
<p id="loading-text" class="hidden">Restoring data...</p>
</div>
<iframe id="app-frame"></iframe>
<!-- INJECTED DATA PLACEHOLDERS -->
<script>
window.__ACCESS_CODE__ = "{{ACCESS_CODE}}";
window.__USER_DATA__ = {{USER_DATA}};
</script>
<script type="module">
// Firebase Config included for reference/completeness as requested
const firebaseConfig = {
apiKey: "AIzaSyAZBKAckVa4IMvJGjcyndZx6Y1XD52lgro",
authDomain: "project-zirconium.firebaseapp.com",
projectId: "project-zirconium",
storageBucket: "project-zirconium.firebasestorage.app",
messagingSenderId: "1096564243475",
appId: "1:1096564243475:web:6d0956a70125eeea1ad3e6",
measurementId: "G-1D4F692C1Q"
};
const lockScreen = document.getElementById('lock-screen');
const appFrame = document.getElementById('app-frame');
const codeInput = document.getElementById('codeInput');
const unlockBtn = document.getElementById('unlockBtn');
const lockMessage = document.getElementById('lockMessage');
const loadingText = document.getElementById('loading-text');
const BASE_URL = 'https://cdn.jsdelivr.net/gh/v5-4simpleproblems/v5@main/logged-in/';
// Check if data is present
if (!window.__ACCESS_CODE__ || window.__ACCESS_CODE__ === "{{ACCESS_CODE}}") {
lockMessage.innerText = "Error: This file is corrupt or missing embedded data.";
unlockBtn.disabled = true;
unlockBtn.style.opacity = "0.5";
}
unlockBtn.addEventListener('click', async () => {
const code = codeInput.value.trim();
if (!code) {
lockMessage.innerText = "Please enter a code.";
return;
}
if (code !== window.__ACCESS_CODE__) {
lockMessage.innerText = "Invalid access code.";
return;
}
// Code is valid
lockMessage.innerText = "";
unlockBtn.classList.add('hidden');
codeInput.classList.add('hidden');
loadingText.classList.remove('hidden');
try {
await restoreUserData();
// Start with dashboard
loadPage('dashboard.html');
} catch (e) {
lockMessage.innerText = "Failed to restore data: " + e.message;
console.error(e);
}
});
async function restoreUserData() {
const data = window.__USER_DATA__;
if (!data) return;
// 1. Restore LocalStorage
if (data.localStorage) {
for (const [key, value] of Object.entries(data.localStorage)) {
localStorage.setItem(key, value);
}
}
// 2. Restore IndexedDB
if (data.indexedDB) {
for (const dbName in data.indexedDB) {
const storesData = data.indexedDB[dbName];
await new Promise(r => {
const req = indexedDB.deleteDatabase(dbName);
req.onsuccess = r; req.onerror = r;
});
await new Promise((resolve, reject) => {
const req = indexedDB.open(dbName, 1);
req.onupgradeneeded = (e) => {
const db = e.target.result;
for (const storeName in storesData) {
if (!db.objectStoreNames.contains(storeName)) {
db.createObjectStore(storeName);
}
}
};
req.onsuccess = async (e) => {
const db = e.target.result;
const tx = db.transaction(Object.keys(storesData), 'readwrite');
for (const storeName in storesData) {
const store = tx.objectStore(storeName);
for (const item of storesData[storeName]) {
store.put(item.value, item.key);
}
}
tx.oncomplete = () => {
db.close();
resolve();
};
tx.onerror = (err) => reject(err);
};
req.onerror = reject;
});
}
}
}
// Exposed function to load pages
window.loadPage = function(pageName) {
// Handle relative paths roughly
if (pageName.startsWith('./')) pageName = pageName.substring(2);
if (pageName.startsWith('../')) pageName = pageName.substring(3); // Assuming flattened structure for simplified view
// If full URL, strip base
if (pageName.startsWith(BASE_URL)) {
pageName = pageName.substring(BASE_URL.length);
}
const url = BASE_URL + pageName;
fetch(url)
.then(res => res.text())
.then(html => {
lockScreen.classList.add('hidden');
appFrame.style.display = 'block';
const doc = appFrame.contentWindow.document;
doc.open();
const baseTag = '<base href="' + BASE_URL + '">';
// Script to intercept clicks and keep them "local" (in the iframe fetch loop)
// Also mock Auth
const patchScript = `
<script>
window._LOCAL_MODE = true;
// Mock Firebase Auth User if profile exists
try {
const profile = localStorage.getItem('offline_user_profile');
if (profile) {
const userData = JSON.parse(profile);
// Mock enough for the UI to render
window.currentUser = {
uid: 'offline-user',
displayName: userData.username || 'Offline User',
email: 'offline@local',
photoURL: userData.customPfp || null,
providerData: []
};
}
} catch(e) {}
document.addEventListener('click', e => {
const link = e.target.closest('a');
if (link && link.href) {
e.preventDefault();
const href = link.getAttribute('href');
// Call parent loader
window.parent.loadPage(href);
}
});
<\/script>
`;
let modifiedHtml = html.replace('<head>', '<head>' + baseTag + patchScript);
doc.write(modifiedHtml);
doc.close();
})
.catch(err => {
// If dashboard fails, we show lock screen again? Or alert inside frame?
console.error(err);
alert("Failed to load page: " + pageName);
});
};
</script>
</body>
</html>