(function() { const rows = document.querySelectorAll('.files .ghl-table-container tbody tr.n-data-table-tr'); const files = []; rows.forEach(row => { const fileNameElement = row.querySelector('[data-col-key="name"]'); const fileIdElement = row.querySelector('[data-col-key="media"] img'); const fileName = fileNameElement ? fileNameElement.textContent : ''; const fileId = fileIdElement ? fileIdElement.src.split('/').pop().split('.')[0] : ''; const isImage = /\.(jpeg|jpg|png|bmp|gif)$/i.test(fileName); if (fileId && fileName && isImage) { files.push({ fileName, fileId }); } }); files.sort((a, b) => a.fileName.localeCompare(b.fileName, undefined, { numeric: true, sensitivity: 'base' })); const sortedFileIds = files.map(file => file.fileId); const textToCopy = JSON.stringify(sortedFileIds, null, 2); // Log the result to console console.log(textToCopy); // Create a temporary textarea element const textArea = document.createElement('textarea'); textArea.value = textToCopy; document.body.appendChild(textArea); // Select the text and copy it to the clipboard textArea.select(); try { document.execCommand('copy'); console.log(`${sortedFileIds.length} File IDs copied to clipboard out of ${rows.length} total rows.`); } catch (err) { console.error('Failed to copy text: ', err); } // Remove the temporary textarea element document.body.removeChild(textArea); })();