#5608 Бастион Империи 22 героев |  | 0 |
| » Глава: Вытворяев
» Летописец: Xz6216, Рукисила, Lao, Sherman202 » Глашатай: Авденаго, Супер Дед, Нехотеп, Тёмный Ральф, СТРАЖА БОГОВ, defialko, Arhivarius9, KeNNy___666, Natanial, Skilly, грант2, Мирный Бог, stasancheg, Xz6216, Рукисила, Lao, Sherman202
» Протокол
| // ------------------ SENT DB MANAGER ------------------
function openDbManager(){
let modal=document.getElementById("hwm-db-modal");
if(modal){ modal.style.display="block"; renderDbList(); return; }
modal=document.createElement("div");
modal.id="hwm-db-modal";
modal.style.position="fixed";
modal.style.top="50%";
modal.style.left="50%";
modal.style.transform="translate(-50%,-50%)";
modal.style.background="#fff";
modal.style.padding="12px";
modal.style.maxHeight="70%";
modal.style.overflowY="auto";
modal.style.width="90%";
modal.style.zIndex="99999";
modal.style.border="1px solid #333";
modal.style.borderRadius="6px";
modal.style.boxShadow="0 4px 20px rgba(0,0,0,0.3)";
modal.innerHTML=`
<div style="display:flex;justify-content:space-between;align-items:center;">
<b>База отправленных</b>
<button id="hwm-db-close">Закрыть</button>
</div>
<div style="margin-top:6px;">
<label>Retention (дн): <input id="hwm-db-ret" type="number" min="0" style="width:60px;"></label>
<button id="hwm-db-save-ret">Сохранить</button>
</div>
<div style="margin-top:6px;">
<button id="hwm-db-clean-old">Очистить старые</button>
<button id="hwm-db-clear-all">Очистить всё</button>
<button id="hwm-db-export">Экспорт</button>
<button id="hwm-db-import">Импорт</button>
</div>
<div id="hwm-db-list" style="margin-top:6px;font-size:12px;"></div>
`;
document.body.appendChild(modal);
document.getElementById("hwm-db-close").addEventListener("click",()=>modal.style.display="none");
document.getElementById("hwm-db-save-ret").addEventListener("click",()=>{
const val=parseInt(document.getElementById("hwm-db-ret").value,10);
if(isNaN(val)||val<0){alert("Неверное число"); return;}
saveRetentionDays(val);
renderDbList();
});
document.getElementById("hwm-db-clean-old").addEventListener("click",()=>{
if(!confirm("Удалить старые записи?")) return;
cleanupExpired(loadRetentionDays());
renderDbList();
});
document.getElementById("hwm-db-clear-all").addEventListener("click",()=>{
if(!confirm("Удалить все записи?")) return;
saveSentDb({});
renderDbList();
});
document.getElementById("hwm-db-export").addEventListener("click",()=>{
const txt=JSON.stringify(loadSentDb(),null,2);
prompt("Скопируйте JSON:",txt);
});
document.getElementById("hwm-db-import").addEventListener("click",()=>{
const txt=prompt("Вставьте JSON базы (заменит текущую):");
if(!txt) return;
try{
const parsed=JSON.parse(txt);
if(typeof parsed!=="object") throw new Error("Неправильный формат");
saveSentDb(parsed);
renderDbList();
}catch(e){alert("Ошибка: "+e.message);}
});
document.getElementById("hwm-db-ret").value=loadRetentionDays();
renderDbList();
}
function renderDbList(){
const container=document.getElementById("hwm-db-list");
if(!container) return;
container.innerHTML="";
const db=loadSentDb();
const keys=Object.keys(db).sort((a,b)=>db[b]-db[a]);
if(keys.length===0){container.textContent="(пусто)"; return;}
const now=Date.now();
for(const nick of keys){
const ts=db[nick];
const days=Math.floor((now-ts)/(24*3600*1000));
const row=document.createElement("div");
row.style.display="flex";
row.style.justifyContent="space-between";
row.style.alignItems="center";
row.style.margin="4px 0";
row.innerHTML=`<span>${escapeHtml(nick)} — ${days} дн.</span>`;
const delBtn=document.createElement("button");
delBtn.textContent="удалить";
delBtn.addEventListener("click",()=>{delete db[nick]; saveSentDb(db); renderDbList();});
row.appendChild(delBtn);
container.appendChild(row);
}
}
function cleanupExpired(retentionDays){
const db=loadSentDb();
const now=Date.now();
let changed=false;
for(const nick in db){
if((now-db[nick])>retentionDays*24*3600*1000){delete db[nick]; changed=true;}
}
if(changed) saveSentDb(db);
}
// ------------------ CORE FLOW ------------------
async function submitSearch(nick){
const form=document.querySelector('form[action="search.php"]');
if(!form) return;
const input=form.querySelector('input[name="key"]');
if(!input) return;
input.value=nick;
await wait(3000+Math.random()*2000);
form.submit();
}
async function goToSmsCreate(id){ await wait(3000+Math.random()*2000); window.location.href=`https://www.heroeswm.ru/sms-create.php?mailto_id=${id}`; }
async function handleSmsFlow(){
const bodyText=document.body.innerText||"";
const timerMatch=bodyText.match(/Сообщение может быть отправлено через (\d+) секунд/);
if(timerMatch){
const seconds=parseInt(timerMatch[1],10);
await wait((seconds*1000)+2000+Math.random()*1000);
const submitBtn=document.querySelector('input[name="subm"]');
if(submitBtn) submitBtn.click();
else window.location.reload();
return;
}
const submitBtn=document.querySelector('input[name="subm"]');
if(submitBtn){
const subjectInput=document.querySelector('input[name="subject"]');
const msgTextarea=document.querySelector('textarea[name="msg"]');
if(subjectInput) subjectInput.value=settings.subject;
if(msgTextarea) msgTextarea.value=settings.message;
await wait(2500+Math.random()*1500);
submitBtn.click();
return;
}
const sentPlayer=settings.players[0];
if(sentPlayer){ markSent(sentPlayer); settings.players.shift(); saveSettings(); }
if(settings.players.length>0){ await wait(3500+Math.random()*2000); window.location.href="https://www.heroeswm.ru/search.php"; }
else alert("✅ Все письма отправлены!");
}
// ------------------ MAIN ------------------
(async function main(){
injectMobileUI();
try{ GM_registerMenuCommand && GM_registerMenuCommand("Очистить базу",()=>{ if(confirm("Удалить все записи базы?")){ saveSentDb({}); alert("База очищена"); } }); }catch(e){}
const retention=loadRetentionDays();
if(settings.players && settings.players.length>0){
const {filtered,skipped}=filterPlayersBySent(settings.players,retention);
if(skipped.length>0){ settings.players=filtered; saveSettings(); showInfo(`Пропущено ${skipped.length} (уже писали)`); }
}
const url=window.location.href;
if(!settings.players||settings.players.length===0) return;
if(url.includes("search.php")) await submitSearch(settings.players[0]);
else if(url.includes("pl_info.php?id=")){ const m=url.match(/id=(\d+)/); if(m&&m[1]) await goToSmsCreate(m[1]); }
else if(url.includes("sms-create.php")||url.includes("sms.php")) await handleSmsFlow();
else window.location.href="https://www.heroeswm.ru/search.php";
})();
})();
|
|
|