Jump to content

MediaWiki:Common.js: Difference between revisions

 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js');
mw.hook('wikipage.content').add(function () {
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css', 'text/css');
  const el = document.getElementById('article-countdown');
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.css', 'text/css');
  console.log('countdown hook fired; element is:', el);
mw.loader.load('/extensions/JavascriptSlideshow/js/slideshow.js');


  if (!el) return;
  el.textContent = '✅ Countdown JS is running…';


  const apiUrl = mw.util.wikiScript('api') +
    '?action=query&meta=siteinfo&siprop=statistics&format=json&origin=*';


$(document).ready(function() {
  fetch(apiUrl)
    var counter = 1;
    .then(r => r.json())
    .then(d => {
      const current = d.query.statistics.articles;
      const goal = 1000;
      const left = goal - current;


    $('.slideshow').each(function() {
      el.innerHTML = left > 0
        var $this = $(this);
        ? `🚧 Only <strong>${left}</strong> articles to go until 1000!`
        if (!$this.attr('id')) {
        : `🎯 We've reached 1000 articles! Let's Go Boyz and Girlz!`;
            // Assign an auto id if missing
    })
            var newId = 'slideshow-auto-' + (counter++);
    .catch(err => {
            $this.attr('id', newId);
      el.textContent = 'API request failed (see console).';
      console.error(err);
    });
});


            // Add the missing spacer
            if ($('#' + newId + '-spacer').length === 0) {
                $('<div>')
                    .attr('id', newId + '-spacer')
                    .insertAfter($this);
            }


            // Force JavascriptSlideshow to initialize this slideshow
// MediaWiki:Common.js
            startSlideshow(newId);
mw.hook('rcfilters.ui.initialized').add(function () {
        }
  document.documentElement.classList.add('rcfilters-ready');
    });
});
});