Youngsun Lim commited on
Commit
82facbf
Β·
1 Parent(s): 6b5fab3

dataset update

Browse files
Files changed (1) hide show
  1. app.py +46 -20
app.py CHANGED
@@ -350,36 +350,62 @@ with gr.Blocks(fill_height=True, css=GLOBAL_CSS) as demo:
350
  gr.HTML("""
351
  <script>
352
  (function(){
353
- function muteAll(root){
354
- const vids = (root || document).querySelectorAll('video');
355
- vids.forEach(v => {
356
- try {
357
- v.muted = true;
358
- v.volume = 0.0;
359
- v.setAttribute('muted','');
360
- // μ‚¬μš©μžκ°€ μ‹€μˆ˜λ‘œ 킀더라도 λ‹€μ‹œ 0으둜
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  v.addEventListener('volumechange', () => {
362
  if (!v.muted || v.volume > 0) { v.muted = true; v.volume = 0.0; }
363
  });
364
- } catch(e){}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  });
366
  }
367
- // 초기 λ Œλ”μ—μ„œ μŒμ†Œκ±°
 
368
  muteAll(document);
369
- // 이후 동적 μƒμ„±λ˜λŠ” λΉ„λ””μ˜€λ„ κ°μ‹œν•΄μ„œ μŒμ†Œκ±°
370
- const obs = new MutationObserver(muts => {
371
- for (const m of muts) {
372
- if (m.type === 'childList') {
373
- muteAll(m.target);
374
- m.addedNodes && m.addedNodes.forEach(n => muteAll(n));
375
- }
376
- }
377
- });
378
- obs.observe(document.body, {subtree:true, childList:true});
379
  })();
380
  </script>
381
  """)
382
 
 
383
  order_state = gr.State(value=[]) # v4μ—μ„œλŠ” value= ꢌμž₯
384
  ptr_state = gr.State(value=0)
385
  cur_video_id = gr.State(value="")
 
350
  gr.HTML("""
351
  <script>
352
  (function(){
353
+ // λͺ¨λ“  일반 DOM + Shadow DOM μ•ˆμ˜ <video>κΉŒμ§€ μ°Ύμ•„ μŒμ†Œκ±°
354
+ function eachNodeWithShadow(root, fn){
355
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
356
+ fn(root);
357
+ while (walker.nextNode()){
358
+ const el = walker.currentNode;
359
+ fn(el);
360
+ if (el.shadowRoot){
361
+ eachNodeWithShadow(el.shadowRoot, fn);
362
+ }
363
+ }
364
+ }
365
+
366
+ function muteVideoEl(v){
367
+ try{
368
+ // μž¬μƒ 전에 λ°˜λ“œμ‹œ muted 속성이 μžˆμ–΄μ•Ό λΈŒλΌμš°μ €κ°€ μ†Œλ¦¬ 차단
369
+ v.muted = true;
370
+ v.volume = 0.0;
371
+ v.setAttribute('muted','');
372
+ v.setAttribute('playsinline','');
373
+ v.setAttribute('preload','metadata');
374
+
375
+ // μ‚¬μš©μžκ°€ λ³Όλ₯¨/μŒμ†Œκ±°λ₯Ό 바꿔도 λ‹€μ‹œ 0으둜
376
+ if (!v._muteHooked){
377
  v.addEventListener('volumechange', () => {
378
  if (!v.muted || v.volume > 0) { v.muted = true; v.volume = 0.0; }
379
  });
380
+ v.addEventListener('play', () => {
381
+ v.muted = true; v.volume = 0.0;
382
+ });
383
+ v._muteHooked = true;
384
+ }
385
+ }catch(e){}
386
+ }
387
+
388
+ function muteAll(root){
389
+ eachNodeWithShadow(root || document, (el)=>{
390
+ if (el.tagName && el.tagName.toLowerCase() === 'video'){
391
+ muteVideoEl(el);
392
+ }else if (el.querySelectorAll){
393
+ el.querySelectorAll('video').forEach(muteVideoEl);
394
+ }
395
  });
396
  }
397
+
398
+ // 초기 λ Œλ”μ—μ„œ
399
  muteAll(document);
400
+
401
+ // 이후 DOM λ³€ν™” κ°μ‹œ(Shadow DOM λ‚΄λΆ€ 변화도 포착)
402
+ const obs = new MutationObserver(() => muteAll(document));
403
+ obs.observe(document, {subtree:true, childList:true, attributes:false});
 
 
 
 
 
 
404
  })();
405
  </script>
406
  """)
407
 
408
+
409
  order_state = gr.State(value=[]) # v4μ—μ„œλŠ” value= ꢌμž₯
410
  ptr_state = gr.State(value=0)
411
  cur_video_id = gr.State(value="")