Classtime copier

Copy the title and answers from Classtime

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         Classtime copier
// @namespace    https://www.classtime.com/
// @version      2024-09-11
// @description  Copy the title and answers from Classtime
// @author       marshallovski
// @match        https://www.classtime.com/code/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=classtime.com
// @grant        none
// @license MIT
// ==/UserScript==

// https://www.youtube.com/watch?v=DBT5lM9pSo8
(function () {
    const interval = setInterval(() => {
        // question element
        const title = document.querySelector('[data-testid="student-session-question-title"]');
        const title2 = document.querySelector('#classtime-mathjax-content');

        // answers element
        const answers = document.querySelector('[data-testid="questions-answers-list"]');

        const elements = title && answers;

        // if question and answers exist, creating button which copies text
        if (elements) {
            // Check if button already exists
            let copyBtn = document.querySelector('#copyBtn');
            if (!copyBtn) {
                // creating the button
                copyBtn = document.createElement('button');
                copyBtn.id = 'copyBtn'; // Set an ID for the button
                copyBtn.innerText = 'Copy answers and question';
                copyBtn.style = 'position:fixed;bottom:1em;z-index:9999;background-color:#006769;color:#eee;border-radius:16px;padding:4px 8px;right:1em;border:1px solid #40A578';

                copyBtn.onclick = () => {
                    navigator.clipboard.writeText(`${title.innerText} (${title2.innerText || ''})\n\n\n${answers.innerText}`);
                    alert("Copied to clipboard!");
                }

                // adding the button to page
                document.body.append(copyBtn);
            } else {
                // Update button's onclick function to copy the latest text
                copyBtn.onclick = () => {
                    navigator.clipboard.writeText(`${title.innerText} (${title2.innerText || ''})\n\n\n${answers.innerText}`);
                    alert("Copied to clipboard!");
                };
            }
        }
    }, 100);
})();