Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion plugins/LastSeen/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,11 @@
function updBlk(b, id) {
const data = lines(id);
if (!data) return b.remove();
const signature = JSON.stringify(data);
if (b.dataset.slickLs === id && b.dataset.slickLsSignature === signature) return;
b.textContent = '';
b.dataset.slickLs = id;
b.dataset.slickLsSignature = signature;
for (const ln of data) {
const line = document.createElement('span');
line.className = 'slick-ls-line';
Expand Down Expand Up @@ -571,7 +574,13 @@
if (!document.body) return setTimeout(boot, 200);
patchWS();
pall();
new MutationObserver(sched).observe(document.body, { subtree: true, childList: true });
new MutationObserver((mutations) => {
const external = mutations.some((mutation) => {
const target = mutation.target;
return target.nodeType !== Node.ELEMENT_NODE || !target.closest('[data-slick-ls]');
});
if (external) sched();
}).observe(document.body, { subtree: true, childList: true });
addEventListener('slick:plugin-settings', sched);
addEventListener('storage', (e) => {
if (e.key === 'slick:lastseen:cache') {
Expand Down
34 changes: 29 additions & 5 deletions plugins/UserPronouns/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
if (window.__slickPronouns) return;

const ID_RE = /^[UW][A-Z0-9]{6,}$/;
const ROW_SEL = '.c-message_kit__message, .c-message, [data-qa="message_container"], [role="listitem"]';

let cache = loadCache();
let dirty = false;
Expand Down Expand Up @@ -215,7 +216,7 @@
}

function paint(ts) {
const row = ts.closest('.c-message_kit__message, .c-message, [data-qa="message_container"], [role="listitem"]');
const row = ts.closest(ROW_SEL);
const sender =
row &&
row.querySelector(
Expand Down Expand Up @@ -251,10 +252,23 @@
}
}

function paintWithin(root) {
const timestamps = [];
if (root.nodeType === Node.ELEMENT_NODE && root.matches('.c-timestamp')) timestamps.push(root);
if (root.querySelectorAll) timestamps.push(...root.querySelectorAll('.c-timestamp'));
const rows = new Set();
timestamps.forEach((timestamp) => {
const row = timestamp.closest(ROW_SEL);
if (!row || rows.has(row)) return;
rows.add(row);
paint(timestamp);
});
if (dirty) saveCache();
}

function paintAll() {
syncColor();
document.querySelectorAll('.c-timestamp').forEach(paint);
if (dirty) saveCache();
paintWithin(document);
}

window.__slickPronouns = {
Expand All @@ -263,11 +277,21 @@
};

let t = null;
const obs = new MutationObserver(() => {
const pendingRoots = new Set();
const obs = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) pendingRoots.add(node);
});
});
if (!pendingRoots.size) return;
if (t) return;
t = setTimeout(() => {
t = null;
paintAll();
const roots = [...pendingRoots];
pendingRoots.clear();
syncColor();
roots.forEach(paintWithin);
}, 200);
});
function boot() {
Expand Down