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

From wiki
Jump to navigation Jump to search
(empty the file)
Tag: Blanking
 
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('bodyContent');
 
    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 15:56, 25 March 2024