作者:牛哥粉丝_对白 | 来源:互联网 | 2023-01-28 10:14
我正在使用Content Script构建chrome扩展。
我有一段代码,使用jQuery在页面上所有ajax请求成功后注入DOM元素。没有jQuery,如何重新创建它?请注意,我无法修改页面上的任何ajax请求。
if(window.jQuery){
jQuery( document ).ajaxComplete(function( event, xhr, settings ) {
for(var i =0; i<$jq('div.handwave').length; i++){
if($($('div.handwave')[i]).children('.done').length <1){
$(document).find('div.handwave').eq(i).append(wind);
}
}
});
}
这可能吗?
1> Phil..:
更新资料
如果要编写Chrome扩展程序,则可能应该使用chrome.webRequest
API。参见https://developer.chrome.com/extensions/webRequest
您可以覆盖提出AJAX请求所需的现有方法之一,例如XMLHttpRequest.prototype.send
添加自己的加载事件侦听器。例如
(function() {
const send = XMLHttpRequest.prototype.send
XMLHttpRequest.prototype.send = function() {
this.addEventListener('load', function() {
console.log('global handler', this.responseText)
// add your global handler here
})
return send.apply(this, arguments)
}
})()
如评论中所述,这不会涵盖fetch
API。