Quizlet

Quizlet script (Read additional info)

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Quizlet
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Quizlet script (Read additional info)
// @author       You
// @match        https://quizlet.com/live
// @icon         https://www.google.com/s2/favicons?sz=64&domain=quizlet.com
// @grant        none
// ==/UserScript==

(function() {

    console.log("Script loaded!");

    let obj = {};

    document.addEventListener('keydown', (event) => {
        if(event.key == "Enter" && event.metaKey) {
            event.preventDefault();
            getAnswerObj();
        }
        if(event.key == 'k') {
            if(Object.keys(obj).length == 0) {
                getAnswerObj(() => {plopAnswer(event.metaKey)});
            } else {
                plopAnswer(event.metaKey);
            }
        }
    });

    let plopAnswer = (click = false) => {
        let answer = document.querySelector('.StudentPrompt-text > div');
        let answerInfo = answer.innerHTML;
        let cards = [...document.querySelectorAll(".StudentAnswerOption div.StudentAnswerOption-text > div")];
        let cardsInfo = cards.map(card => card.innerHTML);

        let keys = Object.keys(obj);
        let values = keys.map(key => obj[key]);
        let div;
        if(keys.includes(answerInfo)) {
            let key = keys[keys.indexOf(answerInfo)];
            let correctAnswer = obj[key];
            let index = cardsInfo.indexOf(correctAnswer);
            div = [...document.querySelectorAll(".StudentAnswerOptions-optionCard")][index];
            div.style.border = '3px solid red';
        } else if(values.includes(answerInfo)){
            let value = values[values.indexOf(answerInfo)];
            let correctAnswer = keys[values.indexOf(answerInfo)];
            let index = cardsInfo.indexOf(correctAnswer);
            div = [...document.querySelectorAll(".StudentAnswerOptions-optionCard")][index];
            div.style.border = '3px solid red';
        } else {
            return;
        }

        if(click) {
            div.querySelector('div.StudentAnswerOption-text > div').click();
            div.style.border = '0px';
        } else {
            let handler = () => {
                div.style.border = '0px';
                div.removeEventListener('click', handler);
            }
            div.addEventListener('click', handler);
        }
    }

    async function getAnswerObj(callAfter = undefined) {
        if (navigator.clipboard) {
            try {
                const text = await navigator.clipboard.readText();
                let arr = text.split(";");
                for(let i = 0; i < arr.length; i++) {
                    let newArr = arr[i].split(',');
                    obj[newArr[0]] = newArr[1];
                }
            } catch (err) {
                console.error('Failed to read clipboard contents:', err);
                return; // Or handle the error as appropriate for your application
            }
        } else {
            console.error('Clipboard API not available.');
            return;
        }
        if(callAfter !== undefined) {
            callAfter();
        }
    }
})();