Skip to content

Instantly share code, notes, and snippets.

@ashtonmeuser
Last active April 20, 2025 15:36
  • Select an option

Select an option

Revisions

  1. ashtonmeuser revised this gist Apr 20, 2025. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions captions.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,18 @@
    (() => {
    const matchingDivs = Array.from(document.querySelectorAll('div')).filter(div =>
    Array.from(div.classList).some(cls => cls.includes('DivDesContainer') || cls.includes('DivVideoDescription'))
    Array.from(div.classList).some(cls =>
    ['DivDescriptionContentContainer', 'DivDesContainer', 'DivVideoDescription'].some(sub => cls.includes(sub))
    )
    );

    const lines = matchingDivs.map(div => `"${div.innerText.trim().replace(/"/g, '""')}"`);
    const lines = matchingDivs.map(div =>
    `"${div.innerText.trim().replace(/"/g, '""')}"`
    );

    const proceed = confirm(`Found ${lines.length} captions. Do you want to download them as CSV?`);
    if (!proceed) return;

    const content = lines.join('\n');
    const content = `text,label\n${lines.join('\n')}`;
    const blob = new Blob([content], { type: 'text/csv;charset=utf-8;' });

    const link = document.createElement('a');
  2. ashtonmeuser created this gist Apr 20, 2025.
    18 changes: 18 additions & 0 deletions captions.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    (() => {
    const matchingDivs = Array.from(document.querySelectorAll('div')).filter(div =>
    Array.from(div.classList).some(cls => cls.includes('DivDesContainer') || cls.includes('DivVideoDescription'))
    );

    const lines = matchingDivs.map(div => `"${div.innerText.trim().replace(/"/g, '""')}"`);

    const content = lines.join('\n');
    const blob = new Blob([content], { type: 'text/csv;charset=utf-8;' });

    const link = document.createElement('a');
    link.href = URL.createObjectURL(blob);
    link.download = 'data.csv';

    document.body.appendChild(link); // Required for Firefox
    link.click();
    document.body.removeChild(link);
    })();