Skip to content

Instantly share code, notes, and snippets.

@nodaguti
Last active September 14, 2025 19:42
Show Gist options
  • Select an option

  • Save nodaguti/7b54519da2dee93e23bc to your computer and use it in GitHub Desktop.

Select an option

Save nodaguti/7b54519da2dee93e23bc to your computer and use it in GitHub Desktop.
Quizlet to CSV
/**
* Convert a list on Quizlet into CSV-formatted text.
* Usage:
* i) Copy and paste into your browser's console.
* ii) Run it!
*/
(() => {
const terms = document.getElementsByClassName('term');
const csv = [];
Array.from(terms).forEach((term) => {
const word = term.querySelector('.qWord').textContent.replace(/[\n\r]+/g, '/');
const def = term.querySelector('.qDef').textContent.replace(/[\n\r]+/g, '/');
csv.push(`"${word}","${def}"`);
});
console.log(csv.join('\n'));
})();
@tika
Copy link

tika commented Sep 14, 2025

Updated for September 2025

(() => {
  try {
    const terms = document.getElementsByClassName('SetPageTermsList-term');
    
    if (terms.length === 0) {
      console.log('No terms found. Make sure you\'re on the correct page.');
      return;
    }
    
    const csv = ['Term,Definition']; // Add header row
    let extractedCount = 0;

    Array.from(terms).forEach((term) => {
      const termTexts = term.querySelectorAll('.TermText');
      
      if (termTexts.length >= 2) {
        // Clean up text by removing extra whitespace and newlines
        const word = termTexts[0].textContent.trim().replace(/[\n\r]+/g, ' ');
        const def = termTexts[1].textContent.trim().replace(/[\n\r]+/g, ' ');
        
        // Escape quotes in CSV by doubling them
        const escapedWord = word.replace(/"/g, '""');
        const escapedDef = def.replace(/"/g, '""');
        
        csv.push(`"${escapedWord}","${escapedDef}"`);
        extractedCount++;
      }
    });

    if (extractedCount === 0) {
      console.log('No valid term pairs found.');
      return;
    }

    // Modern clipboard API (preferred method)
    if (navigator.clipboard && navigator.clipboard.writeText) {
      navigator.clipboard.writeText(csv.join('\n'))
        .then(() => {
          console.log(`✅ CSV data with ${extractedCount} terms copied to clipboard!`);
          console.log('Preview:', csv.slice(0, 3).join('\n') + (csv.length > 3 ? '\n...' : ''));
        })
        .catch((err) => {
          console.error('Failed to copy to clipboard:', err);
          fallbackCopy();
        });
    } else {
      // Fallback method for older browsers
      fallbackCopy();
    }

    function fallbackCopy() {
      const textarea = document.createElement('textarea');
      textarea.value = csv.join('\n');
      textarea.style.position = 'fixed';
      textarea.style.opacity = '0';
      document.body.appendChild(textarea);
      textarea.select();
      
      try {
        const successful = document.execCommand('copy');
        if (successful) {
          console.log(`✅ CSV data with ${extractedCount} terms copied to clipboard!`);
          console.log('Preview:', csv.slice(0, 3).join('\n') + (csv.length > 3 ? '\n...' : ''));
        } else {
          console.log('❌ Copy failed. Here\'s the CSV data:');
          console.log(csv.join('\n'));
        }
      } catch (err) {
        console.log('❌ Copy not supported. Here\'s the CSV data:');
        console.log(csv.join('\n'));
      }
      
      document.body.removeChild(textarea);
    }

  } catch (error) {
    console.error('Script error:', error);
  }
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment