diff --git a/package-lock.json b/package-lock.json index 7cfb00d..5e93ce3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "markdown-it-shiki": "^0.8.0", "monaco-editor": "^0.36.1", "prettier": "^2.8.7", + "terser": "^5.16.8", "typescript": "^5.0.3", "unplugin-auto-import": "^0.15.2", "unplugin-icons": "^0.16.1", @@ -2168,7 +2169,6 @@ "resolved": "https://registry.npmmirror.com/@jridgewell/source-map/-/source-map-0.3.2.tgz", "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", "dev": true, - "peer": true, "dependencies": { "@jridgewell/gen-mapping": "^0.3.0", "@jridgewell/trace-mapping": "^0.3.9" @@ -2179,7 +2179,6 @@ "resolved": "https://registry.npmmirror.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", "dev": true, - "peer": true, "dependencies": { "@jridgewell/set-array": "^1.0.1", "@jridgewell/sourcemap-codec": "^1.4.10", @@ -3153,8 +3152,7 @@ "version": "1.1.2", "resolved": "https://registry.npmmirror.com/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true, - "peer": true + "dev": true }, "node_modules/c12": { "version": "1.1.2", @@ -3284,8 +3282,7 @@ "version": "2.20.3", "resolved": "https://registry.npmmirror.com/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true, - "peer": true + "dev": true }, "node_modules/compute-scroll-into-view": { "version": "1.0.20", @@ -5282,7 +5279,6 @@ "resolved": "https://registry.npmmirror.com/source-map-support/-/source-map-support-0.5.21.tgz", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", "dev": true, - "peer": true, "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -5431,7 +5427,6 @@ "resolved": "https://registry.npmmirror.com/terser/-/terser-5.16.8.tgz", "integrity": "sha512-QI5g1E/ef7d+PsDifb+a6nnVgC4F22Bg6T0xrBrz6iloVB4PUkkunp6V8nzoOOZJIzjWVdAGqCdlKlhLq/TbIA==", "dev": true, - "peer": true, "dependencies": { "@jridgewell/source-map": "^0.3.2", "acorn": "^8.5.0", diff --git a/package.json b/package.json index 3d6f7ae..c06a3bf 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "markdown-it-shiki": "^0.8.0", "monaco-editor": "^0.36.1", "prettier": "^2.8.7", + "terser": "^5.16.8", "typescript": "^5.0.3", "unplugin-auto-import": "^0.15.2", "unplugin-icons": "^0.16.1", diff --git a/src/shared/composables/monaco.ts b/src/shared/composables/monaco.ts index c6877d9..6b6042d 100644 --- a/src/shared/composables/monaco.ts +++ b/src/shared/composables/monaco.ts @@ -1,10 +1,14 @@ import loader, { Monaco } from "@monaco-editor/loader" +import { isLowVersion, protocol } from "~/utils/functions" export const monaco = ref() export async function init() { + const version = isLowVersion ? "0.30.1" : "0.36.1" loader.config({ - paths: { vs: "https://cdn.staticfile.org/monaco-editor/0.36.1/min/vs" }, + paths: { + vs: `${protocol}://cdn.staticfile.org/monaco-editor/${version}/min/vs`, + }, "vs/nls": { availableLanguages: { "*": "zh-cn" } }, }) diff --git a/src/utils/functions.ts b/src/utils/functions.ts index f42b66e..37a1a6b 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -152,3 +152,12 @@ export function decode(bytes?: string) { ) ) } + +function getChromeVersion() { + var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./) + return raw ? parseInt(raw[2], 10) : 0 +} + +export const isLowVersion = getChromeVersion() < 80 + +export const protocol = isLowVersion ? "http" : "https" diff --git a/src/utils/judge.ts b/src/utils/judge.ts index 920f66c..8fad906 100644 --- a/src/utils/judge.ts +++ b/src/utils/judge.ts @@ -1,9 +1,9 @@ import axios from "axios" import { DEAD_RESULTS } from "./constants" -import { decode, encode } from "./functions" +import { decode, encode, protocol } from "./functions" import { Code } from "./types" -const http = axios.create({ baseURL: "https://judge0api.hyyz.izhai.net" }) +const http = axios.create({ baseURL: `${protocol}://judge0api.hyyz.izhai.net` }) export async function createTestSubmission(code: Code, input: string) { const encodedCode = encode(code.value)