From feeea1fe77dc60471eda3ae77b74bbfada3d1321 Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Wed, 24 Jan 2024 17:46:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E6=9C=AA=E6=9D=A5=E7=9A=84http?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E6=8F=90=E5=89=8D=E5=81=9A=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 4 ++-- noname/init/cordova.js | 15 ++++++++------- noname/util/index.js | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/game/game.js b/game/game.js index 9ca14d25d..74670ccdc 100644 --- a/game/game.js +++ b/game/game.js @@ -5,7 +5,7 @@ new Promise(resolve => { if ('__core-js_shared__' in window) resolve(null); else { const nonameInitialized = localStorage.getItem('noname_inited'); - const assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; + const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); const coreJSBundle = document.createElement('script'); coreJSBundle.onerror = coreJSBundle.onload = resolve; coreJSBundle.src = `${assetURL}game/core-js-bundle.js`; @@ -13,7 +13,7 @@ new Promise(resolve => { } }).then(() => { const nonameInitialized = localStorage.getItem('noname_inited'); - const assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; + const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); const userAgent = navigator.userAgent.toLowerCase(); const exit = () => { diff --git a/noname/init/cordova.js b/noname/init/cordova.js index b642fad9d..291d70906 100644 --- a/noname/init/cordova.js +++ b/noname/init/cordova.js @@ -4,6 +4,7 @@ import { Library as lib } from '../library/index.js'; import { Game as game } from '../game/index.js'; import { status as _status } from '../status/index.js'; import { UI as ui } from '../ui/index.js'; +import { nonameInitialized } from '../util/index.js'; export async function cordovaReady() { lib.path = (await import('../library/path.js')).default; @@ -62,7 +63,7 @@ export async function cordovaReady() { url = get.url(dev) + url; } var fileTransfer = new FileTransfer(); - folder = lib.assetURL + folder; + folder = nonameInitialized + folder; if (onprogress) { fileTransfer.onprogress = function (progressEvent) { onprogress(progressEvent.loaded, progressEvent.total); @@ -79,7 +80,7 @@ export async function cordovaReady() { }, onerror); }; game.readFile = function (filename, callback, onerror) { - window.resolveLocalFileSystemURL(lib.assetURL, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized, function (entry) { entry.getFile(filename, {}, function (fileEntry) { fileEntry.file(function (fileToLoad) { var fileReader = new FileReader(); @@ -92,7 +93,7 @@ export async function cordovaReady() { }, onerror); }; game.readFileAsText = function (filename, callback, onerror) { - window.resolveLocalFileSystemURL(lib.assetURL, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized, function (entry) { entry.getFile(filename, {}, function (fileEntry) { fileEntry.file(function (fileToLoad) { var fileReader = new FileReader(); @@ -114,7 +115,7 @@ export async function cordovaReady() { fileReader.readAsArrayBuffer(data, "UTF-8"); } else { - window.resolveLocalFileSystemURL(lib.assetURL + path, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized + path, function (entry) { entry.getFile(name, { create: true }, function (fileEntry) { fileEntry.createWriter(function (fileWriter) { fileWriter.onwriteend = callback; @@ -126,7 +127,7 @@ export async function cordovaReady() { }); }; game.removeFile = function (dir, callback) { - window.resolveLocalFileSystemURL(lib.assetURL, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized, function (entry) { entry.getFile(dir, {}, function (fileEntry) { fileEntry.remove(); if (callback) callback(); @@ -135,7 +136,7 @@ export async function cordovaReady() { }; game.getFileList = (dir, success, failure) => { var files = [], folders = []; - window.resolveLocalFileSystemURL(lib.assetURL + dir, entry => { + window.resolveLocalFileSystemURL(nonameInitialized + dir, entry => { var dirReader = entry.createReader(); var entries = []; var readEntries = () => { @@ -174,7 +175,7 @@ export async function cordovaReady() { create: true }, resolve))).then(directoryEntry => access(directoryEntry, directory, createDirectory)); }; - return new Promise((resolve, reject) => window.resolveLocalFileSystemURL(lib.assetURL, rootEntry => { + return new Promise((resolve, reject) => window.resolveLocalFileSystemURL(nonameInitialized, rootEntry => { const createDirectory = () => { if (directoryList.length) access(rootEntry, directoryList.pop().split('/').reverse(), createDirectory); if (typeof callback == 'function') callback(); diff --git a/noname/util/index.js b/noname/util/index.js index 05fd85205..724ec163f 100644 --- a/noname/util/index.js +++ b/noname/util/index.js @@ -1,5 +1,5 @@ export const nonameInitialized = localStorage.getItem('noname_inited'); -export const assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; +export const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); export const GeneratorFunction = (function* () { }).constructor; export const AsyncFunction = (async function () { }).constructor; export const userAgent = navigator.userAgent.toLowerCase();