Classtime copier

Copy the title and answers from Classtime

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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