Important: The GCConnex decommission will not affect GCCollab or GCWiki. Thank you and happy collaborating!

Difference between revisions of "User:Vid/pages.js"

From wiki
Jump to navigation Jump to search
(Created page with "// This code dynamically updates an HTML table of files with specified extensions on a MediaWiki site as it works (async function() { const extensions = ['pub', 'png', 'gif'...")
 
m (David.mason moved page User:Vid gmail/pages.js to User:Vid/pages.js: Automatically moved page while renaming the user "Vid gmail" to "Vid")
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
// This code dynamically updates an HTML table of files with specified extensions on a MediaWiki site as it works
 
(async function() {
 
  const extensions = ['pub', 'png', 'gif', 'jpg', 'jpeg', 'pdf', 'xls', 'docx', 'pptx', 'doc', 'ppt', 'svg', 'xml', 'mpg', 'odp', 'odt', 'wmv', 'flv', 'vsd', 'mpp', 'ai', 'zip', 'txt', 'wpd', 'rtf', 'drf', 'xlsx', 'xlsm', 'oft', 'swf', 'ppsx', 'dotx', 'potx'];
 
  
  const updateTable = (extension, count) => {
 
    const tableBody = document.getElementById('files-table-body');
 
    if (tableBody) {
 
      const row = `<tr><td>${extension}</td><td>${count}</td></tr>`;
 
      tableBody.innerHTML += row;
 
    } else {
 
      console.error('Files table body element not found');
 
    }
 
  };
 
 
  for (const extension of extensions) {
 
    let continueParam = '';
 
    let totalCount = 0;
 
 
    do {
 
      const response = await fetch(`https://wiki.gccollab.ca/api.php?action=query&list=allimages&aifrom=${extension}&ailimit=max&format=json${continueParam}`);
 
      const data = await response.json();
 
      const files = data.query.allimages || [];
 
 
      // Filter files by extension
 
      const filteredFiles = files.filter(file => file.name.endsWith(`.${extension}`));
 
      totalCount += filteredFiles.length;
 
 
      continueParam = data.continue ? `&aicontinue=${data.continue.aicontinue}` : '';
 
    } while (continueParam);
 
 
    // Update the table with the extension and count
 
    updateTable(extension, totalCount);
 
  }
 
})();
 

Latest revision as of 16:49, 18 December 2024