Quizlet TSV Export

Copies Quizlet flashcards to clipboard in TSV format

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Quizlet TSV Export
// @namespace    http://tampermonkey.net/
// @version      2024-03-21
// @description  Copies Quizlet flashcards to clipboard in TSV format
// @author       ioc
// @license      AGPLv3
// @match        https://quizlet.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=quizlet.com
// @grant        none
// ==/UserScript==

function getCards() {
    const data = document.querySelectorAll("span.TermText");
    if (!data.length) return;

    let result = [];

    Array.from(data).forEach((x, i, arr) => {
        if (i % 2 === 0) {
            result.push(`${x.innerText}\t${arr[i + 1].innerText}`);
        }
    });

    return result;
}

(function() {
    'use strict';

    const classes = ["AssemblyButtonBase", "AssemblySecondaryButton", "AssemblyButtonBase--medium", "AssemblyButtonBase--padding"];

    const result = getCards();
    const titleElem = document.querySelectorAll("h1")[0];
    const btn = document.createElement("button");

    btn.style.marginLeft = "0.5rem";

    classes.forEach((c) => {
        btn.classList.add(c);
    });

    btn.innerText = "Copy TSV";

    btn.onclick = () => {
        try {
            window.navigator.clipboard.writeText(result.join("\n\n"));
            btn.innerText = "Copied!";
        } catch (e) {
            btn.innerText = "Error";
            console.warn("Quizlet TSV Export:", e);
        }

        setTimeout(() => {
            btn.innerText = "Copy TSV";
        }, 500);
    };

    titleElem.appendChild(btn);

})();