fix: base()从script src反推模块前缀——嵌入主页面时pathname推导失效导致URL缺/scense_game

This commit is contained in:
pipeline-agent 2026-08-30 10:36:29 +08:00
parent 979cc39687
commit 269e6467ab

View File

@ -9,6 +9,13 @@ window.scenseGameList = (function () {
}
function base() {
// 嵌入主页面时 location.pathname 是主页面路径,推导失败;
// 改为从本 js 的 <script src> 反推模块前缀(/scense_game/game_list.js -> /scense_game
var scripts = document.querySelectorAll('script[src]');
for (var i = 0; i < scripts.length; i++) {
var m = (scripts[i].src || '').match(/^(.*\/)game_list\.js/);
if (m) return m[1].replace(/\/+$/, '');
}
var p = window.location.pathname.replace(/\/game\/.*$/, '');
return p.replace(/\/+$/, '');
}