无法捕获youtube Crossrider扩展中修改的DOMSubtree

Unable to catch DOMSubtree Modified in youtube Crossrider extensions

本文关键字:修改 DOMSubtree 扩展 Crossrider youtube      更新时间:2023-09-26

我试图通过使用Crossrider扩展来捕捉DOMsubtree修改的事件,但无法获取。

我正试图在页面加载上获得一个youtube视频url,到目前为止还可以。但当我试图点击youtube右侧文章中的视频时,youtube正在打Ajax类型的电话来获取相关视频,然后我无法从地址栏获取点击的视频url。

尝试修改DOMsubtree。

$('body').on('DOMSubtreeModified',function(){
    console.log("something is changing");
});

一些技术人员建议youtube使用Flash加载视频,Jquery无法预测。任何建议

var target = document.querySelector('#player-api'); 
      var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
          if(mutation.type=="attributes"){
            var url1=window.location.href;
            $('#tubevid_div').remove();
              if(url1.indexOf('youtube.com/watch?v=')){
                 InjectUtubeDownloadButton($,url1);
                 //observer.disconnect();
              }
          }
        });    
      });  
   // configuration of the observer:
     var config = {attributes: true}; 
   // pass in the target node, as well as the observer options
     observer.observe(target, config);

在这里,我观察到了来自mozilla文档的Player-api-div中的所有突变更改的更改。回调将只触发一次,我用它来使用InjectUtubeDownloadButton()注入我的下载按钮