var LEVELS_INJECT = [
{ value: 'NORMAL', name: '普通打手' },
{ value: 'SILVER', name: '银牌打手' },
{ value: 'GOLD', name: '金牌打手' },
{ value: 'STAR', name: '明星打手' },
{ value: 'ACE', name: '王牌打手' }
];
function createLevelModal(playerId, playerName){
var mask=document.createElement('div');
mask.style.cssText='position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:999999;display:flex;align-items:center;justify-content:center;';
mask.onclick=function(e){if(e.target===mask)document.body.removeChild(mask);};
var modal=document.createElement('div');
modal.style.cssText='background:#fff;border-radius:12px;padding:24px;width:320px;box-shadow:0 10px 40px rgba(0,0,0,0.2);';
modal.onclick=function(e){e.stopPropagation();};
var title=document.createElement('div');
title.style.cssText='font-size:16px;font-weight:bold;margin-bottom:16px;color:#333;';
title.textContent='设置打手等级 - '+playerName;
var select=document.createElement('select');
select.style.cssText='width:100%;padding:10px;border:1px solid #ddd;border-radius:8px;font-size:14px;margin-bottom:16px;';
LEVELS_INJECT.forEach(function(lv){var opt=document.createElement('option');opt.value=lv.value;opt.textContent=lv.name;select.appendChild(opt);});
var btnRow=document.createElement('div');btnRow.style.cssText='display:flex;gap:10px;';
var cancelBtn=document.createElement('button');
cancelBtn.style.cssText='flex:1;padding:10px;border:1px solid #ddd;border-radius:8px;background:#fff;font-size:14px;cursor:pointer;';
cancelBtn.textContent='取消';
cancelBtn.onclick=function(){document.body.removeChild(mask);};
var confirmBtn=document.createElement('button');
confirmBtn.style.cssText='flex:1;padding:10px;border:none;border-radius:8px;background:linear-gradient(135deg,#ff6b9d,#c44dff);color:#fff;font-size:14px;cursor:pointer;font-weight:bold;';
confirmBtn.textContent='确认设置';
confirmBtn.onclick=function(){
confirmBtn.disabled=true;confirmBtn.textContent='设置中...';
fetch('/api/player/auth/rank/setLevel/'+playerId+'?level='+select.value,{method:'POST'})
.then(function(r){return r.json();})
.then(function(data){
if(data.code===200){alert('设置成功!');document.body.removeChild(mask);location.reload();}
else{alert('设置失败:'+(data.msg||'未知错误'));confirmBtn.disabled=false;confirmBtn.textContent='确认设置';}
})
.catch(function(){alert('设置失败');confirmBtn.disabled=false;confirmBtn.textContent='确认设置';});
};
btnRow.appendChild(cancelBtn);btnRow.appendChild(confirmBtn);
modal.appendChild(title);modal.appendChild(select);modal.appendChild(btnRow);
mask.appendChild(modal);document.body.appendChild(mask);
}
function addLevelButtons(){
if(!location.hash.includes('player')&&!location.pathname.includes('player'))return;
var rows=document.querySelectorAll('.el-table__row');
rows.forEach(function(row){
var actions=row.querySelector('.cell:last-child .el-button-group, .cell:last-child');
if(!actions)return;
var nameEl=row.querySelector('.player-detail-name');
var playerName=nameEl?nameEl.textContent.trim():'未知';
var btn=document.createElement('button');
btn.style.cssText='padding:4px 10px;margin-left:4px;border:1px solid #ff6b9d;border-radius:4px;background:#fff;color:#ff6b9d;font-size:12px;cursor:pointer;white-space:nowrap;';
btn.textContent='⭐等级';
btn.onclick=function(e){
e.stopPropagation();
var allText=row.innerText;
var idM=allText.match(/\b(\d{6,})\b/);
var playerId=idM?idM[1]:null;
if(playerId){createLevelModal(playerId,playerName,'NORMAL');}
else{alert('无法获取打手ID');}
};
actions.appendChild(btn);
});
}
setInterval(addLevelButtons,2000);
// 打手等级管理入口
function addRankAdminEntry(){
if(document.getElementById('rank-admin-float')) return;
var btn = document.createElement('a');
btn.id = 'rank-admin-float';
btn.href = '/rank-admin.html';
btn.target = '_blank';
btn.style.cssText = 'position:fixed;right:20px;bottom:80px;z-index:9999;padding:10px 16px;border-radius:20px;background:linear-gradient(135deg,#ff6b9d,#c44dff);color:#fff;text-decoration:none;font-size:13px;font-weight:bold;box-shadow:0 4px 15px rgba(255,107,157,0.4);';
btn.innerHTML = '⭐ 打手等级';
document.body.appendChild(btn);
}
if(document.readyState === 'loading'){
document.addEventListener('DOMContentLoaded', function(){
setTimeout(addRankAdminEntry, 1000);
setTimeout(addRankAdminEntry, 3000);
});
} else {
setTimeout(addRankAdminEntry, 1000);
setTimeout(addRankAdminEntry, 3000);
}