Widget:CategoryPages: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 15: Line 15:
           wrapper.appendChild(pageLink);
           wrapper.appendChild(pageLink);
           if (pageIdx < (pages.length - 1)) {
           if (pageIdx < (pages.length - 1)) {
             wrapper.appendChild(document.createTextNode(' • ');
             wrapper.appendChild(document.createTextNode(' • '));
           }
           }
         }
         }

Revision as of 00:15, 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);
         if (pageIdx < (pages.length - 1)) {
           wrapper.appendChild(document.createTextNode(' • '));
         }
       }
     }).catch(function(err) {
       console.log('Fetch Error :-S', err);
     });
   })();
 </script>