-
Notifications
You must be signed in to change notification settings - Fork 8
/
loader.js
97 lines (97 loc) · 5.29 KB
/
loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(async function() {
let VERSION = 31.5;
if ((window.location && ['localhost', '127.0.0.1'].includes(location.hostname)) ||
'undefined' != typeof EJS_DEBUG_XX && true === EJS_DEBUG_XX) {
fetch('https://raw.githack.com/EmulatorJS/EmulatorJS/main/data/version.json').then(response => {
if (response.ok) {
response.text().then(body => {
let version = JSON.parse(body);
if (VERSION < version.current_version) {
console.log('Using emulatorjs version ' + VERSION + ' but the newest version is ' + version.current_version + '\nopen https://github.com/EmulatorJS/EmulatorJS to update');
}
})
}
})
}
let scriptTag = document.getElementsByTagName('script')[0];
function loadStyle(file) {
return new Promise(function(resolve, reject) {
let css = document.createElement('link');
css.rel = 'stylesheet';
css.href = function() {
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] == 'string') {
return EJS_paths[file];
} else if ('undefined' != typeof EJS_pathtodata) {
if (!EJS_pathtodata.endsWith('/')) EJS_pathtodata+='/';
return EJS_pathtodata+file+'?v='+VERSION;
} else {
return file+'?v='+VERSION;
}
}();
css.onload = resolve;
document.head.appendChild(css);
})
}
function loadScript(file) {
return new Promise(function (resolve, reject) {
let script = document.createElement('script');
script.src = function() {
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] == 'string') {
return EJS_paths[file];
} else if ('undefined' != typeof EJS_pathtodata) {
if (!EJS_pathtodata.endsWith('/')) EJS_pathtodata+='/';
return EJS_pathtodata+file+'?v='+VERSION;
} else {
return file+'?v='+VERSION;
}
}();
scriptTag.parentNode.insertBefore(script, scriptTag);
script.onload = resolve;
})
}
const isIpad = /Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints && navigator.maxTouchPoints > 1;
if (('undefined' != typeof EJS_DEBUG_XX && true === EJS_DEBUG_XX) ||
/(iPad|iPhone|iPod)/gi.test(navigator.platform) || isIpad) {
await loadStyle('emu-css.css');
await loadScript('emu-main.js');
await loadScript('emulator.js');
} else {
await loadStyle('emu-css.min.css');
await loadScript('emulator.min.js');
}
let config = {};
config.gameUrl = EJS_gameUrl;
'undefined' != typeof EJS_mameCore && (config.mameCore = EJS_mameCore);
'undefined' != typeof EJS_biosUrl && (config.biosUrl = EJS_biosUrl);
'undefined' != typeof EJS_gameParentUrl && (config.gameParentUrl = EJS_gameParentUrl);
'undefined' != typeof EJS_gamePatchUrl && (config.gamePatchUrl = EJS_gamePatchUrl);
'undefined' != typeof EJS_AdUrl && (config.adUrl = EJS_AdUrl);
'undefined' != typeof EJS_paths && (config.paths = EJS_paths);
'undefined' != typeof EJS_gameID && (config.gameId = EJS_gameID);
'undefined' != typeof EJS_netplayUrl && (config.netplayUrl = EJS_netplayUrl);
'undefined' != typeof EJS_startOnLoaded && (config.startOnLoad = EJS_startOnLoaded);
'undefined' != typeof EJS_core && (config.system = EJS_core);
'undefined' != typeof EJS_oldCores && (config.oldCores = EJS_oldCores);
'undefined' != typeof EJS_loadStateURL && (config.loadStateOnStart = EJS_loadStateURL);
'undefined' != typeof EJS_defaultOptions && (config.defaultMenuOptions = EJS_defaultOptions);
'undefined' != typeof EJS_language && (config.lang = EJS_language);
'undefined' != typeof EJS_noAutoCloseAd && (config.noAutoAdClose = EJS_noAutoCloseAd);
'undefined' != typeof EJS_VirtualGamepadSettings && (config.VirtualGamepadSettings = EJS_VirtualGamepadSettings);
'undefined' != typeof EJS_Buttons && (config.buttons = EJS_Buttons);
'undefined' != typeof EJS_Settings && (config.settings = EJS_Settings);
'undefined' != typeof EJS_CacheLimit && (config.cacheLimit = EJS_CacheLimit);
config.onsavestate = null;
config.onloadstate = null;
'undefined' != typeof EJS_onSaveState && (config.onsavestate = EJS_onSaveState);
'undefined' != typeof EJS_onLoadState && (config.onloadstate = EJS_onLoadState);
'undefined' != typeof EJS_lightgun && (config.lightgun = EJS_lightgun);
'undefined' != typeof EJS_gameName && (config.gameName = EJS_gameName);
'undefined' != typeof EJS_pathtodata && (config.dataPath = EJS_pathtodata);
'undefined' != typeof EJS_mouse && (config.mouse = EJS_mouse);
'undefined' != typeof EJS_multitap && (config.multitap = EJS_multitap);
'undefined' != typeof EJS_playerName && (config.playerName = EJS_playerName);
'undefined' != typeof EJS_cheats && (config.cheats = EJS_cheats);
'undefined' != typeof EJS_color && (config.color = EJS_color);
window.EJS_emulator = await new EJS(EJS_player, config);
'undefined' != typeof EJS_onGameStart && EJS_emulator.on('start-game', EJS_onGameStart);
})();