Refactor flatMap polyfill

This commit is contained in:
the1812 2018-11-29 19:57:51 +08:00
parent dae32c7011
commit 42ed2b1268
4 changed files with 22 additions and 18 deletions

View File

@ -1,6 +1,6 @@
// ==UserScript==
// @name Bilibili Evolved (Offline)
// @version 134.90
// @version 136.17
// @description 增强哔哩哔哩Web端体验(离线版): 修复界面瑕疵, 删除广告, 使用夜间模式浏览, 下载视频或视频封面, 以及增加对触屏设备的支持等.
// @author Grant Howard, Coulomb-G
// @copyright 2018, Grant Howrad (https://github.com/the1812)
@ -1053,11 +1053,11 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m
.map(mapFunc)
.reduce((acc, it) => acc.concat(it), []);
};
return flatMap.bind(this.styles);
return flatMap;
}
else
{
return Array.prototype.flatMap.bind(this.styles);
return Array.prototype.flatMap;
}
}
loadCache()
@ -1072,7 +1072,7 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m
return settings.cache[key];
}
}
download()
async download()
{
const key = this.key;
return new Promise((resolve, reject) =>
@ -1083,7 +1083,8 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m
}
else
{
const flattenStyles = this.flatMapPolyfill()(it => typeof it === "object" ? it.key : it);
const flattenStyles = this.flatMapPolyfill()
.bind(this.styles)(it => typeof it === "object" ? it.key : it);
Promise.all(this.dependencies
.concat(flattenStyles.map(it => Resource.all[it]))
.map(r => r.download())

View File

@ -1,6 +1,6 @@
// ==UserScript==
// @name Bilibili Evolved (Preview Offline)
// @version 134.90
// @version 136.17
// @description 增强哔哩哔哩Web端体验(预览离线版): 修复界面瑕疵, 删除广告, 使用夜间模式浏览, 下载视频或视频封面, 以及增加对触屏设备的支持等.
// @author Grant Howard, Coulomb-G
// @copyright 2018, Grant Howrad (https://github.com/the1812)
@ -1053,11 +1053,11 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m
.map(mapFunc)
.reduce((acc, it) => acc.concat(it), []);
};
return flatMap.bind(this.styles);
return flatMap;
}
else
{
return Array.prototype.flatMap.bind(this.styles);
return Array.prototype.flatMap;
}
}
loadCache()
@ -1072,7 +1072,7 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m
return settings.cache[key];
}
}
download()
async download()
{
const key = this.key;
return new Promise((resolve, reject) =>
@ -1083,7 +1083,8 @@ offlineData["https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/m
}
else
{
const flattenStyles = this.flatMapPolyfill()(it => typeof it === "object" ? it.key : it);
const flattenStyles = this.flatMapPolyfill()
.bind(this.styles)(it => typeof it === "object" ? it.key : it);
Promise.all(this.dependencies
.concat(flattenStyles.map(it => Resource.all[it]))
.map(r => r.download())

View File

@ -1001,11 +1001,11 @@
.map(mapFunc)
.reduce((acc, it) => acc.concat(it), []);
};
return flatMap.bind(this.styles);
return flatMap;
}
else
{
return Array.prototype.flatMap.bind(this.styles);
return Array.prototype.flatMap;
}
}
loadCache()
@ -1020,7 +1020,7 @@
return settings.cache[key];
}
}
download()
async download()
{
const key = this.key;
return new Promise((resolve, reject) =>
@ -1031,7 +1031,8 @@
}
else
{
const flattenStyles = this.flatMapPolyfill()(it => typeof it === "object" ? it.key : it);
const flattenStyles = this.flatMapPolyfill()
.bind(this.styles)(it => typeof it === "object" ? it.key : it);
Promise.all(this.dependencies
.concat(flattenStyles.map(it => Resource.all[it]))
.map(r => r.download())

View File

@ -1001,11 +1001,11 @@
.map(mapFunc)
.reduce((acc, it) => acc.concat(it), []);
};
return flatMap.bind(this.styles);
return flatMap;
}
else
{
return Array.prototype.flatMap.bind(this.styles);
return Array.prototype.flatMap;
}
}
loadCache()
@ -1020,7 +1020,7 @@
return settings.cache[key];
}
}
download()
async download()
{
const key = this.key;
return new Promise((resolve, reject) =>
@ -1031,7 +1031,8 @@
}
else
{
const flattenStyles = this.flatMapPolyfill()(it => typeof it === "object" ? it.key : it);
const flattenStyles = this.flatMapPolyfill()
.bind(this.styles)(it => typeof it === "object" ? it.key : it);
Promise.all(this.dependencies
.concat(flattenStyles.map(it => Resource.all[it]))
.map(r => r.download())