Quizlet TSV Export

Copies Quizlet flashcards to clipboard in TSV format

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);

})();