retesere20

chrome-extension-removed-part-2

Oct 1st, 2020
27
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. app.get = function (url, headers, data) {
  3. var xhr = new XMLHttpRequest();
  4. var deferred = Promise.defer();
  5. xhr.onreadystatechange = function () {
  6. if (xhr.readyState === 4) {
  7. if (xhr.status >= 400 || xhr.status < 200) {
  8. var e = new Error(xhr.statusText);
  9. e.status = xhr.status;
  10. deferred.reject(e);
  11. } else deferred.resolve(xhr.responseText);
  12. }
  13. };
  14. xhr.open(data ? "POST" : "GET", url, true);
  15. for (var id in headers) xhr.setRequestHeader(id, headers[id]);
  16. if (data) {
  17. var arr = [];
  18. for (e in data) arr.push(e + '=' + data[e]);
  19. data = arr.join('&');
  20. }
  21. xhr.send(data ? data : '');
  22. return deferred.promise;
  23. };
RAW Paste Data