Onche - Auto-refresh topic

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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