Last active
May 6, 2024 22:47
-
-
Save snshn/a3f09016986abb04da16b80382f6adc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <script> | |
class myXMLHttpRequest extends XMLHttpRequest { | |
constructor() { | |
super(); | |
this._open = this.open; | |
this.open = (method, target) => { | |
// TODO replace file: with http/https: here | |
console.warn(target); | |
var base = "https://gist.github.com/snshn/a3f09016986abb04da16b80382f6adc5"; | |
return this._open(method, new URL(target, base)); | |
} | |
} | |
} | |
XMLHttpRequest = myXMLHttpRequest; | |
// </script> | |
////////////////////// | |
// Proof of concept // | |
////////////////////// | |
var oReq = new XMLHttpRequest(); | |
oReq.onload = function(e) { | |
var ab = oReq.response; | |
const decoder = new TextDecoder(); | |
const str = decoder.decode(ab) | |
console.log(str); | |
} | |
oReq.open("GET", '/'); | |
oReq.responseType = "arraybuffer"; | |
oReq.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment