Hello,

I'm looking into replacing callback and XMLHttpRequest by

  • Fetch
  • Promise and XMLHttpRequest

Fetch doesn't support file:// hence I've decided not to use it, because callback and XMLHttpRequest do allow file://. See Newspaper/issues/Observation_Fetch_API.

This is the code for Promise and it seems to skip the statement (document.URL.startsWith('file:')) that should allow applying this userscript to local files too.

let myPromise = new Promise(function(myResolve, myReject) {
  let request = new XMLHttpRequest();
  request.open('GET', document.documentURI);
  request.onload = function() {
    if (request.status == 200) {
      myResolve(request);
    } else {
      myReject("File not Found");
    }
  };
  request.send();
});

myPromise.then(
  function(request) {
      if (document.URL.startsWith('file:')) {
        mimeType = document.contentType;
      } else {
          mimeType =
            request
            .getResponseHeader('Content-Type');
        }
      if (checkMediaType(mimeType)) {
        renderFeed(request.response)
      }
  },
  function(error) {checkMediaType(error);}
);

Please help.
Thank you.