Remove .gitignore and add dist and node_modules (LFS for .exe)
Made-with: Cursor
This commit is contained in:
1 parent
1fc4db96c8
commit
048ab8b980
5819 files changed
+1357436
-2
No files matched your search
+190
@@ -0,0 +1,190 @@
|
||||
(function () {
|
||||
const CONFIG_URL = 'http://localhost:1947/_int_/config.html';
|
||||
const SESSION_URL = 'http://localhost:1947/_int_/sessions.html';
|
||||
const STORAGE_RUNNING = 'ptw_monitor_running';
|
||||
const STORAGE_LOGS = 'ptw_persistent_logs';
|
||||
const MAX_LOGS = 30;
|
||||
const POLL_MS = 500;
|
||||
const RELOAD_MS = 60000;
|
||||
|
||||
const wv = document.getElementById('wv');
|
||||
const sessionsBox = document.getElementById('sessionsBox');
|
||||
const logBox = document.getElementById('logBox');
|
||||
const toggleBtn = document.getElementById('toggleBtn');
|
||||
const clearBtn = document.getElementById('clearBtn');
|
||||
const statusEl = document.getElementById('status');
|
||||
|
||||
let isRunning = localStorage.getItem(STORAGE_RUNNING) !== 'false';
|
||||
let savedLogs = JSON.parse(localStorage.getItem(STORAGE_LOGS) || '[]');
|
||||
let injectCode = null;
|
||||
let reloadTimer = null;
|
||||
|
||||
function renderSessions(list) {
|
||||
if (!list || list.length === 0) {
|
||||
sessionsBox.innerHTML = "<div class='empty'>No sessions</div>";
|
||||
return;
|
||||
}
|
||||
var byUser = {};
|
||||
list.forEach(function (s) {
|
||||
var u = s.user && s.user.trim() ? s.user.trim() : '(no user)';
|
||||
if (!byUser[u]) byUser[u] = [];
|
||||
byUser[u].push(s);
|
||||
});
|
||||
var users = Object.keys(byUser).sort();
|
||||
var html = [];
|
||||
users.forEach(function (user) {
|
||||
var safeUser = escapeHtml(user);
|
||||
html.push("<div class='sess-user-block'><div class='sess-user-name'>" + safeUser + "</div>");
|
||||
byUser[user].forEach(function (s) {
|
||||
var product = escapeHtml(s.product || '');
|
||||
var feature = escapeHtml(s.feature || '');
|
||||
var detail = (product + (product && feature ? " · " : "") + feature).trim();
|
||||
html.push("<div class='sess-row'>" + (detail ? "<span class='sess-product'>" + detail + "</span>" : "—") + "</div>");
|
||||
});
|
||||
html.push("</div>");
|
||||
});
|
||||
sessionsBox.innerHTML = html.join('');
|
||||
}
|
||||
|
||||
function renderLogs() {
|
||||
if (savedLogs.length === 0) {
|
||||
logBox.innerHTML = "<div class='empty'>No activity...</div>";
|
||||
} else {
|
||||
logBox.innerHTML = savedLogs.map(function (log) {
|
||||
return "<div class='entry'>" + escapeHtml(log) + '</div>';
|
||||
}).join('');
|
||||
}
|
||||
logBox.scrollTop = logBox.scrollHeight;
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = s;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function addLog(msg) {
|
||||
savedLogs.push(msg);
|
||||
if (savedLogs.length > MAX_LOGS) savedLogs.shift();
|
||||
try { localStorage.setItem(STORAGE_LOGS, JSON.stringify(savedLogs)); } catch (e) {}
|
||||
renderLogs();
|
||||
}
|
||||
|
||||
function updateToggleButton() {
|
||||
toggleBtn.textContent = isRunning ? 'MONITOR: ON' : 'MONITOR: OFF';
|
||||
toggleBtn.className = isRunning ? 'toggle-on' : 'toggle-off';
|
||||
}
|
||||
|
||||
function runInWebview(fn) {
|
||||
if (!wv || !wv.executeJavaScript) return Promise.resolve();
|
||||
try {
|
||||
return wv.executeJavaScript(fn);
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
}
|
||||
|
||||
function injectScript() {
|
||||
if (!injectCode) return Promise.resolve();
|
||||
return runInWebview(injectCode).catch(function (err) {
|
||||
console.warn('Inject failed', err);
|
||||
statusEl.textContent = 'Page may block scripts; check console.';
|
||||
});
|
||||
}
|
||||
|
||||
function startReloadTimer() {
|
||||
stopReloadTimer();
|
||||
if (!isRunning) return;
|
||||
reloadTimer = setInterval(function () {
|
||||
if (!isRunning) return;
|
||||
wv.reload();
|
||||
}, RELOAD_MS);
|
||||
}
|
||||
|
||||
function stopReloadTimer() {
|
||||
if (reloadTimer) {
|
||||
clearInterval(reloadTimer);
|
||||
reloadTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function ensureConfigThenSessions() {
|
||||
var url = wv.getURL() || '';
|
||||
if (url.indexOf('config.html') === -1) return;
|
||||
statusEl.textContent = 'Checking config (rows per page)...';
|
||||
runInWebview(
|
||||
"(function(){ var el = document.getElementById('linesperpage'); if (!el) return { submitted: false, status: 'notfound' }; if (el.value === '100') return { submitted: false, status: 'already100' }; el.value = '100'; var btn = document.querySelector('a.confbutton[href*=\"doSubmitConfigUrl\"]'); if (btn) btn.click(); return { submitted: true, status: 'set' }; })()"
|
||||
).then(function (result) {
|
||||
if (result && result.status === 'already100') addLog('Config: rows per page already 100');
|
||||
else if (result && result.submitted) addLog('Config: rows per page set to 100');
|
||||
else if (result && result.status === 'notfound') addLog('Config: rows-per-page input not found');
|
||||
var delay = (result && result.submitted) ? 2500 : 600;
|
||||
setTimeout(function () {
|
||||
wv.src = SESSION_URL;
|
||||
}, delay);
|
||||
}).catch(function () {
|
||||
setTimeout(function () { wv.src = SESSION_URL; }, 500);
|
||||
});
|
||||
}
|
||||
|
||||
wv.addEventListener('did-finish-load', function () {
|
||||
var url = wv.getURL() || '';
|
||||
if (url.indexOf('config.html') !== -1) {
|
||||
ensureConfigThenSessions();
|
||||
return;
|
||||
}
|
||||
if (url.indexOf('sessions.html') === -1) return;
|
||||
statusEl.textContent = 'Connected: ' + SESSION_URL;
|
||||
injectScript().then(function () {
|
||||
return runInWebview("window.__ptw_setRunning(" + isRunning + ")");
|
||||
}).then(function () {
|
||||
if (isRunning) addLog('Refreshed');
|
||||
}).catch(function () {});
|
||||
});
|
||||
|
||||
wv.addEventListener('did-fail-load', function (e) {
|
||||
if (e.errorCode !== -3) statusEl.textContent = 'Load failed: ' + (e.errorDescription || 'check if server is running');
|
||||
});
|
||||
|
||||
setInterval(function () {
|
||||
runInWebview("(window.__ptw_flushLogs && window.__ptw_flushLogs()) || []").then(function (logs) {
|
||||
if (Array.isArray(logs) && logs.length) logs.forEach(addLog);
|
||||
}).catch(function () {});
|
||||
runInWebview("(window.__ptw_getSessions && window.__ptw_getSessions()) || []").then(function (sessions) {
|
||||
if (Array.isArray(sessions)) renderSessions(sessions);
|
||||
}).catch(function () {});
|
||||
}, POLL_MS);
|
||||
|
||||
toggleBtn.addEventListener('click', function () {
|
||||
isRunning = !isRunning;
|
||||
try { localStorage.setItem(STORAGE_RUNNING, isRunning); } catch (e) {}
|
||||
updateToggleButton();
|
||||
addLog(isRunning ? 'Resumed' : 'Paused');
|
||||
runInWebview("window.__ptw_setRunning(" + isRunning + ")").catch(function () {});
|
||||
if (isRunning) {
|
||||
wv.reload();
|
||||
startReloadTimer();
|
||||
} else {
|
||||
stopReloadTimer();
|
||||
}
|
||||
});
|
||||
|
||||
clearBtn.addEventListener('click', function () {
|
||||
savedLogs = [];
|
||||
try { localStorage.removeItem(STORAGE_LOGS); } catch (e) {}
|
||||
renderLogs();
|
||||
});
|
||||
|
||||
clearBtn.classList.add('clear-btn');
|
||||
updateToggleButton();
|
||||
renderLogs();
|
||||
|
||||
if (isRunning) startReloadTimer();
|
||||
|
||||
fetch('inject.js').then(function (r) { return r.text(); }).then(function (code) {
|
||||
injectCode = code;
|
||||
if (wv.getURL() && wv.getURL().indexOf('localhost') !== -1) injectScript();
|
||||
}).catch(function () {
|
||||
statusEl.textContent = 'Could not load inject.js';
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user