我试图通过使用 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 的更改,所有突变更改回调只会触发一次,我使用它来使用 注入(inject)我的下载按钮InjectUtubeDownloadButton();
关于javascript - 无法捕获 youtube Crossrider 扩展中修改的 DOMSubtree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28403490/