's'
This commit is contained in:
72
index.html
72
index.html
@@ -32,13 +32,10 @@ button.loading::after{content:" ⏳";animation:spin 1s linear infinite}
|
||||
<div class="container">
|
||||
<h1>
|
||||
进程:
|
||||
<select id="processSelect">
|
||||
<option value="tiktok">tiktok</option>
|
||||
<option value="youtube">youtube</option>
|
||||
<option value="obs">obs</option>
|
||||
</select>
|
||||
<select id="processSelect"></select>
|
||||
<span id="statusIndicator">⚪ 加载中...</span>
|
||||
</h1>
|
||||
<p id="processScriptNote" style="font-size:0.88em;margin:-12px 0 20px;opacity:0.88;font-family:ui-monospace,monospace"></p>
|
||||
|
||||
<!-- YouTube 专属配置(仅 youtube 时显示) -->
|
||||
<div id="youtubeOnlySection" style="display:none;">
|
||||
@@ -87,10 +84,36 @@ button.loading::after{content:" ⏳";animation:spin 1s linear infinite}
|
||||
<pre id="pm2Log">正在加载状态与日志...</pre>
|
||||
</div>
|
||||
<script>
|
||||
/**
|
||||
* 监控目标:本分支用 *2.py / web2 / obs2 等与「无 2」分支区分;常与 Ubuntu+PM2 配套。
|
||||
* 与 web2.py 中 PROCESS_MONITOR / VALID_PROCESSES 一致(PM2 应用名),script 为入口脚本文件名。
|
||||
* 若改了 PM2 进程名,请同步改 pm2 字段与 web2.py。
|
||||
*/
|
||||
const PROCESS_MONITOR = [
|
||||
{ pm2: 'tiktok', script: 'tiktok2.py', label: 'TikTok' },
|
||||
{ pm2: 'youtube', script: 'youtube2.py', label: 'YouTube' },
|
||||
{ pm2: 'obs', script: 'obs2.sh', label: 'OBS' },
|
||||
];
|
||||
|
||||
function getEntryByPm2(name) {
|
||||
return PROCESS_MONITOR.find((e) => e.pm2 === name) || null;
|
||||
}
|
||||
|
||||
function fillProcessSelect() {
|
||||
processSelect.innerHTML = '';
|
||||
PROCESS_MONITOR.forEach((e) => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = e.pm2;
|
||||
opt.textContent = `${e.label}(${e.script})`;
|
||||
processSelect.appendChild(opt);
|
||||
});
|
||||
}
|
||||
|
||||
const logEl = document.getElementById('pm2Log');
|
||||
const statusIndicator = document.getElementById('statusIndicator');
|
||||
const processSelect = document.getElementById('processSelect');
|
||||
let currentProcess = 'tiktok';
|
||||
fillProcessSelect();
|
||||
let currentProcess = PROCESS_MONITOR[0].pm2;
|
||||
|
||||
// 各专属区域
|
||||
const youtubeOnlySection = document.getElementById('youtubeOnlySection');
|
||||
@@ -109,23 +132,31 @@ const loadUrlBtn = document.getElementById('loadUrlBtn');
|
||||
const saveUrlBtn = document.getElementById('saveUrlBtn');
|
||||
const urlStatus = document.getElementById('urlStatus');
|
||||
|
||||
function refreshProcessScriptNote() {
|
||||
const el = document.getElementById('processScriptNote');
|
||||
const ent = getEntryByPm2(currentProcess);
|
||||
el.textContent = ent ? `脚本: ${ent.script} · PM2 名: ${ent.pm2}` : '';
|
||||
}
|
||||
|
||||
processSelect.addEventListener('change', () => {
|
||||
currentProcess = processSelect.value;
|
||||
refreshProcessScriptNote();
|
||||
fetchStatus();
|
||||
updateSectionsVisibility();
|
||||
});
|
||||
|
||||
function updateSectionsVisibility() {
|
||||
youtubeOnlySection.style.display = currentProcess === 'youtube' ? 'block' : 'none';
|
||||
urlConfigSection.style.display = (currentProcess === 'youtube' || currentProcess === 'tiktok') ? 'block' : 'none';
|
||||
obsSection.style.display = currentProcess === 'obs' ? 'block' : 'none';
|
||||
|
||||
if (currentProcess === 'youtube') {
|
||||
loadYoutubeConfig();
|
||||
}
|
||||
if (currentProcess === 'youtube' || currentProcess === 'tiktok') {
|
||||
loadUrlConfig();
|
||||
}
|
||||
const ent = getEntryByPm2(currentProcess);
|
||||
const isYoutube = ent && ent.script === 'youtube2.py';
|
||||
const isTiktok = ent && ent.script === 'tiktok2.py';
|
||||
const isObs = ent && ent.script === 'obs2.sh';
|
||||
|
||||
youtubeOnlySection.style.display = isYoutube ? 'block' : 'none';
|
||||
urlConfigSection.style.display = (isYoutube || isTiktok) ? 'block' : 'none';
|
||||
obsSection.style.display = isObs ? 'block' : 'none';
|
||||
|
||||
if (isYoutube) loadYoutubeConfig();
|
||||
if (isYoutube || isTiktok) loadUrlConfig();
|
||||
}
|
||||
|
||||
// textarea 高度自适应
|
||||
@@ -215,7 +246,9 @@ async function pm2Action(action){
|
||||
updateStatus(data.process_status);
|
||||
let logText = `【PM2 全状态表格】(${new Date().toLocaleTimeString()})\n${data.raw_status}\n\n`;
|
||||
if(data.process_status === 'not_found'){
|
||||
logText += `【提示】进程 "${currentProcess}" 未注册到 PM2(可能被 pm2 delete 删除)\n`;
|
||||
const ent = getEntryByPm2(currentProcess);
|
||||
const hint = ent ? `${ent.script}(PM2 名: ${ent.pm2})` : currentProcess;
|
||||
logText += `【提示】未在 PM2 中找到: ${hint}\n`;
|
||||
}else{
|
||||
logText += `【实时输出日志】`;
|
||||
if(data.recent_log.includes('不存在') || data.recent_log.includes('无日志路径')){
|
||||
@@ -233,7 +266,9 @@ async function pm2Action(action){
|
||||
logEl.textContent = logText;
|
||||
scrollLog();
|
||||
}else{
|
||||
logEl.textContent = `操作: ${action} ${currentProcess}\n${data.output || '成功'}\n\n正在刷新状态...`;
|
||||
const ent = getEntryByPm2(currentProcess);
|
||||
const who = ent ? `${ent.script} (${ent.pm2})` : currentProcess;
|
||||
logEl.textContent = `操作: ${action} → ${who}\n${data.output || '成功'}\n\n正在刷新状态...`;
|
||||
scrollLog();
|
||||
setTimeout(fetchStatus, 1500);
|
||||
}
|
||||
@@ -258,6 +293,7 @@ document.getElementById('pm2Buttons').addEventListener('click', e=>{
|
||||
|
||||
// 自动刷新 + 初始
|
||||
setInterval(fetchStatus, 1000);
|
||||
refreshProcessScriptNote();
|
||||
fetchStatus();
|
||||
updateSectionsVisibility();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user