Onche - Auto-refresh topic

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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