MediaWiki:Common.js: Difference between revisions

From DefacerID Encyclopedia
No edit summary
No edit summary
Line 5: Line 5:


(function() {
(function() {
  fetch('http://localhost/wikidef/api.php?action=query&list=random&rnnamespace=0&rnlimit=10&format=json')
    fetch('http://localhost/wikidef/api.php?action=query&list=random&rnnamespace=0&rnlimit=10&format=json')
    .then(response => response.json())
        .then(response => response.json())
    .then(data => {
        .then(data => {
      const articles = data.query.random;
            const articles = data.query.random;
      const list = document.createElement('ul');
            const container = document.getElementById('random-articles');
      articles.forEach(article => {
            container.innerHTML = ''; // Clear the loading text
        const item = document.createElement('li');
           
        const link = document.createElement('a');
            articles.forEach(article => {
        link.href = `http://localhost/wikidef/${article.title}`;
                const div = document.createElement('div');
        link.textContent = article.title;
                div.className = 'random-article';
        item.appendChild(link);
               
        list.appendChild(item);
                const title = document.createElement('h2');
      });
                const link = document.createElement('a');
      document.getElementById('random-articles').innerHTML = "";
                link.href = `http://localhost/wikidef/wiki/${article.title}`;
      document.getElementById('random-articles').appendChild(list);
                link.textContent = article.title;
    });
                title.appendChild(link);
               
                const description = document.createElement('p');
                description.textContent = 'Short description or extract of the article'; // Add your logic for description here
               
                div.appendChild(title);
                div.appendChild(description);
               
                container.appendChild(div);
            });
        });
})();
})();

Revision as of 05:33, 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
            
            articles.forEach(article => {
                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/${article.title}`;
                link.textContent = article.title;
                title.appendChild(link);
                
                const description = document.createElement('p');
                description.textContent = 'Short description or extract of the article'; // Add your logic for description here
                
                div.appendChild(title);
                div.appendChild(description);
                
                container.appendChild(div);
            });
        });
})();