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 για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         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);
})();