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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
import os, re, json
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
# ────────────────────────── 1. CONFIGURATION ──────────────────────────
|
7 |
+
DB_FILE = "favorite_sites.json" # Database file for user-saved sites
|
8 |
+
|
9 |
+
# Domains that commonly block iframes
|
10 |
+
BLOCKED_DOMAINS = [
|
11 |
+
"naver.com", "daum.net", "google.com",
|
12 |
+
"facebook.com", "instagram.com", "kakao.com",
|
13 |
+
"ycombinator.com"
|
14 |
+
]
|
15 |
+
|
16 |
+
# ────────────────────────── 2. CURATED CATEGORIES ──────────────────────────
|
17 |
+
CATEGORIES = {
|
18 |
+
"Free AI: Productivity": [
|
19 |
+
"https://huggingface.co/spaces/ginigen/perflexity-clone",
|
20 |
+
"https://huggingface.co/spaces/ginipick/IDEA-DESIGN",
|
21 |
+
"https://huggingface.co/spaces/VIDraft/mouse-webgen",
|
22 |
+
"https://huggingface.co/spaces/openfree/Vibe-Game",
|
23 |
+
"https://huggingface.co/spaces/openfree/Game-Gallery",
|
24 |
+
"https://huggingface.co/spaces/aiqtech/Contributors-Leaderboard",
|
25 |
+
"https://huggingface.co/spaces/fantaxy/Model-Leaderboard",
|
26 |
+
"https://huggingface.co/spaces/fantaxy/Space-Leaderboard",
|
27 |
+
"https://huggingface.co/spaces/openfree/Korean-Leaderboard",
|
28 |
+
],
|
29 |
+
"Free AI: Multimodal": [
|
30 |
+
"https://huggingface.co/spaces/openfree/DreamO-video",
|
31 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",
|
32 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-Uncensored",
|
33 |
+
"https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
|
34 |
+
"https://huggingface.co/spaces/ginigen/SFX-Sound-magic",
|
35 |
+
"https://huggingface.co/spaces/ginigen/VoiceClone-TTS",
|
36 |
+
"https://huggingface.co/spaces/aiqcamp/MCP-kokoro",
|
37 |
+
"https://huggingface.co/spaces/aiqcamp/ENGLISH-Speaking-Scoring",
|
38 |
+
],
|
39 |
+
"Free AI: Professional": [
|
40 |
+
"https://huggingface.co/spaces/ginigen/blogger",
|
41 |
+
"https://huggingface.co/spaces/VIDraft/money-radar",
|
42 |
+
"https://huggingface.co/spaces/immunobiotech/drug-discovery",
|
43 |
+
"https://huggingface.co/spaces/immunobiotech/Gemini-MICHELIN",
|
44 |
+
"https://huggingface.co/spaces/Heartsync/Papers-Leaderboard",
|
45 |
+
"https://huggingface.co/spaces/VIDraft/PapersImpact",
|
46 |
+
"https://huggingface.co/spaces/ginipick/AgentX-Papers",
|
47 |
+
"https://huggingface.co/spaces/openfree/Cycle-Navigator",
|
48 |
+
],
|
49 |
+
"Free AI: Image": [
|
50 |
+
"https://huggingface.co/spaces/ginigen/interior-design",
|
51 |
+
"https://huggingface.co/spaces/ginigen/Workflow-Canvas",
|
52 |
+
"https://huggingface.co/spaces/ginigen/Multi-LoRAgen",
|
53 |
+
"https://huggingface.co/spaces/ginigen/Every-Text",
|
54 |
+
"https://huggingface.co/spaces/ginigen/text3d-r1",
|
55 |
+
"https://huggingface.co/spaces/ginipick/FLUXllama",
|
56 |
+
"https://huggingface.co/spaces/Heartsync/FLUX-Vision",
|
57 |
+
"https://huggingface.co/spaces/ginigen/VisualCloze",
|
58 |
+
"https://huggingface.co/spaces/seawolf2357/Ghibli-Multilingual-Text-rendering",
|
59 |
+
"https://huggingface.co/spaces/ginigen/Ghibli-Meme-Studio",
|
60 |
+
"https://huggingface.co/spaces/VIDraft/Open-Meme-Studio",
|
61 |
+
"https://huggingface.co/spaces/ginigen/3D-LLAMA",
|
62 |
+
],
|
63 |
+
"Free AI: LLM / VLM": [
|
64 |
+
"https://huggingface.co/spaces/VIDraft/Gemma-3-R1984-4B",
|
65 |
+
"https://huggingface.co/spaces/VIDraft/Gemma-3-R1984-12B",
|
66 |
+
"https://huggingface.co/spaces/ginigen/Mistral-Perflexity",
|
67 |
+
"https://huggingface.co/spaces/aiqcamp/gemini-2.5-flash-preview",
|
68 |
+
"https://huggingface.co/spaces/openfree/qwen3-30b-a3b-research",
|
69 |
+
"https://huggingface.co/spaces/openfree/qwen3-235b-a22b-research",
|
70 |
+
"https://huggingface.co/spaces/openfree/Llama-4-Maverick-17B-Research",
|
71 |
+
],
|
72 |
+
}
|
73 |
+
|
74 |
+
# ────────────────────────── 3. DATABASE FUNCTIONS ──────────────────────────
|
75 |
+
def init_db():
|
76 |
+
if not os.path.exists(DB_FILE):
|
77 |
+
with open(DB_FILE, "w", encoding="utf-8") as f:
|
78 |
+
json.dump([], f, ensure_ascii=False)
|
79 |
+
|
80 |
+
def load_db():
|
81 |
+
try:
|
82 |
+
with open(DB_FILE, "r", encoding="utf-8") as f:
|
83 |
+
raw = json.load(f)
|
84 |
+
return raw if isinstance(raw, list) else []
|
85 |
+
except Exception:
|
86 |
+
return []
|
87 |
+
|
88 |
+
def save_db(lst):
|
89 |
+
try:
|
90 |
+
with open(DB_FILE, "w", encoding="utf-8") as f:
|
91 |
+
json.dump(lst, f, ensure_ascii=False, indent=2)
|
92 |
+
return True
|
93 |
+
except Exception:
|
94 |
+
return False
|
95 |
+
|
96 |
+
# ────────────────────────── 4. URL HELPERS ──────────────────────────
|
97 |
+
def direct_url(hf_url):
|
98 |
+
m = re.match(r"https?://huggingface\.co/spaces/([^/]+)/([^/?#]+)", hf_url)
|
99 |
+
if not m:
|
100 |
+
return hf_url
|
101 |
+
owner, name = m.groups()
|
102 |
+
owner = owner.lower()
|
103 |
+
name = name.replace('.', '-').replace('_', '-').lower()
|
104 |
+
return f"https://{owner}-{name}.hf.space"
|
105 |
+
|
106 |
+
def screenshot_url(url):
|
107 |
+
return f"https://image.thum.io/get/fullpage/{url}"
|
108 |
+
|
109 |
+
def process_url_for_preview(url):
|
110 |
+
"""Returns (preview_url, mode)"""
|
111 |
+
# Handle blocked domains first
|
112 |
+
if any(d for d in BLOCKED_DOMAINS if d in url):
|
113 |
+
return screenshot_url(url), "snapshot"
|
114 |
+
|
115 |
+
# Special case handling for problematic URLs
|
116 |
+
if "vibe-coding-tetris" in url or "World-of-Tank-GAME" in url or "Minesweeper-Game" in url:
|
117 |
+
return screenshot_url(url), "snapshot"
|
118 |
+
|
119 |
+
# General HF space handling
|
120 |
+
try:
|
121 |
+
if "huggingface.co/spaces" in url:
|
122 |
+
parts = url.rstrip("/").split("/")
|
123 |
+
if len(parts) >= 5:
|
124 |
+
owner = parts[-2]
|
125 |
+
name = parts[-1]
|
126 |
+
embed_url = f"https://huggingface.co/spaces/{owner}/{name}/embed"
|
127 |
+
return embed_url, "iframe"
|
128 |
+
except Exception:
|
129 |
+
return screenshot_url(url), "snapshot"
|
130 |
+
|
131 |
+
# Default handling
|
132 |
+
return url, "iframe"
|
133 |
+
|
134 |
+
# ────────────────────────── 5. API ROUTES ──────────────────────────
|
135 |
+
@app.route('/api/category')
|
136 |
+
def api_category():
|
137 |
+
cat = request.args.get('name', '')
|
138 |
+
urls = CATEGORIES.get(cat, [])
|
139 |
+
return jsonify([
|
140 |
+
{
|
141 |
+
"title": url.split('/')[-1],
|
142 |
+
"owner": url.split('/')[-2] if '/spaces/' in url else '',
|
143 |
+
"iframe": direct_url(url),
|
144 |
+
"shot": screenshot_url(url),
|
145 |
+
"hf": url
|
146 |
+
} for url in urls
|
147 |
+
])
|
148 |
+
|
149 |
+
@app.route('/api/favorites')
|
150 |
+
def api_favorites():
|
151 |
+
urls = load_db()
|
152 |
+
page = int(request.args.get('page', 1))
|
153 |
+
per_page = int(request.args.get('per_page', 9))
|
154 |
+
|
155 |
+
total_pages = max(1, (len(urls) + per_page - 1) // per_page)
|
156 |
+
start = (page - 1) * per_page
|
157 |
+
end = min(start + per_page, len(urls))
|
158 |
+
|
159 |
+
urls_page = urls[start:end]
|
160 |
+
|
161 |
+
result = []
|
162 |
+
for url in urls_page:
|
163 |
+
try:
|
164 |
+
preview_url, mode = process_url_for_preview(url)
|
165 |
+
result.append({
|
166 |
+
"title": url.split('/')[-1],
|
167 |
+
"url": url,
|
168 |
+
"preview_url": preview_url,
|
169 |
+
"mode": mode
|
170 |
+
})
|
171 |
+
except Exception:
|
172 |
+
# Fallback to screenshot mode
|
173 |
+
result.append({
|
174 |
+
"title": url.split('/')[-1],
|
175 |
+
"url": url,
|
176 |
+
"preview_url": screenshot_url(url),
|
177 |
+
"mode": "snapshot"
|
178 |
+
})
|
179 |
+
|
180 |
+
return jsonify({
|
181 |
+
"items": result,
|
182 |
+
"page": page,
|
183 |
+
"total_pages": total_pages
|
184 |
+
})
|
185 |
+
|
186 |
+
@app.route('/api/url/add', methods=['POST'])
|
187 |
+
def add_url():
|
188 |
+
url = request.form.get('url', '').strip()
|
189 |
+
if not url:
|
190 |
+
return jsonify({"success": False, "message": "URL is required"})
|
191 |
+
|
192 |
+
data = load_db()
|
193 |
+
if url in data:
|
194 |
+
return jsonify({"success": False, "message": "URL already exists"})
|
195 |
+
|
196 |
+
data.insert(0, url)
|
197 |
+
save_db(data)
|
198 |
+
return jsonify({"success": True, "message": "URL added successfully"})
|
199 |
+
|
200 |
+
@app.route('/api/url/update', methods=['POST'])
|
201 |
+
def update_url():
|
202 |
+
old = request.form.get('old', '')
|
203 |
+
new = request.form.get('new', '').strip()
|
204 |
+
|
205 |
+
if not new:
|
206 |
+
return jsonify({"success": False, "message": "New URL is required"})
|
207 |
+
|
208 |
+
data = load_db()
|
209 |
+
try:
|
210 |
+
idx = data.index(old)
|
211 |
+
data[idx] = new
|
212 |
+
save_db(data)
|
213 |
+
return jsonify({"success": True, "message": "URL updated successfully"})
|
214 |
+
except ValueError:
|
215 |
+
return jsonify({"success": False, "message": "URL not found"})
|
216 |
+
|
217 |
+
@app.route('/api/url/delete', methods=['POST'])
|
218 |
+
def delete_url():
|
219 |
+
url = request.form.get('url', '')
|
220 |
+
data = load_db()
|
221 |
+
try:
|
222 |
+
data.remove(url)
|
223 |
+
save_db(data)
|
224 |
+
return jsonify({"success": True, "message": "URL deleted successfully"})
|
225 |
+
except ValueError:
|
226 |
+
return jsonify({"success": False, "message": "URL not found"})
|
227 |
+
|
228 |
+
# ────────────────────────── 6. MAIN ROUTES ──────────────────────────
|
229 |
+
@app.route('/')
|
230 |
+
def home():
|
231 |
+
os.makedirs('templates', exist_ok=True)
|
232 |
+
|
233 |
+
with open('templates/index.html', 'w', encoding='utf-8') as fp:
|
234 |
+
fp.write(r'''<!DOCTYPE html>
|
235 |
+
<html>
|
236 |
+
<head>
|
237 |
+
<meta charset="utf-8">
|
238 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
239 |
+
<title>Web Gallery</title>
|
240 |
+
<style>
|
241 |
+
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;600&display=swap');
|
242 |
+
body{margin:0;font-family:Nunito,sans-serif;background:#f6f8fb;}
|
243 |
+
.tabs{display:flex;flex-wrap:wrap;gap:8px;padding:16px;}
|
244 |
+
.tab{padding:6px 14px;border:none;border-radius:18px;background:#e2e8f0;font-weight:600;cursor:pointer;}
|
245 |
+
.tab.active{background:#a78bfa;color:#1a202c;}
|
246 |
+
.tab.manage{background:#ff6e91;color:white;}
|
247 |
+
.tab.manage.active{background:#ff2d62;color:white;}
|
248 |
+
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:14px;padding:0 16px 60px;}
|
249 |
+
@media(max-width:800px){.grid{grid-template-columns:1fr;}}
|
250 |
+
.card{background:#fff;border-radius:12px;box-shadow:0 2px 8px rgba(0,0,0,.08);overflow:hidden;height:420px;display:flex;flex-direction:column;position:relative;}
|
251 |
+
.frame{flex:1;position:relative;overflow:hidden;}
|
252 |
+
.frame iframe{position:absolute;width:166.667%;height:166.667%;transform:scale(.6);transform-origin:top left;border:0;}
|
253 |
+
.frame img{width:100%;height:100%;object-fit:cover;}
|
254 |
+
.card-label{position:absolute;top:10px;left:10px;padding:4px 8px;border-radius:4px;font-size:11px;font-weight:bold;z-index:100;text-transform:uppercase;letter-spacing:0.5px;box-shadow:0 2px 4px rgba(0,0,0,0.2);}
|
255 |
+
.label-live{background:linear-gradient(135deg, #00c6ff, #0072ff);color:white;}
|
256 |
+
.label-static{background:linear-gradient(135deg, #ff9a9e, #fad0c4);color:#333;}
|
257 |
+
.foot{height:44px;background:#fafafa;display:flex;align-items:center;justify-content:center;border-top:1px solid #eee;}
|
258 |
+
.foot a{font-size:.82rem;font-weight:700;color:#4a6dd8;text-decoration:none;}
|
259 |
+
.pagination{display:flex;justify-content:center;margin:20px 0;gap:10px;}
|
260 |
+
.pagination button{padding:5px 15px;border:none;border-radius:20px;background:#e2e8f0;cursor:pointer;}
|
261 |
+
.pagination button:disabled{opacity:0.5;cursor:not-allowed;}
|
262 |
+
.manage-panel{background:white;border-radius:12px;box-shadow:0 2px 8px rgba(0,0,0,.08);margin:16px;padding:20px;}
|
263 |
+
.form-group{margin-bottom:15px;}
|
264 |
+
.form-group label{display:block;margin-bottom:5px;font-weight:600;}
|
265 |
+
.form-control{width:100%;padding:8px;border:1px solid #ddd;border-radius:4px;box-sizing:border-box;}
|
266 |
+
.btn{padding:8px 15px;border:none;border-radius:4px;cursor:pointer;font-weight:600;}
|
267 |
+
.btn-primary{background:#4a6dd8;color:white;}
|
268 |
+
.btn-danger{background:#e53e3e;color:white;}
|
269 |
+
.btn-success{background:#38a169;color:white;}
|
270 |
+
.status{padding:10px;margin:10px 0;border-radius:4px;display:none;}
|
271 |
+
.status.success{display:block;background:#c6f6d5;color:#22543d;}
|
272 |
+
.status.error{display:block;background:#fed7d7;color:#822727;}
|
273 |
+
.url-list{margin:20px 0;border:1px solid #eee;border-radius:4px;max-height:300px;overflow-y:auto;}
|
274 |
+
.url-item{padding:10px;border-bottom:1px solid #eee;display:flex;justify-content:space-between;align-items:center;}
|
275 |
+
.url-item:last-child{border-bottom:none;}
|
276 |
+
.url-controls{display:flex;gap:5px;}
|
277 |
+
</style>
|
278 |
+
</head>
|
279 |
+
<body>
|
280 |
+
<div class="tabs" id="tabs"></div>
|
281 |
+
<div id="content"></div>
|
282 |
+
<script>
|
283 |
+
// Basic configuration
|
284 |
+
const cats = {{cats|tojson}};
|
285 |
+
const tabs = document.getElementById('tabs');
|
286 |
+
const content = document.getElementById('content');
|
287 |
+
let active = "";
|
288 |
+
let currentPage = 1;
|
289 |
+
// Simple utility functions
|
290 |
+
function loadHTML(url, callback) {
|
291 |
+
const xhr = new XMLHttpRequest();
|
292 |
+
xhr.open('GET', url, true);
|
293 |
+
xhr.onreadystatechange = function() {
|
294 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
295 |
+
callback(xhr.responseText);
|
296 |
+
}
|
297 |
+
};
|
298 |
+
xhr.send();
|
299 |
+
}
|
300 |
+
function makeRequest(url, method, data, callback) {
|
301 |
+
const xhr = new XMLHttpRequest();
|
302 |
+
xhr.open(method, url, true);
|
303 |
+
xhr.onreadystatechange = function() {
|
304 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
305 |
+
callback(JSON.parse(xhr.responseText));
|
306 |
+
}
|
307 |
+
};
|
308 |
+
if (method === 'POST') {
|
309 |
+
xhr.send(data);
|
310 |
+
} else {
|
311 |
+
xhr.send();
|
312 |
+
}
|
313 |
+
}
|
314 |
+
function updateTabs() {
|
315 |
+
Array.from(tabs.children).forEach(b => {
|
316 |
+
b.classList.toggle('active', b.dataset.c === active);
|
317 |
+
});
|
318 |
+
}
|
319 |
+
// Tab handlers
|
320 |
+
function loadCategory(cat) {
|
321 |
+
if(cat === active) return;
|
322 |
+
active = cat;
|
323 |
+
updateTabs();
|
324 |
+
|
325 |
+
content.innerHTML = '<p style="text-align:center;padding:40px">Loading…</p>';
|
326 |
+
|
327 |
+
makeRequest('/api/category?name=' + encodeURIComponent(cat), 'GET', null, function(data) {
|
328 |
+
let html = '<div class="grid">';
|
329 |
+
|
330 |
+
data.forEach(item => {
|
331 |
+
html += `
|
332 |
+
<div class="card">
|
333 |
+
<div class="frame">
|
334 |
+
<iframe src="${item.iframe}" loading="lazy" sandbox="allow-forms allow-modals allow-popups allow-same-origin allow-scripts allow-downloads"></iframe>
|
335 |
+
</div>
|
336 |
+
<div class="foot">
|
337 |
+
<a href="${item.hf}" target="_blank">${item.title}</a>
|
338 |
+
</div>
|
339 |
+
</div>
|
340 |
+
`;
|
341 |
+
});
|
342 |
+
|
343 |
+
html += '</div>';
|
344 |
+
content.innerHTML = html;
|
345 |
+
});
|
346 |
+
}
|
347 |
+
function loadFavorites(page) {
|
348 |
+
if(active === 'Favorites' && currentPage === page) return;
|
349 |
+
active = 'Favorites';
|
350 |
+
currentPage = page || 1;
|
351 |
+
updateTabs();
|
352 |
+
|
353 |
+
content.innerHTML = '<p style="text-align:center;padding:40px">Loading…</p>';
|
354 |
+
|
355 |
+
makeRequest('/api/favorites?page=' + currentPage, 'GET', null, function(data) {
|
356 |
+
let html = '<div class="grid">';
|
357 |
+
|
358 |
+
if(data.items.length === 0) {
|
359 |
+
html += '<p style="grid-column:1/-1;text-align:center;padding:40px">No favorites saved yet.</p>';
|
360 |
+
} else {
|
361 |
+
data.items.forEach(item => {
|
362 |
+
if(item.mode === 'snapshot') {
|
363 |
+
html += `
|
364 |
+
<div class="card">
|
365 |
+
<div class="card-label label-static">Static</div>
|
366 |
+
<div class="frame">
|
367 |
+
<img src="${item.preview_url}" loading="lazy">
|
368 |
+
</div>
|
369 |
+
<div class="foot">
|
370 |
+
<a href="${item.url}" target="_blank">${item.title}</a>
|
371 |
+
</div>
|
372 |
+
</div>
|
373 |
+
`;
|
374 |
+
} else {
|
375 |
+
html += `
|
376 |
+
<div class="card">
|
377 |
+
<div class="card-label label-live">LIVE</div>
|
378 |
+
<div class="frame">
|
379 |
+
<iframe src="${item.preview_url}" loading="lazy" sandbox="allow-forms allow-modals allow-popups allow-same-origin allow-scripts allow-downloads"></iframe>
|
380 |
+
</div>
|
381 |
+
<div class="foot">
|
382 |
+
<a href="${item.url}" target="_blank">${item.title}</a>
|
383 |
+
</div>
|
384 |
+
</div>
|
385 |
+
`;
|
386 |
+
}
|
387 |
+
});
|
388 |
+
}
|
389 |
+
|
390 |
+
html += '</div>';
|
391 |
+
|
392 |
+
// Add pagination
|
393 |
+
html += `
|
394 |
+
<div class="pagination">
|
395 |
+
<button ${currentPage <= 1 ? 'disabled' : ''} onclick="loadFavorites(${currentPage-1})">« Previous</button>
|
396 |
+
<span>Page ${currentPage} of ${data.total_pages}</span>
|
397 |
+
<button ${currentPage >= data.total_pages ? 'disabled' : ''} onclick="loadFavorites(${currentPage+1})">Next »</button>
|
398 |
+
</div>
|
399 |
+
`;
|
400 |
+
|
401 |
+
content.innerHTML = html;
|
402 |
+
});
|
403 |
+
}
|
404 |
+
function loadManage() {
|
405 |
+
if(active === 'Manage') return;
|
406 |
+
active = 'Manage';
|
407 |
+
updateTabs();
|
408 |
+
|
409 |
+
content.innerHTML = `
|
410 |
+
<div class="manage-panel">
|
411 |
+
<h2>Add New URL</h2>
|
412 |
+
<div class="form-group">
|
413 |
+
<label for="new-url">URL</label>
|
414 |
+
<input type="text" id="new-url" class="form-control" placeholder="https://example.com">
|
415 |
+
</div>
|
416 |
+
<button onclick="addUrl()" class="btn btn-primary">Add URL</button>
|
417 |
+
<div id="add-status" class="status"></div>
|
418 |
+
|
419 |
+
<h2>Manage Saved URLs</h2>
|
420 |
+
<div id="url-list" class="url-list">Loading...</div>
|
421 |
+
</div>
|
422 |
+
`;
|
423 |
+
|
424 |
+
loadUrlList();
|
425 |
+
}
|
426 |
+
// URL management functions
|
427 |
+
function loadUrlList() {
|
428 |
+
makeRequest('/api/favorites?per_page=100', 'GET', null, function(data) {
|
429 |
+
const urlList = document.getElementById('url-list');
|
430 |
+
|
431 |
+
if(data.items.length === 0) {
|
432 |
+
urlList.innerHTML = '<p style="text-align:center;padding:20px">No URLs saved yet.</p>';
|
433 |
+
return;
|
434 |
+
}
|
435 |
+
|
436 |
+
let html = '';
|
437 |
+
data.items.forEach(item => {
|
438 |
+
html += `
|
439 |
+
<div class="url-item">
|
440 |
+
<div>${item.url}</div>
|
441 |
+
<div class="url-controls">
|
442 |
+
<button class="btn" onclick="editUrl('${item.url}')">Edit</button>
|
443 |
+
<button class="btn btn-danger" onclick="deleteUrl('${item.url}')">Delete</button>
|
444 |
+
</div>
|
445 |
+
</div>
|
446 |
+
`;
|
447 |
+
});
|
448 |
+
|
449 |
+
urlList.innerHTML = html;
|
450 |
+
});
|
451 |
+
}
|
452 |
+
function addUrl() {
|
453 |
+
const url = document.getElementById('new-url').value.trim();
|
454 |
+
|
455 |
+
if(!url) {
|
456 |
+
showStatus('add-status', 'Please enter a URL', false);
|
457 |
+
return;
|
458 |
+
}
|
459 |
+
|
460 |
+
const formData = new FormData();
|
461 |
+
formData.append('url', url);
|
462 |
+
|
463 |
+
makeRequest('/api/url/add', 'POST', formData, function(data) {
|
464 |
+
showStatus('add-status', data.message, data.success);
|
465 |
+
if(data.success) {
|
466 |
+
document.getElementById('new-url').value = '';
|
467 |
+
loadUrlList();
|
468 |
+
}
|
469 |
+
});
|
470 |
+
}
|
471 |
+
function editUrl(url) {
|
472 |
+
const newUrl = prompt('Edit URL:', url);
|
473 |
+
|
474 |
+
if(!newUrl || newUrl === url) return;
|
475 |
+
|
476 |
+
const formData = new FormData();
|
477 |
+
formData.append('old', url);
|
478 |
+
formData.append('new', newUrl);
|
479 |
+
|
480 |
+
makeRequest('/api/url/update', 'POST', formData, function(data) {
|
481 |
+
if(data.success) {
|
482 |
+
loadUrlList();
|
483 |
+
} else {
|
484 |
+
alert(data.message);
|
485 |
+
}
|
486 |
+
});
|
487 |
+
}
|
488 |
+
function deleteUrl(url) {
|
489 |
+
if(!confirm('Are you sure you want to delete this URL?')) return;
|
490 |
+
|
491 |
+
const formData = new FormData();
|
492 |
+
formData.append('url', url);
|
493 |
+
|
494 |
+
makeRequest('/api/url/delete', 'POST', formData, function(data) {
|
495 |
+
if(data.success) {
|
496 |
+
loadUrlList();
|
497 |
+
} else {
|
498 |
+
alert(data.message);
|
499 |
+
}
|
500 |
+
});
|
501 |
+
}
|
502 |
+
function showStatus(id, message, success) {
|
503 |
+
const status = document.getElementById(id);
|
504 |
+
status.textContent = message;
|
505 |
+
status.className = success ? 'status success' : 'status error';
|
506 |
+
setTimeout(() => {
|
507 |
+
status.className = 'status';
|
508 |
+
}, 3000);
|
509 |
+
}
|
510 |
+
// Create tabs
|
511 |
+
// Favorites tab first
|
512 |
+
const favTab = document.createElement('button');
|
513 |
+
favTab.className = 'tab';
|
514 |
+
favTab.textContent = 'Favorites';
|
515 |
+
favTab.dataset.c = 'Favorites';
|
516 |
+
favTab.onclick = function() { loadFavorites(1); };
|
517 |
+
tabs.appendChild(favTab);
|
518 |
+
// Category tabs
|
519 |
+
cats.forEach(c => {
|
520 |
+
const b = document.createElement('button');
|
521 |
+
b.className = 'tab';
|
522 |
+
b.textContent = c;
|
523 |
+
b.dataset.c = c;
|
524 |
+
b.onclick = function() { loadCategory(c); };
|
525 |
+
tabs.appendChild(b);
|
526 |
+
});
|
527 |
+
// Manage tab last
|
528 |
+
const manageTab = document.createElement('button');
|
529 |
+
manageTab.className = 'tab manage';
|
530 |
+
manageTab.textContent = 'Manage';
|
531 |
+
manageTab.dataset.c = 'Manage';
|
532 |
+
manageTab.onclick = function() { loadManage(); };
|
533 |
+
tabs.appendChild(manageTab);
|
534 |
+
// Start with Favorites tab
|
535 |
+
loadFavorites(1);
|
536 |
+
</script>
|
537 |
+
</body>
|
538 |
+
</html>''')
|
539 |
+
|
540 |
+
# Return the rendered template
|
541 |
+
return render_template('index.html', cats=list(CATEGORIES.keys()))
|
542 |
+
|
543 |
+
# Initialize database on startup
|
544 |
+
init_db()
|
545 |
+
|
546 |
+
if __name__ == '__main__':
|
547 |
+
app.run(host='0.0.0.0', port=7860)
|