Print content-type 'application/vnd.apple.mpegurl'
当前为
// ==UserScript==
// @name Print requests with content-type 'application/vnd.apple.mpegurl'
// @namespace http://your-domain-here/
// @version 7
// @description Print content-type 'application/vnd.apple.mpegurl'
// @match http://*/*
// @match https://*/*
// @grant GM_xmlhttpRequest
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// Intercept the XHR requests
function interceptXHR(xhr) {
// Print the XHR request to the console
console.log('XHR request intercepted:', xhr);
// Check if the content type is application/vnd.apple.mpegurl
const contentType = xhr.getResponseHeader('content-type');
if (contentType === 'application/vnd.apple.mpegurl') {
console.log('XHR request with content type application/vnd.apple.mpegurl:', xhr);
}
}
// Add interceptors to all XHR requests
window.XMLHttpRequest.prototype.realSend = window.XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.send = function(data) {
interceptXHR(this);
this.realSend(data);
};
// Observe the document for changes and add interceptors to any new iframes
const observer = new MutationObserver(observeIframes);
observer.observe(document, { childList: true, subtree: true });
// Add interceptors to any iframes already in the document
observeIframes();
function observeIframes() {
const iframes = document.getElementsByTagName('iframe');
for (let i = 0; i < iframes.length; i++) {
addInterceptorToIframe(iframes[i]);
}
}
function addInterceptorToIframe(iframe) {
// Check if interceptor already added
if (iframe.contentWindow.XMLHttpRequest.prototype.realSend) {
return;
}
// Add interceptor to XHR requests in the iframe
iframe.contentWindow.XMLHttpRequest.prototype.realSend = iframe.contentWindow.XMLHttpRequest.prototype.send;
iframe.contentWindow.XMLHttpRequest.prototype.send = function(data) {
interceptXHR(this);
this.realSend(data);
}
// Observe the iframe for changes and add interceptors to any new iframes
const observer = new iframe.contentWindow.MutationObserver(observeIframesInIframe);
observer.observe(iframe.contentDocument, { childList: true, subtree: true });
// Add interceptors to any iframes already in the iframe
observeIframesInIframe();
function observeIframesInIframe() {
const iframes = iframe.contentDocument.getElementsByTagName('iframe');
for (let i = 0; i < iframes.length; i++) {
addInterceptorToIframe(iframes[i]);
}
}
}
})();