Pipeline code copied into app/; llama.py now uses launcher-local llama.cpp (app/bin) and Qwen GGUF (app/models) instead of LM Studio. install.js fetches ffmpeg, 7zip, llama.cpp CUDA 13, sherpa-onnx diarization models, bge-m3 and Qwen3.6-35B-A3B, then pre-builds the uv script environments. start.js serves the GUI on fixed port 18765 (hardcoded in the browser extension). reset.js keeps app/out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
4.8 KiB
JavaScript
109 lines
4.8 KiB
JavaScript
// Content script on Teams web: logs active speaker, shares, captions, chat, hands, presence while recording.
|
|
// Events go via the offscreen document (it has host_permissions for 127.0.0.1). Never clicks or types in the call.
|
|
const SEL = {
|
|
duration: '[data-tid="call-duration"]',
|
|
nametag: '[data-tid="participant-info-nametag"]',
|
|
info: '[data-tid="participant-info"]',
|
|
speaking: '[data-tid="voice-level-stream-outline"][data-is-speaking="true"]',
|
|
self: '[data-tid="myself-video"]',
|
|
shareAria: /^(Contenuto condiviso da|Content shared by) (.+)$/,
|
|
caption: null, captionAuthor: null, captionText: null, // discovery step (see plan 3b)
|
|
chatMsg: null, chatAuthor: null, chatText: null, // discovery step
|
|
hand: null, // discovery step
|
|
};
|
|
|
|
let buf = [], timers = [], seenCap = new WeakSet(), seenChat = new WeakSet(), lastShare = "", raised = new Set(), lastTitle = null;
|
|
|
|
const norm = raw => {
|
|
raw = (raw || "").trim();
|
|
const m = raw.match(/^([^,]+),\s*([^(]+?)\s*(\(.*)?$/);
|
|
if (!m) return raw;
|
|
return `${m[2]} ${m[1]}`.split(/\s+/).map(w => (w.length > 1 && w === w.toUpperCase() ? w[0] + w.slice(1).toLowerCase() : w)).join(" ");
|
|
};
|
|
const tileOf = el => { while (el && !el.querySelector(SEL.nametag)) el = el.parentElement; return el; };
|
|
const keyOf = tile => {
|
|
for (let e = tile; e; e = e.parentElement) if ((e.dataset?.tid || "").includes("@")) return e.dataset.tid;
|
|
return tile.querySelector(SEL.nametag)?.textContent.trim() || "";
|
|
};
|
|
const nameOf = tile => norm(tile.querySelector(SEL.nametag)?.textContent);
|
|
const selfName = () => { const s = document.querySelector(SEL.self); return s ? nameOf(s) : ""; };
|
|
const emit = (kind, who_key = "", who = "", text = "") => buf.push({ ts: Date.now(), kind, who_key, who, text });
|
|
const guard = f => () => { try { f(); } catch { } };
|
|
const send = () => { if (buf.length) chrome.runtime.sendMessage({ to: "off", cmd: "events", events: buf.splice(0) }).catch(() => { }); };
|
|
const tiles = () => [...document.querySelectorAll(SEL.nametag)].map(tileOf).filter(Boolean);
|
|
|
|
function meta() {
|
|
const title = document.title.replace(/^[^|]*\|\s*/, "").replace(/\s*\|\s*Microsoft Teams$/, "");
|
|
if (title === lastTitle) return;
|
|
lastTitle = title;
|
|
emit("meta", "", "", JSON.stringify({ title, call_elapsed: document.querySelector(SEL.duration)?.textContent.trim() || "", url: location.href }));
|
|
}
|
|
function present() {
|
|
const seen = new Map();
|
|
for (const t of tiles()) seen.set(keyOf(t), { key: keyOf(t), who: t.closest(SEL.self) ? selfName() : nameOf(t) });
|
|
emit("present", "", "", JSON.stringify([...seen.values()]));
|
|
}
|
|
function active() {
|
|
for (const el of document.querySelectorAll(SEL.speaking)) {
|
|
const t = tileOf(el); if (!t) continue;
|
|
if (t.closest(SEL.self) || t.matches(SEL.self)) emit("active", "self", selfName());
|
|
else emit("active", keyOf(t), nameOf(t));
|
|
}
|
|
}
|
|
function share() {
|
|
const names = tiles().map(nameOf);
|
|
let cur = "";
|
|
for (const el of document.querySelectorAll("[aria-label]")) {
|
|
const m = el.getAttribute("aria-label").match(SEL.shareAria);
|
|
if (m) { cur = names.find(n => n && m[2].startsWith(n)) || m[2]; break; }
|
|
}
|
|
if (cur === lastShare) return;
|
|
if (lastShare) emit("share_stop", "", lastShare);
|
|
if (cur) emit("share_start", "", cur);
|
|
lastShare = cur;
|
|
}
|
|
function messages() {
|
|
if (SEL.caption) for (const el of document.querySelectorAll(SEL.caption)) {
|
|
if (seenCap.has(el)) continue; seenCap.add(el);
|
|
const text = el.querySelector(SEL.captionText)?.textContent.trim();
|
|
if (text) emit("caption", "", norm(el.querySelector(SEL.captionAuthor)?.textContent), text);
|
|
}
|
|
if (SEL.chatMsg) for (const el of document.querySelectorAll(SEL.chatMsg)) {
|
|
if (seenChat.has(el)) continue; seenChat.add(el);
|
|
const text = el.querySelector(SEL.chatText)?.textContent.trim();
|
|
if (text) emit("chat", "", norm(el.querySelector(SEL.chatAuthor)?.textContent), text);
|
|
}
|
|
if (SEL.hand) {
|
|
const now = new Set();
|
|
for (const el of document.querySelectorAll(SEL.hand)) {
|
|
const t = tileOf(el); if (!t) continue;
|
|
const k = keyOf(t); now.add(k);
|
|
if (!raised.has(k)) emit("hand", k, nameOf(t));
|
|
}
|
|
raised = now;
|
|
}
|
|
}
|
|
|
|
function stop() {
|
|
timers.forEach(clearInterval); timers = [];
|
|
send();
|
|
if (lastShare) { emit("share_stop", "", lastShare); lastShare = ""; }
|
|
send();
|
|
}
|
|
function start() {
|
|
stop();
|
|
buf = []; seenCap = new WeakSet(); seenChat = new WeakSet(); raised = new Set(); lastTitle = null; lastShare = "";
|
|
meta(); present();
|
|
timers = [
|
|
setInterval(guard(() => { meta(); active(); }), 500),
|
|
setInterval(guard(() => { share(); messages(); }), 1000),
|
|
setInterval(guard(present), 30000),
|
|
setInterval(guard(send), 5000),
|
|
];
|
|
}
|
|
|
|
chrome.runtime.onMessage.addListener(m => {
|
|
if (m.cmd === "cap-start") start();
|
|
if (m.cmd === "cap-stop") stop();
|
|
});
|