User script (written with GPT) for Tampermonkey or similar extensions.
It restores old cams, allows you to change their position, and adjust their size in all rooms, regardless of room settings.

Alt Tag

Script updated: usernames on cameras should now display correctly.

  1. Install Tampermonkey ( Chrome Firefox ) or a similar userscript manager
  2. For Chrome-based browsers: you must enable the Allow User Scripts option — see instructions www.tampermonkey.net/faq.php?locale=en#Q209. Firefox users can skip this and continue to the next step.
  3. Open the Tampermonkey extension panel (icon in the browser toolbar) → "Create a new script" / "New script".
  4. Remove all text in the editor and paste the userscript code (below).
  5. Save the script in Tampermonkey: click "File" (top left) → "Save".
  6. Reload the Kosmi page — the script should start working

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
// ==UserScript==
// @name         movable webcams improved (square edge-resize)
// @namespace    https://kosmi.io/
// @version      6.9
// @description  Draggable & resizable square small webcams on app.kosmi.io — enclosure has border/shadow and fixed 64px radius
// @match        https://app.kosmi.io/*
// @grant        none
// ==/UserScript==

(function () {
'use strict';

const THRESH_W = 800, THRESH_H = 800;
const MIN_SIDE = 80;
const Z = 999999;
const DRAG_START_THRESHOLD = 8;
const EDGE_THICKNESS = 20;
const showHandle = false;

function findParticipantWrapper(video) {
  let p = video;
  for (let i = 0; i < 6 && p; i++) {
    p = p.parentElement;
    if (!p) break;
    try {
      const hasTextDiv = Array.from(p.querySelectorAll('div')).some(d=>{
        const t = d.textContent?.trim();
        return t && t.length <= 40 && /[^\s]/.test(t);
      });
      if (hasTextDiv) return p;
    } catch (e) {}
  }
  return null;
}

function makeInteractive(video, origWrapper) {
  if (!video) return;
  if (video.dataset.kosmiInteractive) return;
  if (!origWrapper) origWrapper = findParticipantWrapper(video) || video.parentElement;
  if (!origWrapper) return;

  const rect = video.getBoundingClientRect();
  if (rect.width < 40 || rect.height < 40) return;

  // Extract username BEFORE replacing/hiding the wrapper
  let username = 'User';
  try {
    const textDiv = Array.from(origWrapper.querySelectorAll('div')).find(d=>{
      const t = d.textContent?.trim();
      return t && t.length <= 40 && /[^\s]/.test(t);
    });
    if (textDiv && textDiv.textContent?.trim()) username = textDiv.textContent.trim();

    if ((!username || username === 'User') && video.dataset && video.dataset.username) username = video.dataset.username.trim();
    if ((!username || username === 'User') && (video.getAttribute('aria-label') || video.title)) {
      username = (video.getAttribute('aria-label') || video.title).trim();
    }

    if ((!username || username === 'User')) {
      const texts = Array.from(origWrapper.querySelectorAll('*')).map(n => n.textContent?.trim()).filter(Boolean);
      if (texts.length) username = texts.find(t => t.length <= 40) || texts[0];
    }
  } catch (e) {}
  video.dataset.kosmiName = username;

  // Placeholder to restore later
  const placeholder = document.createElement('div');
  const initialSide = Math.max(rect.width, rect.height);
  Object.assign(placeholder.style, {
    width: initialSide + 'px',
    height: initialSide + 'px',
    display: getComputedStyle(origWrapper).display === 'inline' ? 'inline-block' : getComputedStyle(origWrapper).display
  });
  const nextSibling = video.nextSibling;
  try { origWrapper.replaceChild(placeholder, video); } catch (e) { return; }

  placeholder._origParent = origWrapper;
  placeholder._origNext = nextSibling;
  placeholder._origNode = video;

  // Container (square)
  const container = document.createElement('div');
  Object.assign(container.style, {
    position: 'fixed',
    left: rect.left + 'px',
    top: rect.top + 'px',
    width: initialSide + 'px',
    height: initialSide + 'px',
    zIndex: String(Z),
    boxSizing: 'border-box',
    overflow: 'hidden',
    background: 'transparent',
    touchAction: 'none',
    pointerEvents: 'auto',
    border: '2px solid rgba(255, 255, 255, 0.2)',
    boxShadow: '0 4px 12px rgba(0, 0, 0, 0.35)',
    borderRadius: '24px',
    cursor: 'default'
  });
  container.className = 'kosmi-move-container';
  container.appendChild(video);
  document.body.appendChild(container);

  // Video fills container
  Object.assign(video.style, {
    width: '100%',
    height: '100%',
    objectFit: 'cover',
    display: 'block',
    pointerEvents: 'auto',
    userSelect: 'none',
    '-webkit-user-drag': 'none',
    border: 'none',
    boxShadow: 'none',
    outline: 'none',
    borderRadius: '0'
  });

  // Hide original wrapper
  try {
    Object.assign(origWrapper.style, {
      display: 'none',
      visibility: 'hidden',
      pointerEvents: 'none'
    });
  } catch (e) {}

  // Username badge (use saved name)
  const nameLayer = document.createElement('div');
  Object.assign(nameLayer.style, {
    position: 'absolute',
    bottom: '1%',
    left: '0',
    right: '0',
    textAlign: 'center',
    pointerEvents: 'none',
    zIndex: '12'
  });
  const badge = document.createElement('span');
  Object.assign(badge.style, {
    background: 'rgba(0,0,0,0.7)',
    color: '#fff',
    padding: '0.35em 0.85em',
    borderRadius: '6px',
    fontSize: 'clamp(12.8rem, 2.8vw, 1.1rem)',
    fontWeight: '500',
    whiteSpace: 'nowrap',
    overflow: 'hidden',
    textOverflow: 'ellipsis',
    maxWidth: '88%',
    display: 'inline-block',
    boxShadow: '0 2px 6px rgba(0,0,0,0.6)'
  });
  badge.textContent = video.dataset.kosmiName || 'User';
  nameLayer.appendChild(badge);
  container.appendChild(nameLayer);

  // optional small handle
  let handle = null;
  if (showHandle) {
    handle = document.createElement('div');
    Object.assign(handle.style, {
      position: 'absolute',
      right: '6px',
      top: '6px',
      width: '18px',
      height: '18px',
      background: 'rgba(0,0,0,0.55)',
      borderRadius: '4px',
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      color: '#fff',
      fontSize: '12px',
      cursor: 'move',
      zIndex: 2
    });
    handle.textContent = '⇅';
    container.appendChild(handle);
  }

  // ─── Drag ────────────────────────────────────────────────────────
  let dragId = null, dragStart = null, isDragging = false;
  function startDrag(e) {
    if (e.button !== 0) return;
    dragId = e.pointerId;
    dragStart = {
      x: e.clientX, y: e.clientY,
      l: parseFloat(container.style.left), t: parseFloat(container.style.top)
    };
    try { container.setPointerCapture(dragId); } catch {}
    container.addEventListener('pointermove', moveDrag);
    container.addEventListener('pointerup', endDrag);
    container.addEventListener('pointercancel', endDrag);
    e.preventDefault();
  }
  function moveDrag(e) {
    if (e.pointerId !== dragId) return;
    const dx = e.clientX - dragStart.x, dy = e.clientY - dragStart.y;
    if (!isDragging) {
      if (Math.hypot(dx, dy) >= DRAG_START_THRESHOLD) {
        isDragging = true;
        video.style.pointerEvents = 'none';
      } else return;
    }
    container.style.left = (dragStart.l + dx) + 'px';
    container.style.top = (dragStart.t + dy) + 'px';
  }
  function endDrag(e) {
    if (e.pointerId !== dragId) return;
    isDragging = false;
    video.style.pointerEvents = 'auto';
    if (dragId !== null) try { container.releasePointerCapture(dragId); } catch {}
    dragId = null;
    container.removeEventListener('pointermove', moveDrag);
    container.removeEventListener('pointerup', endDrag);
    container.removeEventListener('pointercancel', endDrag);
  }

  if (showHandle && handle) handle.addEventListener('pointerdown', startDrag);
  else {
    container.addEventListener('pointerdown', function (e) {
      const r = container.getBoundingClientRect();
      const ex = e.clientX - r.left, ey = e.clientY - r.top;
      if (ex < EDGE_THICKNESS || ex > r.width - EDGE_THICKNESS || ey < EDGE_THICKNESS || ey > r.height - EDGE_THICKNESS) {
        return;
      }
      startDrag(e);
    });
  }

  // ─── Resize по краям ─────────────────────────────────────────────
  let resId = null, resStart = null, isResizing = false;
  let dirs = { l: false, r: false, t: false, b: false };

  function inResizeZone(x, y, w, h) {
    return x < EDGE_THICKNESS || x > w - EDGE_THICKNESS || y < EDGE_THICKNESS || y > h - EDGE_THICKNESS;
  }

  container.addEventListener('pointermove', e => {
    const r = container.getBoundingClientRect();
    const ex = e.clientX - r.left;
    const ey = e.clientY - r.top;

    if (inResizeZone(ex, ey, r.width, r.height)) {
      const l = ex < EDGE_THICKNESS;
      const ri = ex > r.width - EDGE_THICKNESS;
      const tp = ey < EDGE_THICKNESS;
      const bt = ey > r.height - EDGE_THICKNESS;

      container.style.cursor =
        (l && tp || ri && bt) ? 'nwse-resize' :
        (ri && tp || l && bt) ? 'nesw-resize' :
        (l || ri) ? 'ew-resize' :
        (tp || bt) ? 'ns-resize' : 'default';
    } else {
      container.style.cursor = 'default';
    }
  });

  container.addEventListener('pointerdown', e => {
    const r = container.getBoundingClientRect();
    const ex = e.clientX - r.left;
    const ey = e.clientY - r.top;

    const l = ex < EDGE_THICKNESS;
    const ri = ex > r.width - EDGE_THICKNESS;
    const tp = ey < EDGE_THICKNESS;
    const bt = ey > r.height - EDGE_THICKNESS;

    if (!(l || ri || tp || bt)) return;

    e.stopPropagation();
    isResizing = true;
    resId = e.pointerId;
    dirs = { l, r: ri, t: tp, b: bt };
    resStart = {
      x: e.clientX, y: e.clientY,
      l: parseFloat(container.style.left),
      t: parseFloat(container.style.top),
      side: container.clientWidth
    };
    try { container.setPointerCapture(resId); } catch {}
    container.addEventListener('pointermove', resizeMove);
    container.addEventListener('pointerup', resizeEnd);
    container.addEventListener('pointercancel', resizeEnd);
  });

  function resizeMove(e) {
    if (!isResizing || e.pointerId !== resId) return;

    let delta = 0;
    const dx = e.clientX - resStart.x;
    const dy = e.clientY - resStart.y;

    if (dirs.r) delta = dx;
    else if (dirs.l) delta = -dx;
    else if (dirs.b) delta = dy;
    else if (dirs.t) delta = -dy;

    let newSide = Math.round(resStart.side + delta);
    if (newSide < MIN_SIDE) newSide = MIN_SIDE;

    let nl = resStart.l;
    let nt = resStart.t;
    if (dirs.l) nl = resStart.l - (newSide - resStart.side);
    if (dirs.t) nt = resStart.t - (newSide - resStart.side);

    container.style.width = newSide + 'px';
    container.style.height = newSide + 'px';
    container.style.left = nl + 'px';
    container.style.top = nt + 'px';
    container.style.borderRadius = '24px';
  }

  function resizeEnd(e) {
    if (e.pointerId !== resId) return;
    isResizing = false;
    if (resId !== null) try { container.releasePointerCapture(resId); } catch {}
    resId = null;
    container.removeEventListener('pointermove', resizeMove);
    container.removeEventListener('pointerup', resizeEnd);
    container.removeEventListener('pointercancel', resizeEnd);
    container.style.cursor = 'default';
  }

  try {
    new ResizeObserver(() => {
      const w = container.clientWidth;
      const h = container.clientHeight;
      if (Math.abs(w - h) > 2) {
        const s = Math.max(MIN_SIDE, Math.round((w + h) / 2));
        container.style.width = s + 'px';
        container.style.height = s + 'px';
        container.style.borderRadius = '24px';
      }
    }).observe(container);
  } catch (e) {}

  // ─── Cleanup при остановке стрима ────────────────────────────────
  function cleanup() {
    if (!placeholder._origNode) return;
    try {
      video.srcObject?.getTracks?.().forEach(t => { try{ t.stop(); }catch{} });
    } catch (e) {}
    try { video.remove(); } catch (e) {}
    try { container.remove(); } catch (e) {}
    try {
      const p = placeholder._origParent;
      const n = placeholder._origNext;
      if (n?.parentElement === p) p.insertBefore(placeholder, n);
      else p.appendChild(placeholder);
      placeholder._origNode = null;
    } catch (e) {}
  }

  function isLive() {
    try {
      if (video.srcObject) {
        const ts = video.srcObject.getTracks();
        return ts.length > 0 && ts.some(t => t.readyState === 'live' || t.enabled);
      }
      return video.readyState >= 2 && !video.paused;
    } catch { return false; }
  }

  video.addEventListener('emptied', () => !isLive() && cleanup());
  video.addEventListener('pause', () => !isLive() && cleanup());
  video.addEventListener('abort', () => !isLive() && cleanup());
  video.addEventListener('error', () => !isLive() && cleanup());

  const checkInterval = setInterval(() => {
    if (!document.body.contains(container)) {
      clearInterval(checkInterval);
      return;
    }
    if (!isLive()) {
      clearInterval(checkInterval);
      setTimeout(cleanup, 50);
    }
  }, 1000);

  const mo = new MutationObserver(() => {
    if (!document.body.contains(container)) {
      clearInterval(checkInterval);
      mo.disconnect();
    }
  });
  mo.observe(document.body, { childList: true, subtree: true });

  video.dataset.kosmiInteractive = '1';
}

function scan() {
  const vids = Array.from(document.querySelectorAll('video'));
  vids.forEach(v => {
    if (v.dataset.kosmiInteractive) return;
    const r = v.getBoundingClientRect();
    if (r.width >= THRESH_W || r.height >= THRESH_H) return;
    const wrapper = findParticipantWrapper(v);
    if (!wrapper) return;
    makeInteractive(v, wrapper);
  });
}

// safe start
function startScanSafely(){
  setTimeout(scan, 500);
  new MutationObserver(scan).observe(document.body, { childList:true, subtree:true });
}
if (document.readyState === 'complete' || document.readyState === 'interactive') startScanSafely();
else window.addEventListener('DOMContentLoaded', startScanSafely);

})();
Edit

Pub: 09 Jan 2026 06:10 UTC

Edit: 14 Mar 2026 19:46 UTC

Views: 523