mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Support dynamic import
This commit is contained in:
parent
c28a59464b
commit
d8c32c68cb
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
.vscode/
|
.vscode/
|
||||||
builder/node/
|
builder/node/
|
||||||
|
builder/dotnet/Properties
|
||||||
.node_modules/
|
.node_modules/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
build.cache
|
build.cache
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Bilibili Evolved (Offline)
|
// @name Bilibili Evolved (Offline)
|
||||||
// @version 245.99
|
// @version 246.06
|
||||||
// @description Bilibili Evolved 的离线版, 所有功能都已内置于脚本中.
|
// @description Bilibili Evolved 的离线版, 所有功能都已内置于脚本中.
|
||||||
// @author Grant Howard, Coulomb-G
|
// @author Grant Howard, Coulomb-G
|
||||||
// @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G)
|
// @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G)
|
||||||
@ -1660,6 +1660,7 @@ class ResourceManager
|
|||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
this.data = Resource.all;
|
this.data = Resource.all;
|
||||||
|
this.skippedImport = [];
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
this.styleManager = new StyleManager(this);
|
this.styleManager = new StyleManager(this);
|
||||||
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
||||||
@ -1712,7 +1713,12 @@ class ResourceManager
|
|||||||
import(componentName)
|
import(componentName)
|
||||||
{
|
{
|
||||||
const resource = Resource.all[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)
|
if (!resource.downloaded)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Bilibili Evolved (Preview Offline)
|
// @name Bilibili Evolved (Preview Offline)
|
||||||
// @version 245.99
|
// @version 246.06
|
||||||
// @description Bilibili Evolved 的预览离线版, 可以抢先体验新功能, 并且所有功能都已内置于脚本中.
|
// @description Bilibili Evolved 的预览离线版, 可以抢先体验新功能, 并且所有功能都已内置于脚本中.
|
||||||
// @author Grant Howard, Coulomb-G
|
// @author Grant Howard, Coulomb-G
|
||||||
// @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G)
|
// @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G)
|
||||||
@ -1660,6 +1660,7 @@ class ResourceManager
|
|||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
this.data = Resource.all;
|
this.data = Resource.all;
|
||||||
|
this.skippedImport = [];
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
this.styleManager = new StyleManager(this);
|
this.styleManager = new StyleManager(this);
|
||||||
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
||||||
@ -1712,7 +1713,12 @@ class ResourceManager
|
|||||||
import(componentName)
|
import(componentName)
|
||||||
{
|
{
|
||||||
const resource = Resource.all[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)
|
if (!resource.downloaded)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1611,6 +1611,7 @@ class ResourceManager
|
|||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
this.data = Resource.all;
|
this.data = Resource.all;
|
||||||
|
this.skippedImport = [];
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
this.styleManager = new StyleManager(this);
|
this.styleManager = new StyleManager(this);
|
||||||
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
||||||
@ -1663,7 +1664,12 @@ class ResourceManager
|
|||||||
import(componentName)
|
import(componentName)
|
||||||
{
|
{
|
||||||
const resource = Resource.all[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)
|
if (!resource.downloaded)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1611,6 +1611,7 @@ class ResourceManager
|
|||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
this.data = Resource.all;
|
this.data = Resource.all;
|
||||||
|
this.skippedImport = [];
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
this.styleManager = new StyleManager(this);
|
this.styleManager = new StyleManager(this);
|
||||||
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
||||||
@ -1663,7 +1664,12 @@ class ResourceManager
|
|||||||
import(componentName)
|
import(componentName)
|
||||||
{
|
{
|
||||||
const resource = Resource.all[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)
|
if (!resource.downloaded)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -12,17 +12,11 @@ namespace BilibiliEvolved.Build
|
|||||||
public ProjectBuilder BuildClient()
|
public ProjectBuilder BuildClient()
|
||||||
{
|
{
|
||||||
var source = File.ReadAllText("client/bilibili-evolved.js");
|
var source = File.ReadAllText("client/bilibili-evolved.js");
|
||||||
var importRegex = new Regex(@"import (.*) from [""'](.*)[""'];", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
source = RegexReplacer.Replace(source, @"import (.*) from [""'](.*)[""'];", match =>
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
var match = importRegex.Match(source);
|
|
||||||
if (!match.Success)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
var module = File.ReadAllText("client/" + match.Groups[2].Value.Replace("./", "") + ".js").Replace("export ", "");
|
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);
|
File.WriteAllText(SourcePath, source);
|
||||||
Source = File.ReadAllText(SourcePath);
|
Source = File.ReadAllText(SourcePath);
|
||||||
WriteSuccess("Client Build complete.");
|
WriteSuccess("Client Build complete.");
|
||||||
|
|||||||
29
builder/dotnet/RegexReplacer.cs
Normal file
29
builder/dotnet/RegexReplacer.cs
Normal file
@ -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<Match, string> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -142,23 +142,26 @@ namespace BilibiliEvolved.Build
|
|||||||
{
|
{
|
||||||
if (!input.StartsWith("(() =>"))
|
if (!input.StartsWith("(() =>"))
|
||||||
{
|
{
|
||||||
var importRegex = new Regex(@"import (.*) from [""'](.*)[""'];", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
Func<string, string> convertToRuntimeSource = source =>
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
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("/");
|
var index = source.LastIndexOf("/");
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
source = source.Remove(0, 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 = @"(() =>
|
input = @"(() =>
|
||||||
{
|
{
|
||||||
return (settings, resources) =>
|
return (settings, resources) =>
|
||||||
|
|||||||
Binary file not shown.
@ -3,6 +3,7 @@ export class ResourceManager
|
|||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
this.data = Resource.all;
|
this.data = Resource.all;
|
||||||
|
this.skippedImport = [];
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
this.styleManager = new StyleManager(this);
|
this.styleManager = new StyleManager(this);
|
||||||
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
const styleMethods = Object.getOwnPropertyNames(StyleManager.prototype).filter(it => it !== "constructor");
|
||||||
@ -55,7 +56,12 @@ export class ResourceManager
|
|||||||
import(componentName)
|
import(componentName)
|
||||||
{
|
{
|
||||||
const resource = Resource.all[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)
|
if (!resource.downloaded)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user