LOLZ Collapse

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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});
})();