|
|
@@ -18,15 +18,18 @@
|
|
|
* along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
-/* global SingleFileCore, base64, DOMParser, getComputedStyle, TextDecoder, fetch, parseSrcset, uglifycss */
|
|
|
+/* global SingleFileCore, base64, DOMParser, getComputedStyle, TextDecoder, fetch, superFetch, parseSrcset, uglifycss */
|
|
|
|
|
|
this.SingleFile = (() => {
|
|
|
|
|
|
+
|
|
|
// --------
|
|
|
// Download
|
|
|
// --------
|
|
|
const USER_AGENT = "Mozilla/5.0 (compatible; SingleFile Bot/1.0)";
|
|
|
|
|
|
+ let fetchResource;
|
|
|
+
|
|
|
class Download {
|
|
|
static async getContent(resourceURL, asDataURI) {
|
|
|
const requestOptions = {
|
|
|
@@ -36,8 +39,11 @@ this.SingleFile = (() => {
|
|
|
}
|
|
|
};
|
|
|
let resourceContent;
|
|
|
+ if (!fetchResource) {
|
|
|
+ fetchResource = typeof superFetch == "undefined" ? fetch : superFetch;
|
|
|
+ }
|
|
|
try {
|
|
|
- resourceContent = await (this.superFetch || fetch)(resourceURL, requestOptions);
|
|
|
+ resourceContent = await fetchResource(resourceURL, requestOptions);
|
|
|
} catch (e) {
|
|
|
return asDataURI ? "data:base64," : "";
|
|
|
}
|