MediaWiki:Common.js: Difference between revisions

From DefacerID Encyclopedia
No edit summary
No edit summary
Line 12: Line 12:
             container.innerHTML = ''; // Clear the loading text
             container.innerHTML = ''; // Clear the loading text
              
              
             articles.forEach(article => {
             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');
                 const div = document.createElement('div');
                 div.className = 'random-article';
                 div.className = 'random-article';
Line 18: Line 24:
                 const title = document.createElement('h2');
                 const title = document.createElement('h2');
                 const link = document.createElement('a');
                 const link = document.createElement('a');
                 link.href = `http://localhost/wikidef/wiki/${article.title}`;
                 link.href = `http://localhost/wikidef/wiki/${page.title}`;
                 link.textContent = article.title;
                 link.textContent = page.title;
                 title.appendChild(link);
                 title.appendChild(link);
                  
                  
                 const description = document.createElement('p');
                 const description = document.createElement('p');
                 description.textContent = 'Short description or extract of the article'; // Add your logic for description here
                 description.innerHTML = page.extract; // Extracted summary of the article
                  
                  
                 div.appendChild(title);
                 div.appendChild(title);

Revision as of 05:35, 4 August 2024

$(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/wiki/${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);
            });
        });
})();