// popup.js document.addEventListener('DOMContentLoaded', function() { const generateButton = document.getElementById('generate'); const outputDiv = document.getElementById('output'); const useStoredSettings = document.getElementById('useStoredSettings'); // Load saved patterns into textareas chrome.storage.sync.get({ includePatterns: 'src/**/*.ts,**/*.md', ignorePatterns: '**/*.log,tmp/' }, function(items) { document.getElementById('includePatterns').value = items.includePatterns; document.getElementById('ignorePatterns').value = items.ignorePatterns; }); document.getElementById('openSettings').addEventListener('click', function() { chrome.runtime.openOptionsPage(); }); function getRepoUrlFromGitHub(url) { try { const githubUrl = new URL(url); if (!githubUrl.hostname.includes('github.com')) { return null; } // Split the pathname and remove empty strings const pathParts = githubUrl.pathname.split('/').filter(part => part); // We need at least username/repo if (pathParts.length < 2) { return null; } // Just take the username and repo name const [username, repo] = pathParts; return `https://github.com/${username}/${repo}`; } catch (e) { console.error('Error parsing GitHub URL:', e); return null; } } generateButton.addEventListener('click', async () => { // Get the current tab const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); const repoUrl = getRepoUrlFromGitHub(tab.url); if (!repoUrl) { outputDiv.textContent = 'Please navigate to a GitHub repository page'; return; } const includePatterns = document.getElementById('includePatterns').value; const ignorePatterns = document.getElementById('ignorePatterns').value; let command = `npx repomix --remote ${repoUrl}`; if (useStoredSettings.checked) { // Get stored settings chrome.storage.sync.get({ outputStyle: 'plain', removeComments: false, removeEmptyLines: false, showLineNumbers: false, enableSecurityCheck: true }, function(settings) { if (settings.outputStyle !== 'plain') { command += ` --style ${settings.outputStyle}`; } if (settings.removeComments) { command += ' --remove-comments'; } if (settings.removeEmptyLines) { command += ' --remove-empty-lines'; } if (settings.showLineNumbers) { command += ' --output-show-line-numbers'; } if (!settings.enableSecurityCheck) { command += ' --no-security-check'; } if (includePatterns) { command += ` --include "${includePatterns}"`; } if (ignorePatterns) { command += ` --ignore "${ignorePatterns}"`; } displayOutput(command); }); } else { if (includePatterns) { command += ` --include "${includePatterns}"`; } if (ignorePatterns) { command += ` --ignore "${ignorePatterns}"`; } displayOutput(command); } }); function displayOutput(command) { outputDiv.innerHTML = `