2024-04-22 13:47:07 +00:00
|
|
|
|
<!DOCTYPE html>
|
2024-02-16 09:33:42 +00:00
|
|
|
|
|
2023-09-24 04:22:57 +00:00
|
|
|
|
<head>
|
2024-04-22 13:47:07 +00:00
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
|
<meta name="format-detection" content="telephone=no" />
|
|
|
|
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
|
|
|
<meta name="viewport" content="user-scalable=no, viewport-fit=cover" />
|
2023-12-27 15:07:16 +00:00
|
|
|
|
<title>无名杀</title>
|
2024-04-06 17:01:43 +00:00
|
|
|
|
<script>
|
2024-04-22 13:47:07 +00:00
|
|
|
|
if (
|
|
|
|
|
typeof window.require == "function" &&
|
|
|
|
|
typeof window.process == "object" &&
|
|
|
|
|
typeof window.__dirname == "string"
|
|
|
|
|
) {
|
2024-04-06 17:01:43 +00:00
|
|
|
|
// 使importMap解析node内置模块
|
2024-04-22 13:47:07 +00:00
|
|
|
|
const builtinModules = require("module").builtinModules;
|
2024-04-06 17:01:43 +00:00
|
|
|
|
if (Array.isArray(builtinModules)) {
|
|
|
|
|
const importMap = {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
imports: {},
|
2024-04-06 17:01:43 +00:00
|
|
|
|
};
|
|
|
|
|
for (const module of builtinModules) {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
importMap.imports[module] = importMap.imports[`node:${module}`] =
|
|
|
|
|
`./noname-builtinModules/${module}`;
|
2024-04-06 17:01:43 +00:00
|
|
|
|
}
|
2024-04-22 13:47:07 +00:00
|
|
|
|
const im = document.createElement("script");
|
|
|
|
|
im.type = "importmap";
|
2024-04-06 17:01:43 +00:00
|
|
|
|
im.textContent = JSON.stringify(importMap);
|
|
|
|
|
document.currentScript.after(im);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2023-12-27 15:07:16 +00:00
|
|
|
|
<script>
|
2024-03-30 18:18:12 +00:00
|
|
|
|
"use strict";
|
2024-02-16 09:33:42 +00:00
|
|
|
|
(() => {
|
|
|
|
|
window.onerror = function (msg, src, line, column, err) {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
let str = `错误文件: ${typeof src == "string" && src.length > 0 ? decodeURI(src) : "未知文件"}`;
|
2024-02-16 09:33:42 +00:00
|
|
|
|
str += `\n错误信息: ${msg}`;
|
|
|
|
|
str += `\n行号: ${line}`;
|
|
|
|
|
str += `\n列号: ${column}`;
|
2024-04-22 13:47:07 +00:00
|
|
|
|
if (err && err.stack) str += "\n" + decodeURI(err.stack);
|
2024-02-16 09:33:42 +00:00
|
|
|
|
console.error(str);
|
|
|
|
|
alert(str);
|
|
|
|
|
};
|
|
|
|
|
const STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
|
|
|
|
|
const errorList = [];
|
2024-03-08 16:38:21 +00:00
|
|
|
|
function extractLocation(urlLike) {
|
|
|
|
|
// 不存在地址信息的字符串
|
|
|
|
|
if (!/:/.test(urlLike)) {
|
|
|
|
|
return [urlLike];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 捕获位置用到的正则
|
|
|
|
|
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
2024-04-22 13:47:07 +00:00
|
|
|
|
const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
|
2024-03-08 16:38:21 +00:00
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
return [parts[1], parts[2] || void 0, parts[3] || void 0];
|
|
|
|
|
}
|
2024-04-22 13:47:07 +00:00
|
|
|
|
window.onunhandledrejection = async (event) => {
|
|
|
|
|
event.promise.catch((error) => {
|
2024-02-16 09:33:42 +00:00
|
|
|
|
console.log(error);
|
|
|
|
|
// 如果`error`是个错误,则继续处理
|
|
|
|
|
if (error instanceof Error) {
|
|
|
|
|
// 如果已经处理过该错误,则不再处理
|
|
|
|
|
if (errorList.includes(error)) return;
|
|
|
|
|
errorList.push(error);
|
|
|
|
|
// 如果`error`拥有字符串形式的报错栈堆,且报错栈堆确实符合v8的stack
|
2024-04-22 13:47:07 +00:00
|
|
|
|
if (typeof error.stack === "string" && STACK_REGEXP.test(error.stack)) {
|
2024-02-16 09:33:42 +00:00
|
|
|
|
// 获取符合栈堆信息的字符串,一般来说就是从第二行开始的所有行
|
|
|
|
|
// 为了处理eval的情况,故必须获取完行数
|
2024-04-22 13:47:07 +00:00
|
|
|
|
let lines = error.stack.split("\n").filter((line) => STACK_REGEXP.test(line));
|
2024-02-16 09:33:42 +00:00
|
|
|
|
|
|
|
|
|
// 提供类型信息防止vscode报错
|
|
|
|
|
/**
|
|
|
|
|
* @type {string | undefined}
|
|
|
|
|
*/
|
|
|
|
|
let fileName = void 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {number | undefined}
|
|
|
|
|
*/
|
|
|
|
|
let line = void 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {number | undefined}
|
|
|
|
|
*/
|
|
|
|
|
let column = void 0;
|
|
|
|
|
|
|
|
|
|
// 从第一条开始遍历,一直遍历到不存在eval的位置
|
|
|
|
|
for (let currentLine = 0; currentLine < lines.length; ++currentLine) {
|
|
|
|
|
if (/\(eval /.test(lines[currentLine])) continue;
|
|
|
|
|
|
2024-04-22 13:47:07 +00:00
|
|
|
|
let formatedLine = lines[currentLine]
|
|
|
|
|
.replace(/^\s+/, "")
|
|
|
|
|
.replace(/\(eval code/g, "(")
|
|
|
|
|
.replace(/^.*?\s+/, "");
|
2024-02-16 09:33:42 +00:00
|
|
|
|
|
|
|
|
|
const location = formatedLine.match(/ (\(.+\)$)/);
|
2024-04-22 13:47:07 +00:00
|
|
|
|
if (location) formatedLine = formatedLine.replace(location[0], "");
|
2024-02-16 09:33:42 +00:00
|
|
|
|
|
|
|
|
|
const locationParts = extractLocation(location ? location[1] : formatedLine);
|
|
|
|
|
|
2024-04-22 13:47:07 +00:00
|
|
|
|
fileName = ["eval", "<anonymous>"].includes(locationParts[0])
|
|
|
|
|
? void 0
|
|
|
|
|
: locationParts[0];
|
2024-02-16 09:33:42 +00:00
|
|
|
|
line = Number(locationParts[1]);
|
|
|
|
|
column = Number(locationParts[2]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
window.onerror(error.message, fileName, line, column, error);
|
|
|
|
|
}
|
|
|
|
|
// 反之我们只能不考虑报错文件信息,直接调用onerror
|
|
|
|
|
else {
|
|
|
|
|
try {
|
|
|
|
|
// @ts-ignore
|
2024-04-22 13:47:07 +00:00
|
|
|
|
let [_, src = void 0, line = void 0, column = void 0] =
|
|
|
|
|
/at\s+.*\s+\((.*):(\d*):(\d*)\)/i.exec(error.stack.split("\n")[1]);
|
|
|
|
|
if (typeof line == "string") line = Number(line);
|
|
|
|
|
if (typeof column == "string") column = Number(column);
|
2024-02-16 09:33:42 +00:00
|
|
|
|
// @ts-ignore
|
|
|
|
|
window.onerror(error.message, src, line, column, error);
|
|
|
|
|
} catch (e) {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
window.onerror(error.message, "", 0, 0, error);
|
2024-02-16 09:33:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
})();
|
2023-12-27 15:07:16 +00:00
|
|
|
|
</script>
|
2024-01-15 13:08:05 +00:00
|
|
|
|
<script>
|
2024-03-30 18:18:12 +00:00
|
|
|
|
"use strict";
|
2024-04-22 13:47:07 +00:00
|
|
|
|
if (
|
|
|
|
|
location.href.startsWith("http") &&
|
|
|
|
|
typeof window.initReadWriteFunction != "function" &&
|
|
|
|
|
!window.require &&
|
|
|
|
|
!window.__dirname
|
|
|
|
|
) {
|
2024-02-16 09:33:42 +00:00
|
|
|
|
window.initReadWriteFunction = async function (game) {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
fetch(`./readFile?fileName=noname.js`)
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((response) => {
|
2024-01-15 13:08:05 +00:00
|
|
|
|
return response.json();
|
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((result) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
if (result && result.success) callback();
|
2024-04-22 13:47:07 +00:00
|
|
|
|
else reject(result.errorMsg);
|
2024-01-15 13:08:05 +00:00
|
|
|
|
})
|
2024-01-19 15:57:05 +00:00
|
|
|
|
.catch(reject);
|
2024-01-15 13:08:05 +00:00
|
|
|
|
|
2024-01-19 15:57:05 +00:00
|
|
|
|
function callback() {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
game.readFile = function (fileName, callback = () => {}, error = () => {}) {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
fetch(`./readFile?fileName=${fileName}`)
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((response) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
return response.json();
|
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((result) => {
|
|
|
|
|
if (result && result.success)
|
|
|
|
|
callback(new Uint8Array(result.data).buffer);
|
2024-01-19 15:57:05 +00:00
|
|
|
|
else error(result && result.errorMsg);
|
|
|
|
|
})
|
|
|
|
|
.catch(error);
|
|
|
|
|
};
|
2024-01-15 13:08:05 +00:00
|
|
|
|
|
2024-04-22 13:47:07 +00:00
|
|
|
|
game.readFileAsText = function (fileName, callback = () => {}, error = () => {}) {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
fetch(`./readFileAsText?fileName=${fileName}`)
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((response) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
return response.json();
|
2024-01-15 13:08:05 +00:00
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((result) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
if (result && result.success) callback(result.data);
|
|
|
|
|
else error(result && result.errorMsg);
|
|
|
|
|
})
|
|
|
|
|
.catch(error);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-22 13:47:07 +00:00
|
|
|
|
game.writeFile = function (data, path, name, callback = () => {}) {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
game.ensureDirectory(path, function () {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
if (Object.prototype.toString.call(data) == "[object File]") {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
const fileReader = new FileReader();
|
|
|
|
|
fileReader.onload = function (e) {
|
|
|
|
|
game.writeFile(e.target.result, path, name, callback);
|
|
|
|
|
};
|
|
|
|
|
fileReader.readAsArrayBuffer(data, "UTF-8");
|
2024-04-22 13:47:07 +00:00
|
|
|
|
} else {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
let filePath = path;
|
2024-04-22 13:47:07 +00:00
|
|
|
|
if (path.endsWith("/")) {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
filePath += name;
|
|
|
|
|
} else if (path == "") {
|
|
|
|
|
filePath += name;
|
|
|
|
|
} else {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
filePath += "/" + name;
|
2024-01-19 15:57:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetch(`./writeFile`, {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
method: "post",
|
2024-01-19 15:57:05 +00:00
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify({
|
2024-04-22 13:47:07 +00:00
|
|
|
|
data:
|
|
|
|
|
typeof data == "string"
|
|
|
|
|
? data
|
|
|
|
|
: Array.prototype.slice.call(new Uint8Array(data)),
|
|
|
|
|
path: filePath,
|
|
|
|
|
}),
|
2024-01-19 15:57:05 +00:00
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((response) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
return response.json();
|
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((result) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
if (result && result.success) {
|
|
|
|
|
callback();
|
|
|
|
|
} else {
|
|
|
|
|
callback(result.errorMsg);
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-01-15 13:08:05 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2024-01-19 15:57:05 +00:00
|
|
|
|
};
|
2024-01-15 13:08:05 +00:00
|
|
|
|
|
2024-04-22 13:47:07 +00:00
|
|
|
|
game.removeFile = function (fileName, callback = () => {}) {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
fetch(`./removeFile?fileName=${fileName}`)
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((response) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
return response.json();
|
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((result) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
callback(result.errorMsg);
|
|
|
|
|
})
|
|
|
|
|
.catch(error);
|
|
|
|
|
};
|
2024-01-15 13:08:05 +00:00
|
|
|
|
|
2024-04-22 13:47:07 +00:00
|
|
|
|
game.getFileList = function (dir, callback = () => {}, onerror) {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
fetch(`./getFileList?dir=${dir}`)
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((response) => {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
return response.json();
|
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((result) => {
|
|
|
|
|
if (!result) {
|
|
|
|
|
throw new Error("Cannot get available resource.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.success) {
|
|
|
|
|
callback(result.data.folders, result.data.files);
|
|
|
|
|
} else if (onerror) {
|
|
|
|
|
onerror(new Error(result.errorMsg));
|
2024-01-19 15:57:05 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-22 13:47:07 +00:00
|
|
|
|
game.ensureDirectory = function (list, callback = () => {}, file = false) {
|
2024-01-19 15:57:05 +00:00
|
|
|
|
let pathArray = typeof list == "string" ? list.split("/") : list;
|
|
|
|
|
if (file) {
|
|
|
|
|
pathArray = pathArray.slice(0, -1);
|
2024-01-15 13:08:05 +00:00
|
|
|
|
}
|
2024-01-19 15:57:05 +00:00
|
|
|
|
game.createDir(pathArray.join("/"), callback, console.error);
|
|
|
|
|
};
|
2024-01-15 13:08:05 +00:00
|
|
|
|
|
2024-04-22 13:47:07 +00:00
|
|
|
|
game.createDir = (
|
|
|
|
|
directory,
|
|
|
|
|
successCallback = () => {},
|
|
|
|
|
errorCallback = () => {}
|
|
|
|
|
) => {
|
2024-03-30 18:18:12 +00:00
|
|
|
|
fetch(`./createDir?dir=${directory}`)
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((response) => {
|
2024-03-30 18:18:12 +00:00
|
|
|
|
return response.json();
|
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((result) => {
|
2024-03-30 18:18:12 +00:00
|
|
|
|
if (result && result.success) {
|
|
|
|
|
successCallback();
|
|
|
|
|
} else {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
errorCallback(new Error("创建文件夹失败"));
|
|
|
|
|
}
|
2024-03-30 18:18:12 +00:00
|
|
|
|
})
|
|
|
|
|
.catch(errorCallback);
|
|
|
|
|
};
|
2024-04-22 13:47:07 +00:00
|
|
|
|
game.removeDir = (
|
|
|
|
|
directory,
|
|
|
|
|
successCallback = () => {},
|
|
|
|
|
errorCallback = () => {}
|
|
|
|
|
) => {
|
2024-03-30 18:18:12 +00:00
|
|
|
|
fetch(`./removeDir?dir=${directory}`)
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((response) => {
|
2024-03-30 18:18:12 +00:00
|
|
|
|
return response.json();
|
|
|
|
|
})
|
2024-04-22 13:47:07 +00:00
|
|
|
|
.then((result) => {
|
2024-03-30 18:18:12 +00:00
|
|
|
|
if (result && result.success) {
|
|
|
|
|
successCallback();
|
|
|
|
|
} else {
|
2024-04-22 13:47:07 +00:00
|
|
|
|
errorCallback(new Error("创建文件夹失败"));
|
|
|
|
|
}
|
2024-03-30 18:18:12 +00:00
|
|
|
|
})
|
2024-03-30 18:35:14 +00:00
|
|
|
|
.catch(errorCallback);
|
2024-03-30 18:18:12 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-01-19 15:57:05 +00:00
|
|
|
|
resolve();
|
2024-01-15 13:08:05 +00:00
|
|
|
|
}
|
2024-01-19 15:57:05 +00:00
|
|
|
|
});
|
2024-01-15 13:08:05 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2023-12-27 15:07:16 +00:00
|
|
|
|
<script src="game/update.js"></script>
|
|
|
|
|
<script src="game/config.js"></script>
|
|
|
|
|
<script src="game/package.js"></script>
|
|
|
|
|
<script src="game/game.js"></script>
|
2024-04-22 13:47:07 +00:00
|
|
|
|
</head>
|