Last active
September 14, 2025 19:42
-
-
Save nodaguti/7b54519da2dee93e23bc to your computer and use it in GitHub Desktop.
Quizlet to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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')); | |
})(); |
Replace SetPageTerms-term
with SetPageTermsList-term
to make those work
Working Clipboard Snippet:
/**
* 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('SetPageTermsList-term');
const csv = [];
Array.from(terms).forEach((term) => {
const termTexts = term.querySelectorAll('.TermText');
const word = termTexts[0].textContent.replace(/[\n\r]+/g, '/');
const def = termTexts[1].textContent.replace(/[\n\r]+/g, '/');
csv.push(`"${word}","${def}"`);
});
// Create a temporary textarea element to copy the CSV text
const textarea = document.createElement('textarea');
textarea.value = csv.join('\n');
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
console.log('CSV text copied to clipboard');
})();
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
June '24 update:
Bonus: automatically copy to clipboad: