2022-12-29 23:08:44 +08:00
|
|
|
|
///<reference path="../../src/types/core.d.ts" />
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
extensions.js:负责拓展插件
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-29 23:08:44 +08:00
|
|
|
|
'use strict';
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
2022-12-29 23:08:44 +08:00
|
|
|
|
function extensions() {}
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
extensions.prototype._load = function (callback) {
|
|
|
|
|
if (main.replayChecking) return callback();
|
|
|
|
|
if (!window.fs) {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
this._loadJs(
|
|
|
|
|
'_server/fs.js',
|
|
|
|
|
function () {
|
|
|
|
|
core.extensions._listExtensions(callback);
|
|
|
|
|
},
|
|
|
|
|
callback
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
} else this._listExtensions(callback);
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
extensions.prototype._loadJs = function (file, callback, onerror) {
|
|
|
|
|
var script = document.createElement('script');
|
|
|
|
|
script.src = file + '?v=' + main.version;
|
|
|
|
|
script.onload = callback;
|
|
|
|
|
script.onerror = onerror;
|
|
|
|
|
main.dom.body.appendChild(script);
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
extensions.prototype._listExtensions = function (callback) {
|
|
|
|
|
if (!window.fs) return callback();
|
|
|
|
|
fs.readdir('extensions', function (error, data) {
|
|
|
|
|
if (error || !(data instanceof Array)) return callback();
|
|
|
|
|
var list = [];
|
|
|
|
|
data.forEach(function (name) {
|
|
|
|
|
if (/^[\w.-]+\.js$/.test(name)) {
|
|
|
|
|
list.push(name);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
list.sort();
|
|
|
|
|
core.extensions._loadExtensions(list, callback);
|
|
|
|
|
});
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
extensions.prototype._loadExtensions = function (list, callback) {
|
|
|
|
|
var i = 0;
|
|
|
|
|
var load = function () {
|
|
|
|
|
if (i == list.length) return callback();
|
|
|
|
|
core.extensions._loadJs('extensions/' + list[i++], load, load);
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
load();
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|