diff --git a/.gitignore b/.gitignore index 497525037..5dbf658d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .vscode/ builder/node/ +builder/dotnet/Properties .node_modules/ package-lock.json build.cache diff --git a/bilibili-evolved.offline.user.js b/bilibili-evolved.offline.user.js index 88a0060e6..da01641db 100644 --- a/bilibili-evolved.offline.user.js +++ b/bilibili-evolved.offline.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Bilibili Evolved (Offline) -// @version 245.99 +// @version 246.06 // @description Bilibili Evolved 的离线版, 所有功能都已内置于脚本中. // @author Grant Howard, Coulomb-G // @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G) @@ -1660,6 +1660,7 @@ class ResourceManager constructor() { this.data = Resource.all; + this.skippedImport = []; this.attributes = {}; this.styleManager = new StyleManager(this); const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor"); @@ -1712,7 +1713,12 @@ class ResourceManager import(componentName) { const resource = Resource.all[componentName]; - if (resource && resource.type.name === "html") + if (!resource) + { + this.skippedImport.push(componentName); + return; + } + if (resource.type.name === "html") { if (!resource.downloaded) { diff --git a/bilibili-evolved.preview-offline.user.js b/bilibili-evolved.preview-offline.user.js index 342686ccf..dea9f2676 100644 --- a/bilibili-evolved.preview-offline.user.js +++ b/bilibili-evolved.preview-offline.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Bilibili Evolved (Preview Offline) -// @version 245.99 +// @version 246.06 // @description Bilibili Evolved 的预览离线版, 可以抢先体验新功能, 并且所有功能都已内置于脚本中. // @author Grant Howard, Coulomb-G // @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G) @@ -1660,6 +1660,7 @@ class ResourceManager constructor() { this.data = Resource.all; + this.skippedImport = []; this.attributes = {}; this.styleManager = new StyleManager(this); const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor"); @@ -1712,7 +1713,12 @@ class ResourceManager import(componentName) { const resource = Resource.all[componentName]; - if (resource && resource.type.name === "html") + if (!resource) + { + this.skippedImport.push(componentName); + return; + } + if (resource.type.name === "html") { if (!resource.downloaded) { diff --git a/bilibili-evolved.preview.user.js b/bilibili-evolved.preview.user.js index 5e449a58d..3e5f0982c 100644 --- a/bilibili-evolved.preview.user.js +++ b/bilibili-evolved.preview.user.js @@ -1611,6 +1611,7 @@ class ResourceManager constructor() { this.data = Resource.all; + this.skippedImport = []; this.attributes = {}; this.styleManager = new StyleManager(this); const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor"); @@ -1663,7 +1664,12 @@ class ResourceManager import(componentName) { const resource = Resource.all[componentName]; - if (resource && resource.type.name === "html") + if (!resource) + { + this.skippedImport.push(componentName); + return; + } + if (resource.type.name === "html") { if (!resource.downloaded) { diff --git a/bilibili-evolved.user.js b/bilibili-evolved.user.js index 49cb3ed9d..189a5302f 100644 --- a/bilibili-evolved.user.js +++ b/bilibili-evolved.user.js @@ -1611,6 +1611,7 @@ class ResourceManager constructor() { this.data = Resource.all; + this.skippedImport = []; this.attributes = {}; this.styleManager = new StyleManager(this); const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor"); @@ -1663,7 +1664,12 @@ class ResourceManager import(componentName) { const resource = Resource.all[componentName]; - if (resource && resource.type.name === "html") + if (!resource) + { + this.skippedImport.push(componentName); + return; + } + if (resource.type.name === "html") { if (!resource.downloaded) { diff --git a/builder/dotnet/ClientBuilder.cs b/builder/dotnet/ClientBuilder.cs index 538efc16e..655cbca2f 100644 --- a/builder/dotnet/ClientBuilder.cs +++ b/builder/dotnet/ClientBuilder.cs @@ -12,17 +12,11 @@ namespace BilibiliEvolved.Build public ProjectBuilder BuildClient() { var source = File.ReadAllText("client/bilibili-evolved.js"); - var importRegex = new Regex(@"import (.*) from [""'](.*)[""'];", RegexOptions.Compiled | RegexOptions.IgnoreCase); - while (true) + source = RegexReplacer.Replace(source, @"import (.*) from [""'](.*)[""'];", match => { - var match = importRegex.Match(source); - if (!match.Success) - { - break; - } var module = File.ReadAllText("client/" + match.Groups[2].Value.Replace("./", "") + ".js").Replace("export ", ""); - source = source.Replace(match.Value, module); - } + return module; + }); File.WriteAllText(SourcePath, source); Source = File.ReadAllText(SourcePath); WriteSuccess("Client Build complete."); diff --git a/builder/dotnet/RegexReplacer.cs b/builder/dotnet/RegexReplacer.cs new file mode 100644 index 000000000..49a178386 --- /dev/null +++ b/builder/dotnet/RegexReplacer.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace BilibiliEvolved.Build +{ + static class RegexReplacer + { + public static string Replace(string text, string regexText, Func func) + { + var regex = new Regex(regexText, RegexOptions.Compiled | RegexOptions.IgnoreCase); + while (true) + { + var match = regex.Match(text); + if (!match.Success) + { + break; + } + text = text.Replace(match.Value, func(match)); + } + return text; + } + } +} \ No newline at end of file diff --git a/builder/dotnet/ResourceBuilder.cs b/builder/dotnet/ResourceBuilder.cs index d21dc62e2..459560e3f 100644 --- a/builder/dotnet/ResourceBuilder.cs +++ b/builder/dotnet/ResourceBuilder.cs @@ -142,23 +142,26 @@ namespace BilibiliEvolved.Build { if (!input.StartsWith("(() =>")) { - var importRegex = new Regex(@"import (.*) from [""'](.*)[""'];", RegexOptions.Compiled | RegexOptions.IgnoreCase); - while (true) + Func convertToRuntimeSource = source => { - var match = importRegex.Match(input); - if (!match.Success) - { - break; - } - var imported = match.Groups[1].Value.Replace(" as ", ":"); - var source = match.Groups[2].Value; var index = source.LastIndexOf("/"); if (index != -1) { source = source.Remove(0, index + 1); } - input = input.Replace(match.Value, $"const {imported} = resources.import(\"{source}\");"); - } + return source; + }; + input = RegexReplacer.Replace(input, @"import (.*) from [""'](.*)[""'];", match => + { + var imported = match.Groups[1].Value.Replace(" as ", ":"); + var source = convertToRuntimeSource(match.Groups[2].Value); + return $"const {imported} = resources.import(\"{source}\");"; + }); + input = RegexReplacer.Replace(input, @" import\((.*)\)", match => + { + var source = convertToRuntimeSource(match.Groups[1].Value); + return $" resources.importAsync(\"{source}\");"; + }); input = @"(() => { return (settings, resources) => diff --git a/builder/dotnet/publish/build.dll b/builder/dotnet/publish/build.dll index f3ac2f856..0ec9cbf78 100644 Binary files a/builder/dotnet/publish/build.dll and b/builder/dotnet/publish/build.dll differ diff --git a/client/resource-manager.js b/client/resource-manager.js index f2e60a7e9..0a8580d97 100644 --- a/client/resource-manager.js +++ b/client/resource-manager.js @@ -3,6 +3,7 @@ export class ResourceManager constructor() { this.data = Resource.all; + this.skippedImport = []; this.attributes = {}; this.styleManager = new StyleManager(this); const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor"); @@ -55,7 +56,12 @@ export class ResourceManager import(componentName) { const resource = Resource.all[componentName]; - if (resource && resource.type.name === "html") + if (!resource) + { + this.skippedImport.push(componentName); + return; + } + if (resource.type.name === "html") { if (!resource.downloaded) {