Skip to content

Commit

Permalink
feat: $app & Console
Browse files Browse the repository at this point in the history
Update response.dev.js
Update request.dev.js
Update database.mjs
Update response.js
Update request.js
  • Loading branch information
VirgilClyne committed Nov 29, 2024
1 parent 7462fb4 commit 42c5292
Show file tree
Hide file tree
Showing 14 changed files with 761 additions and 756 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "src/utils"]
path = src/utils
url = https://github.com/NanoCat-Me/utils.git
[submodule "src/protobuf"]
path = src/protobuf
url = https://github.com/DualSubs/protobuf.git
8 changes: 0 additions & 8 deletions arguments-builder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ export default defineConfig({
},
},
args: [
{
key: "Switch",
name: "总功能开关",
defaultValue: true,
type: "boolean",
description: "是否启用此APP修改",
exclude: ["surge", "loon"],
},
{
key: "Type",
name: "[字幕] 启用类型",
Expand Down
78 changes: 78 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"files": {
"ignore": [
"**/*.bundle.js"
],
"ignoreUnknown": false
},
"formatter": {
"enabled": true,
"indentStyle": "tab",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 320
},
"javascript": {
"formatter": {
"arrowParentheses": "asNeeded",
"bracketSameLine": true,
"quoteStyle": "double"
}
},
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true
}
},
"linter": {
"enabled": true,
"rules": {
"complexity": {
"noForEach": "off",
"noStaticOnlyClass": "off",
"noUselessSwitchCase": "off",
"useArrowFunction": "info",
"useFlatMap": "off",
"useLiteralKeys": "info"
},
"correctness": {
"noInnerDeclarations": "info",
"noSelfAssign": "off",
"noSwitchDeclarations": "info",
"noUnsafeOptionalChaining": "info"
},
"performance": {
"noDelete": "info"
},
"recommended": true,
"style": {
"noNegationElse": "off",
"noParameterAssign": "off",
"noUselessElse": "off",
"noVar": "info",
"useDefaultParameterLast": "info",
"useForOf": "error",
"useNodejsImportProtocol": "error",
"useNumberNamespace": "error",
"useSingleVarDeclarator": "off"
},
"suspicious": {
"noAssignInExpressions": "info",
"noDoubleEquals": "info",
"noFallthroughSwitchClause": "info",
"noGlobalIsNan": "off",
"useDefaultSwitchClauseLast": "off"
}
}
},
"organizeImports": {
"enabled": true
},
"vcs": {
"clientKind": "git",
"enabled": true,
"useIgnoreFile": true
}
}
9 changes: 7 additions & 2 deletions rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default defineConfig({
new NodePolyfillPlugin({
//additionalAliases: ['console'],
}),
new rspack.BannerPlugin({
banner: `console.log('Date: ${new Date().toLocaleString("zh-CN", { timeZone: "PRC" })}');`,
raw: true,
}),
new rspack.BannerPlugin({
banner: `console.log('Version: ${pkg.version}');`,
raw: true,
Expand All @@ -24,13 +28,14 @@ export default defineConfig({
raw: true,
}),
new rspack.BannerPlugin({
banner: "console.log('🍿️ DualSubs: ▶️ YouTube');",
banner: `console.log('${pkg.displayName}');`,
raw: true,
}),
new rspack.BannerPlugin({
banner: "https://DualSubs.github.io",
banner: pkg.homepage,
}),
],
devtool: false,
performance: false,
module: {
rules: [
Expand Down
9 changes: 7 additions & 2 deletions rspack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default defineConfig({
new NodePolyfillPlugin({
//additionalAliases: ['console'],
}),
new rspack.BannerPlugin({
banner: `console.log('Date: ${new Date().toLocaleString("zh-CN", { timeZone: "PRC" })}');`,
raw: true,
}),
new rspack.BannerPlugin({
banner: `console.log('Version: ${pkg.version}');`,
raw: true,
Expand All @@ -24,13 +28,14 @@ export default defineConfig({
raw: true,
}),
new rspack.BannerPlugin({
banner: "console.log('🍿️ DualSubs: ▶️ YouTube β');",
banner: `console.log('${pkg.displayName}');`,
raw: true,
}),
new rspack.BannerPlugin({
banner: "https://DualSubs.github.io",
banner: pkg.homepage,
}),
],
devtool: false,
performance: false,
module: {
rules: [
Expand Down
2 changes: 0 additions & 2 deletions src/function/database.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export default {
Default: {
Settings: {
Switch: true,
Type: "Translate",
Types: ["Official", "Translate"],
Languages: ["EN", "ZH"],
Expand All @@ -20,7 +19,6 @@ export default {
},
YouTube: {
Settings: {
Switch: true,
Type: "Official",
Types: ["Translate", "External"],
Languages: ["AUTO", "ZH"],
Expand Down
7 changes: 4 additions & 3 deletions src/function/setCache.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { log } from "@nsnanocat/util";
import { Console } from "@nsnanocat/util";

/**
* Set Cache
* @author VirgilClyne
Expand All @@ -7,9 +8,9 @@ import { log } from "@nsnanocat/util";
* @return {Boolean} isSaved
*/
export default function setCache(cache, cacheSize = 100) {
log(`☑️ Set Cache, cacheSize: ${cacheSize}`, "");
Console.log("☑️ Set Cache", `cacheSize: ${cacheSize}`);
cache = Array.from(cache || []); // Map转Array
cache = cache.slice(-cacheSize); // 限制缓存大小
log(`✅ Set Cache`, "");
Console.log("✅ Set Cache");
return cache;
};
8 changes: 4 additions & 4 deletions src/function/setCaptions.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { log } from "@nsnanocat/util";
import { Console } from "@nsnanocat/util";

export default function setCaptions(captions, translationLanguages) {
log(`☑️ Set Captions`);
Console.log("☑️ Set Captions");
// 有播放器字幕列表渲染器
if (captions?.playerCaptionsTracklistRenderer) {
log(`⚠ Tracklist`);
Console.info("Tracklist");
if (captions?.playerCaptionsTracklistRenderer?.captionTracks) {
// 改字幕可用性
captions.playerCaptionsTracklistRenderer.captionTracks = captions?.playerCaptionsTracklistRenderer.captionTracks.map(caption => {
Expand Down Expand Up @@ -38,6 +38,6 @@ export default function setCaptions(captions, translationLanguages) {
captions.playerCaptionsTracklistRenderer.defaultCaptionTrackIndex = 0;
};
};
log(`✅ Set Captions, `);
Console.log("✅ Set Captions");
return captions;
};
11 changes: 6 additions & 5 deletions src/function/setENV.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getStorage, Lodash as _, log } from "@nsnanocat/util";
import { Console, getStorage, Lodash as _ } from "@nsnanocat/util";

/**
* Set Environment Variables
Expand All @@ -10,19 +10,20 @@ import { getStorage, Lodash as _, log } from "@nsnanocat/util";
* @return {Object} { Settings, Caches, Configs }
*/
export default function setENV(name, platforms, database) {
log(`☑️ Set Environment Variables`, "");
let { Settings, Caches, Configs } = getStorage(name, platforms, database);
Console.log("☑️ Set Environment Variables");
const { Settings, Caches, Configs } = getStorage(name, platforms, database);
/***************** Settings *****************/
if (!Array.isArray(Settings?.Types)) Settings.Types = (Settings.Types) ? [Settings.Types] : []; // 只有一个选项时,无逗号分隔
log(`✅ Set Environment Variables, Settings: ${typeof Settings}, Settings内容: ${JSON.stringify(Settings)}`, "");
Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings)}`);
/***************** Caches *****************/
//log(`✅ Set Environment Variables, Caches: ${typeof Caches}, Caches内容: ${JSON.stringify(Caches)}`, "");
//Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`);
if (typeof Caches?.Playlists !== "object" || Array.isArray(Caches?.Playlists)) Caches.Playlists = {}; // 创建Playlists缓存
Caches.Playlists.Master = new Map(JSON.parse(Caches?.Playlists?.Master || "[]")); // Strings转Array转Map
Caches.Playlists.Subtitle = new Map(JSON.parse(Caches?.Playlists?.Subtitle || "[]")); // Strings转Array转Map
if (typeof Caches?.Subtitles !== "object") Caches.Subtitles = new Map(JSON.parse(Caches?.Subtitles || "[]")); // Strings转Array转Map
if (typeof Caches?.Metadatas !== "object" || Array.isArray(Caches?.Metadatas)) Caches.Metadatas = {}; // 创建Playlists缓存
if (typeof Caches?.Metadatas?.Tracks !== "object") Caches.Metadatas.Tracks = new Map(JSON.parse(Caches?.Metadatas?.Tracks || "[]")); // Strings转Array转Map
/***************** Configs *****************/
Console.log("✅ Set Environment Variables");
return { Settings, Caches, Configs };
};
Loading

0 comments on commit 42c5292

Please sign in to comment.