LOLZ Collapse

Удаляет дублирующиеся уведомления

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         LOLZ Collapse
// @namespace    https://lolz.live
// @version      1.0
// @description  Удаляет дублирующиеся уведомления
// @match        https://lolz.live/*
// @grant        none
// ==/UserScript==

(() => {
  'use strict';

  const debounce = (fn, delay = 200) => {
    let t; return (...a) => { clearTimeout(t); t = setTimeout(() => fn(...a), delay); };
  };

  const run = debounce(() => {
    const list = document.querySelector('#AlertsDestinationWrapper ol');
    if (!list) return;

    const buckets = new Map();

    [...list.querySelectorAll('li.Alert')].forEach(li => {
      const isLike = li.querySelector('.alertAction.like2') || /нравится/i.test(li.textContent);
      const type   = isLike ? 'like' : 'reply';

      let key;
      if (isLike) {
        key = li.querySelector('h3 a[href*="posts/"]')?.href?.match(/posts\/(\d+)/)?.[1];
      } else {
        key = li.querySelector('h3 a[data-previewurl]')?.dataset.previewurl?.match(/threads\/(\d+)/)?.[1];
      }
      if (!key) return;

      const bucketKey = `${type}_${key}`;
      (buckets.get(bucketKey) || buckets.set(bucketKey, []).get(bucketKey)).push(li);
    });

    buckets.forEach(group => {
      if (group.length < 2) return;

      const [first, ...rest] = group;
      const others = rest.length;

      rest.forEach(li => li.remove());

      const h3 = first.querySelector('h3');
      if (!h3) return;
      const nickLink = h3.querySelector('a.username');
      if (!nickLink) return;

      if (h3.querySelector('.tm-counter')) return;

      const counter = document.createElement('span');
      counter.className = 'tm-counter';
      counter.textContent = ` (и ещё ${others})`;
      Object.assign(counter.style, {color:'#fff', marginLeft:'4px'});
      nickLink.after(counter);
    });
  });

  run();
  const panel = document.getElementById('AlertPanels');
  if (panel) new MutationObserver(run).observe(panel, {childList: true, subtree: true});
})();