Auto speaker count from roster, one-to-one speaker map, clean LLM junk, merge recordings, Teams caption scraping
This commit is contained in:
+12
-8
@@ -7,12 +7,12 @@ const SEL = {
|
||||
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)
|
||||
caption: '[data-tid="author"],[data-tid="closed-caption-text"]', // DOM order; author only on first row of a speaker's run
|
||||
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;
|
||||
let buf = [], timers = [], seenCap = new WeakMap(), capAuthor = "", seenChat = new WeakSet(), lastShare = "", raised = new Set(), lastTitle = null;
|
||||
|
||||
const norm = raw => {
|
||||
raw = (raw || "").trim();
|
||||
@@ -28,7 +28,7 @@ const keyOf = tile => {
|
||||
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 guard = f => () => { try { f(); } catch (e) { console.error("[teams-whisper]", e); } };
|
||||
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);
|
||||
|
||||
@@ -64,9 +64,12 @@ function share() {
|
||||
}
|
||||
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 (el.getAttribute("data-tid") === "author") { capAuthor = norm(el.textContent); continue; }
|
||||
// caption text grows while spoken: emit once it was unchanged for a full tick
|
||||
const text = el.textContent.trim(), s = seenCap.get(el) || {};
|
||||
if (s.done) continue;
|
||||
if (text && s.text === text) { s.done = true; emit("caption", "", capAuthor, text); }
|
||||
s.text = text; seenCap.set(el, s);
|
||||
}
|
||||
if (SEL.chatMsg) for (const el of document.querySelectorAll(SEL.chatMsg)) {
|
||||
if (seenChat.has(el)) continue; seenChat.add(el);
|
||||
@@ -92,11 +95,12 @@ function stop() {
|
||||
}
|
||||
function start() {
|
||||
stop();
|
||||
buf = []; seenCap = new WeakSet(); seenChat = new WeakSet(); raised = new Set(); lastTitle = null; lastShare = "";
|
||||
buf = []; seenCap = new WeakMap(); capAuthor = ""; seenChat = new WeakSet(); raised = new Set(); lastTitle = null; lastShare = "";
|
||||
meta(); present();
|
||||
timers = [
|
||||
setInterval(guard(() => { meta(); active(); }), 500),
|
||||
setInterval(guard(() => { share(); messages(); }), 1000),
|
||||
setInterval(guard(share), 1000),
|
||||
setInterval(guard(messages), 1000),
|
||||
setInterval(guard(present), 30000),
|
||||
setInterval(guard(send), 5000),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user