Spaces:
Sleeping
Sleeping
Delete app-backup.py
Browse files- app-backup.py +0 -563
app-backup.py
DELETED
|
@@ -1,563 +0,0 @@
|
|
| 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 |
-
|
| 283 |
-
<script>
|
| 284 |
-
// Basic configuration
|
| 285 |
-
const cats = {{cats|tojson}};
|
| 286 |
-
const tabs = document.getElementById('tabs');
|
| 287 |
-
const content = document.getElementById('content');
|
| 288 |
-
let active = "";
|
| 289 |
-
let currentPage = 1;
|
| 290 |
-
|
| 291 |
-
// Simple utility functions
|
| 292 |
-
function loadHTML(url, callback) {
|
| 293 |
-
const xhr = new XMLHttpRequest();
|
| 294 |
-
xhr.open('GET', url, true);
|
| 295 |
-
xhr.onreadystatechange = function() {
|
| 296 |
-
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 297 |
-
callback(xhr.responseText);
|
| 298 |
-
}
|
| 299 |
-
};
|
| 300 |
-
xhr.send();
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
function makeRequest(url, method, data, callback) {
|
| 304 |
-
const xhr = new XMLHttpRequest();
|
| 305 |
-
xhr.open(method, url, true);
|
| 306 |
-
xhr.onreadystatechange = function() {
|
| 307 |
-
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 308 |
-
callback(JSON.parse(xhr.responseText));
|
| 309 |
-
}
|
| 310 |
-
};
|
| 311 |
-
if (method === 'POST') {
|
| 312 |
-
xhr.send(data);
|
| 313 |
-
} else {
|
| 314 |
-
xhr.send();
|
| 315 |
-
}
|
| 316 |
-
}
|
| 317 |
-
|
| 318 |
-
function updateTabs() {
|
| 319 |
-
Array.from(tabs.children).forEach(b => {
|
| 320 |
-
b.classList.toggle('active', b.dataset.c === active);
|
| 321 |
-
});
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
// Tab handlers
|
| 325 |
-
function loadCategory(cat) {
|
| 326 |
-
if(cat === active) return;
|
| 327 |
-
active = cat;
|
| 328 |
-
updateTabs();
|
| 329 |
-
|
| 330 |
-
content.innerHTML = '<p style="text-align:center;padding:40px">Loadingโฆ</p>';
|
| 331 |
-
|
| 332 |
-
makeRequest('/api/category?name=' + encodeURIComponent(cat), 'GET', null, function(data) {
|
| 333 |
-
let html = '<div class="grid">';
|
| 334 |
-
|
| 335 |
-
data.forEach(item => {
|
| 336 |
-
html += `
|
| 337 |
-
<div class="card">
|
| 338 |
-
<div class="frame">
|
| 339 |
-
<iframe src="${item.iframe}" loading="lazy" sandbox="allow-forms allow-modals allow-popups allow-same-origin allow-scripts allow-downloads"></iframe>
|
| 340 |
-
</div>
|
| 341 |
-
<div class="foot">
|
| 342 |
-
<a href="${item.hf}" target="_blank">${item.title}</a>
|
| 343 |
-
</div>
|
| 344 |
-
</div>
|
| 345 |
-
`;
|
| 346 |
-
});
|
| 347 |
-
|
| 348 |
-
html += '</div>';
|
| 349 |
-
content.innerHTML = html;
|
| 350 |
-
});
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
function loadFavorites(page) {
|
| 354 |
-
if(active === 'Favorites' && currentPage === page) return;
|
| 355 |
-
active = 'Favorites';
|
| 356 |
-
currentPage = page || 1;
|
| 357 |
-
updateTabs();
|
| 358 |
-
|
| 359 |
-
content.innerHTML = '<p style="text-align:center;padding:40px">Loadingโฆ</p>';
|
| 360 |
-
|
| 361 |
-
makeRequest('/api/favorites?page=' + currentPage, 'GET', null, function(data) {
|
| 362 |
-
let html = '<div class="grid">';
|
| 363 |
-
|
| 364 |
-
if(data.items.length === 0) {
|
| 365 |
-
html += '<p style="grid-column:1/-1;text-align:center;padding:40px">No favorites saved yet.</p>';
|
| 366 |
-
} else {
|
| 367 |
-
data.items.forEach(item => {
|
| 368 |
-
if(item.mode === 'snapshot') {
|
| 369 |
-
html += `
|
| 370 |
-
<div class="card">
|
| 371 |
-
<div class="card-label label-static">Static</div>
|
| 372 |
-
<div class="frame">
|
| 373 |
-
<img src="${item.preview_url}" loading="lazy">
|
| 374 |
-
</div>
|
| 375 |
-
<div class="foot">
|
| 376 |
-
<a href="${item.url}" target="_blank">${item.title}</a>
|
| 377 |
-
</div>
|
| 378 |
-
</div>
|
| 379 |
-
`;
|
| 380 |
-
} else {
|
| 381 |
-
html += `
|
| 382 |
-
<div class="card">
|
| 383 |
-
<div class="card-label label-live">LIVE</div>
|
| 384 |
-
<div class="frame">
|
| 385 |
-
<iframe src="${item.preview_url}" loading="lazy" sandbox="allow-forms allow-modals allow-popups allow-same-origin allow-scripts allow-downloads"></iframe>
|
| 386 |
-
</div>
|
| 387 |
-
<div class="foot">
|
| 388 |
-
<a href="${item.url}" target="_blank">${item.title}</a>
|
| 389 |
-
</div>
|
| 390 |
-
</div>
|
| 391 |
-
`;
|
| 392 |
-
}
|
| 393 |
-
});
|
| 394 |
-
}
|
| 395 |
-
|
| 396 |
-
html += '</div>';
|
| 397 |
-
|
| 398 |
-
// Add pagination
|
| 399 |
-
html += `
|
| 400 |
-
<div class="pagination">
|
| 401 |
-
<button ${currentPage <= 1 ? 'disabled' : ''} onclick="loadFavorites(${currentPage-1})">ยซ Previous</button>
|
| 402 |
-
<span>Page ${currentPage} of ${data.total_pages}</span>
|
| 403 |
-
<button ${currentPage >= data.total_pages ? 'disabled' : ''} onclick="loadFavorites(${currentPage+1})">Next ยป</button>
|
| 404 |
-
</div>
|
| 405 |
-
`;
|
| 406 |
-
|
| 407 |
-
content.innerHTML = html;
|
| 408 |
-
});
|
| 409 |
-
}
|
| 410 |
-
|
| 411 |
-
function loadManage() {
|
| 412 |
-
if(active === 'Manage') return;
|
| 413 |
-
active = 'Manage';
|
| 414 |
-
updateTabs();
|
| 415 |
-
|
| 416 |
-
content.innerHTML = `
|
| 417 |
-
<div class="manage-panel">
|
| 418 |
-
<h2>Add New URL</h2>
|
| 419 |
-
<div class="form-group">
|
| 420 |
-
<label for="new-url">URL</label>
|
| 421 |
-
<input type="text" id="new-url" class="form-control" placeholder="https://example.com">
|
| 422 |
-
</div>
|
| 423 |
-
<button onclick="addUrl()" class="btn btn-primary">Add URL</button>
|
| 424 |
-
<div id="add-status" class="status"></div>
|
| 425 |
-
|
| 426 |
-
<h2>Manage Saved URLs</h2>
|
| 427 |
-
<div id="url-list" class="url-list">Loading...</div>
|
| 428 |
-
</div>
|
| 429 |
-
`;
|
| 430 |
-
|
| 431 |
-
loadUrlList();
|
| 432 |
-
}
|
| 433 |
-
|
| 434 |
-
// URL management functions
|
| 435 |
-
function loadUrlList() {
|
| 436 |
-
makeRequest('/api/favorites?per_page=100', 'GET', null, function(data) {
|
| 437 |
-
const urlList = document.getElementById('url-list');
|
| 438 |
-
|
| 439 |
-
if(data.items.length === 0) {
|
| 440 |
-
urlList.innerHTML = '<p style="text-align:center;padding:20px">No URLs saved yet.</p>';
|
| 441 |
-
return;
|
| 442 |
-
}
|
| 443 |
-
|
| 444 |
-
let html = '';
|
| 445 |
-
data.items.forEach(item => {
|
| 446 |
-
html += `
|
| 447 |
-
<div class="url-item">
|
| 448 |
-
<div>${item.url}</div>
|
| 449 |
-
<div class="url-controls">
|
| 450 |
-
<button class="btn" onclick="editUrl('${item.url}')">Edit</button>
|
| 451 |
-
<button class="btn btn-danger" onclick="deleteUrl('${item.url}')">Delete</button>
|
| 452 |
-
</div>
|
| 453 |
-
</div>
|
| 454 |
-
`;
|
| 455 |
-
});
|
| 456 |
-
|
| 457 |
-
urlList.innerHTML = html;
|
| 458 |
-
});
|
| 459 |
-
}
|
| 460 |
-
|
| 461 |
-
function addUrl() {
|
| 462 |
-
const url = document.getElementById('new-url').value.trim();
|
| 463 |
-
|
| 464 |
-
if(!url) {
|
| 465 |
-
showStatus('add-status', 'Please enter a URL', false);
|
| 466 |
-
return;
|
| 467 |
-
}
|
| 468 |
-
|
| 469 |
-
const formData = new FormData();
|
| 470 |
-
formData.append('url', url);
|
| 471 |
-
|
| 472 |
-
makeRequest('/api/url/add', 'POST', formData, function(data) {
|
| 473 |
-
showStatus('add-status', data.message, data.success);
|
| 474 |
-
if(data.success) {
|
| 475 |
-
document.getElementById('new-url').value = '';
|
| 476 |
-
loadUrlList();
|
| 477 |
-
}
|
| 478 |
-
});
|
| 479 |
-
}
|
| 480 |
-
|
| 481 |
-
function editUrl(url) {
|
| 482 |
-
const newUrl = prompt('Edit URL:', url);
|
| 483 |
-
|
| 484 |
-
if(!newUrl || newUrl === url) return;
|
| 485 |
-
|
| 486 |
-
const formData = new FormData();
|
| 487 |
-
formData.append('old', url);
|
| 488 |
-
formData.append('new', newUrl);
|
| 489 |
-
|
| 490 |
-
makeRequest('/api/url/update', 'POST', formData, function(data) {
|
| 491 |
-
if(data.success) {
|
| 492 |
-
loadUrlList();
|
| 493 |
-
} else {
|
| 494 |
-
alert(data.message);
|
| 495 |
-
}
|
| 496 |
-
});
|
| 497 |
-
}
|
| 498 |
-
|
| 499 |
-
function deleteUrl(url) {
|
| 500 |
-
if(!confirm('Are you sure you want to delete this URL?')) return;
|
| 501 |
-
|
| 502 |
-
const formData = new FormData();
|
| 503 |
-
formData.append('url', url);
|
| 504 |
-
|
| 505 |
-
makeRequest('/api/url/delete', 'POST', formData, function(data) {
|
| 506 |
-
if(data.success) {
|
| 507 |
-
loadUrlList();
|
| 508 |
-
} else {
|
| 509 |
-
alert(data.message);
|
| 510 |
-
}
|
| 511 |
-
});
|
| 512 |
-
}
|
| 513 |
-
|
| 514 |
-
function showStatus(id, message, success) {
|
| 515 |
-
const status = document.getElementById(id);
|
| 516 |
-
status.textContent = message;
|
| 517 |
-
status.className = success ? 'status success' : 'status error';
|
| 518 |
-
setTimeout(() => {
|
| 519 |
-
status.className = 'status';
|
| 520 |
-
}, 3000);
|
| 521 |
-
}
|
| 522 |
-
|
| 523 |
-
// Create tabs
|
| 524 |
-
// Favorites tab first
|
| 525 |
-
const favTab = document.createElement('button');
|
| 526 |
-
favTab.className = 'tab';
|
| 527 |
-
favTab.textContent = 'Favorites';
|
| 528 |
-
favTab.dataset.c = 'Favorites';
|
| 529 |
-
favTab.onclick = function() { loadFavorites(1); };
|
| 530 |
-
tabs.appendChild(favTab);
|
| 531 |
-
|
| 532 |
-
// Category tabs
|
| 533 |
-
cats.forEach(c => {
|
| 534 |
-
const b = document.createElement('button');
|
| 535 |
-
b.className = 'tab';
|
| 536 |
-
b.textContent = c;
|
| 537 |
-
b.dataset.c = c;
|
| 538 |
-
b.onclick = function() { loadCategory(c); };
|
| 539 |
-
tabs.appendChild(b);
|
| 540 |
-
});
|
| 541 |
-
|
| 542 |
-
// Manage tab last
|
| 543 |
-
const manageTab = document.createElement('button');
|
| 544 |
-
manageTab.className = 'tab manage';
|
| 545 |
-
manageTab.textContent = 'Manage';
|
| 546 |
-
manageTab.dataset.c = 'Manage';
|
| 547 |
-
manageTab.onclick = function() { loadManage(); };
|
| 548 |
-
tabs.appendChild(manageTab);
|
| 549 |
-
|
| 550 |
-
// Start with Favorites tab
|
| 551 |
-
loadFavorites(1);
|
| 552 |
-
</script>
|
| 553 |
-
</body>
|
| 554 |
-
</html>''')
|
| 555 |
-
|
| 556 |
-
# Return the rendered template
|
| 557 |
-
return render_template('index.html', cats=list(CATEGORIES.keys()))
|
| 558 |
-
|
| 559 |
-
# Initialize database on startup
|
| 560 |
-
init_db()
|
| 561 |
-
|
| 562 |
-
if __name__ == '__main__':
|
| 563 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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