Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -261,46 +261,53 @@ def create_interface():
|
|
| 261 |
|
| 262 |
js_code = """
|
| 263 |
function gradio_init() {
|
| 264 |
-
|
| 265 |
|
| 266 |
-
//
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
|
|
|
| 292 |
}
|
| 293 |
}
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
}
|
| 298 |
-
});
|
| 299 |
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
|
|
|
| 304 |
}
|
| 305 |
"""
|
| 306 |
|
|
|
|
| 261 |
|
| 262 |
js_code = """
|
| 263 |
function gradio_init() {
|
| 264 |
+
const url = new URL(window.location);
|
| 265 |
|
| 266 |
+
// 檢查 URL 是否已經是 dark mode
|
| 267 |
+
if (url.searchParams.get('__theme') !== 'dark') {
|
| 268 |
+
// 如果不是,設定參數並重新載入
|
| 269 |
+
url.searchParams.set('__theme', 'dark');
|
| 270 |
+
window.location.href = url.href;
|
| 271 |
+
} else {
|
| 272 |
+
// 如果已經是 dark mode,才設定事件監聽
|
| 273 |
+
const observer = new MutationObserver((mutations, obs) => {
|
| 274 |
+
const table = document.getElementById('periodic-table-container');
|
| 275 |
+
if (table) {
|
| 276 |
+
console.log("Periodic table found, attaching event listener.");
|
| 277 |
+
let selectedElementDiv = null;
|
| 278 |
|
| 279 |
+
table.addEventListener('click', function(event) {
|
| 280 |
+
const targetCell = event.target.closest('.element-cell');
|
| 281 |
+
|
| 282 |
+
if (targetCell && !targetCell.classList.contains('empty-cell')) {
|
| 283 |
+
const symbol = targetCell.dataset.symbol;
|
| 284 |
+
console.log(`Element clicked: ${symbol}`);
|
| 285 |
|
| 286 |
+
if (selectedElementDiv) {
|
| 287 |
+
selectedElementDiv.classList.remove('selected');
|
| 288 |
+
}
|
| 289 |
+
targetCell.classList.add('selected');
|
| 290 |
+
selectedElementDiv = targetCell;
|
| 291 |
|
| 292 |
+
const hidden_input_component = document.getElementById('hidden_trigger_for_js');
|
| 293 |
+
if (hidden_input_component) {
|
| 294 |
+
const textarea = hidden_input_component.querySelector('textarea');
|
| 295 |
+
if (textarea) {
|
| 296 |
+
textarea.value = symbol;
|
| 297 |
+
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
| 298 |
+
}
|
| 299 |
}
|
| 300 |
}
|
| 301 |
+
});
|
| 302 |
+
obs.disconnect();
|
| 303 |
+
}
|
| 304 |
+
});
|
|
|
|
| 305 |
|
| 306 |
+
observer.observe(document.body, {
|
| 307 |
+
childList: true,
|
| 308 |
+
subtree: true
|
| 309 |
+
});
|
| 310 |
+
}
|
| 311 |
}
|
| 312 |
"""
|
| 313 |
|