PTW_* keywords match only in the Feature cell. Modules 19 and 9 match only when Product contains PTW70 (e.g. 1 PTW70) and Feature is exactly 19 or 9. Rebuild distributables. Co-authored-by: Cursor <cursoragent@cursor.com>
94 lines
3.8 KiB
JavaScript
94 lines
3.8 KiB
JavaScript
// Injected into the webview (sessions page). Runs in that page's context.
|
|
(function () {
|
|
'use strict';
|
|
|
|
const TARGET_KEYWORDS = [
|
|
'PTW_DATAEXCHANGE', 'PTW_ARC_FLASH', 'PTW_DEVEVAL', 'PTW_AFAULT',
|
|
'PTW_DAPPER', 'PTW_COOREVAL', 'PTW_CAPTOR', 'PTW_IEC_FAULT', 'PTW_IEC61363'
|
|
];
|
|
|
|
/** Exact match on Feature cell only; Product must look like PTW70 (e.g. "1 PTW70") so "9"/"19" do not fire on other lines. */
|
|
const TARGET_FEATURE_IDS = ['19', '9'];
|
|
|
|
window.__ptw_logQueue = window.__ptw_logQueue || [];
|
|
window.__ptw_running = window.__ptw_running !== false;
|
|
|
|
function addLog(msg) {
|
|
const t = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
window.__ptw_logQueue.push(`[${t}] ${msg}`);
|
|
}
|
|
|
|
function productFeatureCells(row) {
|
|
var cells = row.querySelectorAll('td');
|
|
if (cells.length < 5) return { product: '', feature: '' };
|
|
var product = (cells[3] && cells[3].innerText) ? cells[3].innerText.replace(/\s+/g, ' ').trim() : '';
|
|
var feature = (cells[4] && cells[4].innerText) ? cells[4].innerText.replace(/\s+/g, ' ').trim() : '';
|
|
return { product: product, feature: feature };
|
|
}
|
|
|
|
function isPtw70Product(product) {
|
|
return product.indexOf('PTW70') !== -1;
|
|
}
|
|
|
|
function matchesKeywordInFeature(feature) {
|
|
return TARGET_KEYWORDS.some(function (k) { return feature.indexOf(k) !== -1; });
|
|
}
|
|
|
|
function matchesFeatureId(product, feature) {
|
|
if (!isPtw70Product(product)) return false;
|
|
return TARGET_FEATURE_IDS.some(function (id) { return feature === id; });
|
|
}
|
|
|
|
function scanAndDisconnect() {
|
|
if (!window.__ptw_running) return;
|
|
const rows = document.querySelectorAll('#mydata table.list tr');
|
|
rows.forEach(function (row) {
|
|
const rowText = row.innerText;
|
|
var pf = productFeatureCells(row);
|
|
const keywordMatch = matchesKeywordInFeature(pf.feature);
|
|
const idMatch = matchesFeatureId(pf.product, pf.feature);
|
|
if (keywordMatch || idMatch) {
|
|
const disconnectLink = row.querySelector('a.sbutton');
|
|
if (disconnectLink && disconnectLink.textContent.indexOf('Disconnect') !== -1) {
|
|
const itemName = (rowText.split('\t')[0] || '').trim() || 'Item';
|
|
addLog('OUT: ' + itemName);
|
|
disconnectLink.click();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
window.__ptw_flushLogs = function () {
|
|
const q = window.__ptw_logQueue.slice();
|
|
window.__ptw_logQueue = [];
|
|
return q;
|
|
};
|
|
|
|
window.__ptw_setRunning = function (v) { window.__ptw_running = !!v; };
|
|
window.__ptw_getRunning = function () { return window.__ptw_running; };
|
|
|
|
/** Returns list of { user, product, feature, machine, loginTime } from #mydata table.list */
|
|
window.__ptw_getSessions = function () {
|
|
var out = [];
|
|
var rows = document.querySelectorAll('#mydata table.list tr');
|
|
for (var i = 0; i < rows.length; i++) {
|
|
if (rows[i].classList && rows[i].classList.contains('tableheader')) continue;
|
|
var cells = rows[i].querySelectorAll('td');
|
|
if (cells.length < 9) continue;
|
|
var product = (cells[3] && cells[3].innerText) ? cells[3].innerText.replace(/\s+/g, ' ').trim() : '';
|
|
var feature = (cells[4] && cells[4].innerText) ? cells[4].innerText.replace(/\s+/g, ' ').trim() : '';
|
|
var user = (cells[6] && cells[6].innerText) ? cells[6].innerText.trim() : '';
|
|
var machine = (cells[7] && cells[7].innerText) ? cells[7].innerText.trim() : '';
|
|
var loginTime = (cells[8] && cells[8].innerText) ? cells[8].innerText.trim() : '';
|
|
out.push({ user: user, product: product, feature: feature, machine: machine, loginTime: loginTime });
|
|
}
|
|
return out;
|
|
};
|
|
|
|
var targetNode = document.getElementById('mydata') || document.body;
|
|
var observer = new MutationObserver(function () { scanAndDisconnect(); });
|
|
observer.observe(targetNode, { childList: true, subtree: true });
|
|
addLog('Refreshed');
|
|
scanAndDisconnect();
|
|
})();
|