MediaWiki:Common.js

From DefacerID Encyclopedia
Revision as of 05:37, 4 August 2024 by DefacerID (talk | contribs)

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(document).ready(function() {
    $('.cs-comment-form').show();
});


(function() {
    fetch('http://localhost/wikidef/api.php?action=query&list=random&rnnamespace=0&rnlimit=10&format=json')
        .then(response => response.json())
        .then(data => {
            const articles = data.query.random;
            const container = document.getElementById('random-articles');
            container.innerHTML = ''; // Clear the loading text
            
            const pageIds = articles.map(article => article.id).join('|');
            return fetch(`http://localhost/wikidef/api.php?action=query&prop=extracts&pageids=${pageIds}&exintro&format=json`);
        })
        .then(response => response.json())
        .then(data => {
            const container = document.getElementById('random-articles');
            Object.values(data.query.pages).forEach(page => {
                const div = document.createElement('div');
                div.className = 'random-article';
                
                const title = document.createElement('h2');
                const link = document.createElement('a');
                link.href = `http://localhost/wikidef/index.php/${page.title}`;
                link.textContent = page.title;
                title.appendChild(link);
                
                const description = document.createElement('p');
                description.innerHTML = page.extract; // Extracted summary of the article
                
                div.appendChild(title);
                div.appendChild(description);
                
                container.appendChild(div);
            });
        });
})();