Quizlet TSV Export

Copies Quizlet flashcards to clipboard in TSV format

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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);

})();