Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2015 Eyeo GmbH | |
4 * | |
5 * Adblock Plus is free software: you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 3 as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 "use strict"; | |
19 | |
20 (function(global) | |
21 { | |
22 if ("fetch" in global) | |
23 return; | |
24 | |
25 function Response(xhr) | |
26 { | |
27 this._xhr = xhr; | |
28 } | |
29 Response.prototype = { | |
30 get ok() | |
31 { | |
32 return this._xhr.status >= 200 && this._xhr.status <= 299; | |
33 }, | |
34 text: function() | |
35 { | |
36 return Promise.resolve(this._xhr.responseText); | |
37 } | |
38 }; | |
39 | |
40 global.fetch = function(url) | |
41 { | |
42 return new Promise(function(resolve, reject) | |
43 { | |
44 var xhr = new XMLHttpRequest(); | |
45 | |
46 xhr.onload = function() | |
47 { | |
48 resolve(new Response(xhr)); | |
49 }; | |
50 | |
51 xhr.onerror = xhr.onabort = function() | |
52 { | |
53 reject(new TypeError("Failed to fetch")); | |
54 }; | |
55 | |
56 xhr.overrideMimeType("text/plain"); | |
kzar
2016/01/19 15:03:24
I'm curious, why do this?
Sebastian Noack
2016/01/19 15:08:29
Otherwise, XMLHttpRequest would try to parse the r
kzar
2016/01/19 15:41:02
Acknowledged.
| |
57 xhr.open("GET", url); | |
58 xhr.send(); | |
59 }); | |
60 }; | |
61 })(this); | |
OLD | NEW |