Widget:CategoryPages: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 10: Line 10:
         for (const pageIdx in pages) {
         for (const pageIdx in pages) {
           const page = pages[pageIdx];
           const page = pages[pageIdx];
           const pageSpan = document.createElement('span');
           const pageLink = document.createElement('a');
           pageSpan.innerHTML = `<a href="/index.php?curid=${page.pageid}">${page.title}</a>`;
           pageLink.href = `/index.php?curid=${page.pageid}`;
           wrapper.appendChild(pageSpan);
          pageLink.appendChild(document.createTextNode(page.title));
           wrapper.appendChild(pageLink);
         }
         }
       }).catch(function(err) {
       }).catch(function(err) {

Revision as of 00:11, 24 January 2025

 <script type="text/javascript">
   (function() {
     const url = '/api.php?action=query&list=categorymembers&cmtitle=Category:Tools and Equipment in Electronics Area&format=json';
     fetch(url).then(function(response) {
       return response.json();
     }).then(function(data) {
       const wrapper = document.getElementById('categoryPages');
       const pages = data.query.categorymembers;
       for (const pageIdx in pages) {
         const page = pages[pageIdx];
         const pageLink = document.createElement('a');
         pageLink.href = `/index.php?curid=${page.pageid}`;
         pageLink.appendChild(document.createTextNode(page.title));
         wrapper.appendChild(pageLink);
       }
     }).catch(function(err) {
       console.log('Fetch Error :-S', err);
     });
   })();
 </script>