Jump to content

MediaWiki:Common.js

From HF Tools Wiki
Revision as of 03:18, 8 May 2026 by HFAdmin (talk | contribs) (Product-grade HF theme upgrade)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
(function () {
  function ready(fn) {
    if (document.readyState !== 'loading') fn();
    else document.addEventListener('DOMContentLoaded', fn);
  }

  ready(function () {
    document.querySelectorAll('.hf-hub-card, .hf-stat-strip div, .hf-timeline a, .hf-review-card').forEach(function (el) {
      el.classList.add('hf-reveal');
    });

    var observer = new IntersectionObserver(function (entries) {
      entries.forEach(function (entry) {
        if (entry.isIntersecting) {
          entry.target.classList.add('is-visible');
          observer.unobserve(entry.target);
        }
      });
    }, { threshold: 0.16 });

    document.querySelectorAll('.hf-reveal').forEach(function (el) {
      observer.observe(el);
    });

    document.querySelectorAll('[data-hf-count]').forEach(function (el) {
      var target = parseInt(el.getAttribute('data-hf-count'), 10);
      var start = performance.now();
      function tick(now) {
        var progress = Math.min(1, (now - start) / 900);
        var eased = 1 - Math.pow(1 - progress, 3);
        el.textContent = Math.round(target * eased).toLocaleString() + (target > 100 ? '+' : '');
        if (progress < 1) requestAnimationFrame(tick);
      }
      requestAnimationFrame(tick);
    });

    var search = document.getElementById('hfHubSearch');
    var cards = Array.prototype.slice.call(document.querySelectorAll('.hf-hub-card'));
    if (search && cards.length) {
      search.addEventListener('input', function () {
        var q = search.value.trim().toLowerCase();
        cards.forEach(function (card) {
          var text = (card.textContent + ' ' + (card.getAttribute('data-hf-filter') || '')).toLowerCase();
          card.classList.toggle('hf-is-hidden', q && text.indexOf(q) === -1);
        });
      });
    }
  });
})();