25 lines
748 B
JavaScript
25 lines
748 B
JavaScript
|
"use strict";
|
||
|
|
||
|
/**
|
||
|
* Fetches content from the given URL and returns it via a Promise.
|
||
|
* Original source: https://gist.github.com/0b2aee73f8d168e36a353901193e7ff5#file-getfromurl-js
|
||
|
* Proof that I wrote this is, of course, available upon request.
|
||
|
*
|
||
|
* @param {string} url The url to fetch the content from.
|
||
|
* @returns {Promise<string>} The content at the specified url.
|
||
|
*/
|
||
|
|
||
|
export default function GetFromUrl(url) {
|
||
|
return new Promise(function(resolve, reject) {
|
||
|
let request = new XMLHttpRequest();
|
||
|
request.addEventListener("load", function() {
|
||
|
if (request.status > 199 && request.status < 300)
|
||
|
resolve(request.response);
|
||
|
else
|
||
|
reject(request.response);
|
||
|
});
|
||
|
request.open("GET", url, true);
|
||
|
request.send(null);
|
||
|
})
|
||
|
}
|