Onche - Auto-refresh topic

Clique automatiquement sur la barre "Nouveaux messages" d'Onche

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Onche - Auto-refresh topic
// @namespace    onche.autorefresh
// @version      2.0
// @description  Clique automatiquement sur la barre "Nouveaux messages" d'Onche
// @match        https://onche.org/topic/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
  'use strict';

  const INTERVAL = 3000; // vérifie toutes les 3s si la barre est apparue

  let paused = false;

  // --- Indicateur de statut ---
  const badge = document.createElement('div');
  badge.style.cssText =
    'position:fixed;bottom:16px;right:16px;z-index:9999;padding:8px 12px;' +
    'border-radius:8px;font:13px Inter,sans-serif;background:#1b6ec2;color:#fff;' +
    'cursor:pointer;box-shadow:0 2px 8px rgba(0,0,0,.4);user-select:none;';
  badge.textContent = '⟳ Auto ON';
  badge.title = 'Cliquer pour mettre en pause / reprendre';
  badge.addEventListener('click', () => {
    paused = !paused;
    badge.textContent = paused ? '⏸ Auto OFF' : '⟳ Auto ON';
    badge.style.background = paused ? '#555' : '#1b6ec2';
  });
  document.body.appendChild(badge);

  function clickNewMessages() {
    if (paused || document.hidden) return;

    // L'indicateur de nouveaux messages d'Onche
    const indicator = document.querySelector('#new-messages-indicator');
    if (!indicator) return;

    // Visible seulement quand il y a du nouveau
    const visible =
      !indicator.classList.contains('indicator-hidden') &&
      indicator.offsetParent !== null &&
      indicator.textContent.trim().length > 0;

    if (visible) {
      // On clique sur l'élément cliquable à l'intérieur (ou l'indicateur lui-même)
      const target =
        indicator.querySelector('a, button, [class*="clickable"], div') ||
        indicator;
      target.click();

      badge.textContent = '↻ Chargé';
      badge.style.background = '#2e9e4f';
      setTimeout(() => {
        if (!paused) {
          badge.textContent = '⟳ Auto ON';
          badge.style.background = '#1b6ec2';
        }
      }, 2000);
    }
  }

  setInterval(clickNewMessages, INTERVAL);
})();