aicodingfun commited on
Commit
c5f88ac
·
verified ·
1 Parent(s): 98178ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -33
app.py CHANGED
@@ -261,46 +261,53 @@ def create_interface():
261
 
262
  js_code = """
263
  function gradio_init() {
264
- document.documentElement.classList.add('dark');
265
 
266
- // 設定事件監聽
267
- const observer = new MutationObserver((mutations, obs) => {
268
- const table = document.getElementById('periodic-table-container');
269
- if (table) {
270
- console.log("Periodic table found, attaching event listener.");
271
- let selectedElementDiv = null;
 
 
 
 
 
 
272
 
273
- table.addEventListener('click', function(event) {
274
- const targetCell = event.target.closest('.element-cell');
275
-
276
- if (targetCell && !targetCell.classList.contains('empty-cell')) {
277
- const symbol = targetCell.dataset.symbol;
278
- console.log(`Element clicked: ${symbol}`);
279
 
280
- if (selectedElementDiv) {
281
- selectedElementDiv.classList.remove('selected');
282
- }
283
- targetCell.classList.add('selected');
284
- selectedElementDiv = targetCell;
285
 
286
- const hidden_input_component = document.getElementById('hidden_trigger_for_js');
287
- if (hidden_input_component) {
288
- const textarea = hidden_input_component.querySelector('textarea');
289
- if (textarea) {
290
- textarea.value = symbol;
291
- textarea.dispatchEvent(new Event('input', { bubbles: true }));
 
292
  }
293
  }
294
- }
295
- });
296
- obs.disconnect();
297
- }
298
- });
299
 
300
- observer.observe(document.body, {
301
- childList: true,
302
- subtree: true
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