/** * โหลดก่อนสคริปต์อื่นที่ใช้ appPath() — รองรับ WAMP subfolder เช่น /game-justic2/ */ (function (global) { var APP_BASE = ''; var scripts = document.getElementsByTagName('script'); for (var i = 0; i < scripts.length; i++) { var full = scripts[i].src; if (!full || !/\/app-base\.js(\?|#|$)/i.test(full)) continue; try { var path = new URL(full, global.location.href).pathname; APP_BASE = path.replace(/\/app-base\.js.*$/i, '').replace(/\/$/, '') || ''; break; } catch (e) { /* ignore */ } } if (!APP_BASE && global.location && global.location.pathname) { var pageMatch = String(global.location.pathname).match(/^\/(game-justic2|game-justic)(?=\/|$)/i); if (pageMatch) APP_BASE = '/' + pageMatch[1]; } if (!APP_BASE) { try { var savedBase = (global.sessionStorage && global.sessionStorage.getItem('APP_BASE')) || (global.localStorage && global.localStorage.getItem('APP_BASE')) || ''; if (savedBase && savedBase.charAt(0) === '/') APP_BASE = savedBase.replace(/\/$/, ''); } catch (e3) { /* ignore */ } } try { if (APP_BASE) { if (global.sessionStorage) global.sessionStorage.setItem('APP_BASE', APP_BASE); if (global.localStorage) global.localStorage.setItem('APP_BASE', APP_BASE); } } catch (e4) { /* ignore */ } global.APP_BASE = APP_BASE; global.appPath = function appPath(rel) { if (rel == null || rel === '') return APP_BASE || ''; rel = String(rel); if (rel.charAt(0) !== '/') rel = '/' + rel; return (APP_BASE || '') + rel; }; var host = global.location ? global.location.hostname : 'localhost'; var protocol = global.location && global.location.protocol === 'https:' ? 'https:' : 'http:'; global.GAME_SERVER = protocol + '//' + host + ':3004'; global.CHAT_SERVER = protocol + '//' + host + ':3003'; })(typeof window !== 'undefined' ? window : this);