cocoat commited on
Commit
b82efbd
·
verified ·
1 Parent(s): 4663f54

復元+JS

Browse files
Files changed (1) hide show
  1. app.py +42 -15
app.py CHANGED
@@ -225,21 +225,48 @@ with gr.Blocks(css=css, theme=gr.themes.Default(font=[gr.themes.GoogleFont("maki
225
  )
226
  gr.HTML(
227
  """
228
- <script>
229
- window.addEventListener('load', () => {
230
- const loaderEl = document.getElementById('custom-loader');
231
- const mo = new MutationObserver((mutations) => {
232
- const svg = document.querySelector('svg.svelte-zyxd38');
233
- if (!svg || !loaderEl) return;
234
- // loader が SVG 内にない場合は再アタッチ
235
- if (!svg.contains(loaderEl)) {
236
- svg.appendChild(loaderEl);
237
- }
238
- });
239
- // childList: 子の追加/削除、subtree: 再描画で中身クリア→追加されるのを検知
240
- mo.observe(document.body, { childList: true, subtree: true });
241
- });
242
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  """
244
  )
245
  img_out = gr.Image()
 
225
  )
226
  gr.HTML(
227
  """
228
+ <script>
229
+ window.addEventListener('load', () => {
230
+ const observer = new MutationObserver(() => {
231
+ const svg = document.querySelector('svg.svelte-zyxd38');
232
+ if (!svg) return;
233
+ // 一度挿入したら再挿入しない
234
+ if (svg.querySelector('foreignObject#custom-loader-fo')) return;
235
+
236
+ const SVG_NS = 'http://www.w3.org/2000/svg';
237
+ // foreignObject を作成
238
+ const fo = document.createElementNS(SVG_NS, 'foreignObject');
239
+ fo.setAttribute('id', 'custom-loader-fo');
240
+ fo.setAttribute('width', '100%'); // SVG 内の表示エリア幅に合わせて調整
241
+ fo.setAttribute('height', '100%'); // SVG 内の表示エリア高さに合わせて調整
242
+ fo.setAttribute('x', '0');
243
+ fo.setAttribute('y', '0');
244
+
245
+ // HTML 部分を innerHTML で一発挿入
246
+ fo.innerHTML = `
247
+ <div id="custom-loader" xmlns="http://www.w3.org/1999/xhtml">
248
+ <div class="loading-text">
249
+ <span style="animation-delay:0s">i</span>
250
+ <span style="animation-delay:0.1s">n</span>
251
+ <span style="animation-delay:0.2s"> </span>
252
+ <span style="animation-delay:0.3s">p</span>
253
+ <span style="animation-delay:0.4s">r</span>
254
+ <span style="animation-delay:0.5s">o</span>
255
+ <span style="animation-delay:0.6s">g</span>
256
+ <span style="animation-delay:0.7s">r</span>
257
+ <span style="animation-delay:0.8s">e</span>
258
+ <span style="animation-delay:0.9s">s</span>
259
+ <span style="animation-delay:1.0s">s</span>
260
+ </div>
261
+ <img src="icon.png" alt="loading icon" />
262
+ </div>
263
+ `;
264
+
265
+ svg.appendChild(fo);
266
+ });
267
+ observer.observe(document.body, { childList: true, subtree: true });
268
+ });
269
+ </script>
270
  """
271
  )
272
  img_out = gr.Image()