Moodle Copy

Copies the current question to clipboard in the moodle quiz. Make sure to change the @match statement to your quiz website.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Moodle Copy
// @namespace    http://tampermonkey.net/
// @version      0.4.1
// @description  Copies the current question to clipboard in the moodle quiz. Make sure to change the @match statement to your quiz website.
// @author       Anonim Arı
// @match        https://ayva.itu.edu.tr/mod/quiz/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=edu.tr
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  "use strict";

  document.addEventListener(
    "contextmenu",
    (e) => {
      e.returnValue = true;
      e.stopPropagation && e.stopPropagation();
    },
    true
  );

  const element = document.querySelector(
    'form > div > div > div[class="content"]'
  );

  if (!element) return console.log("Element not found");

  function createButton() {
    const button = document.createElement("button");
    const art = `¯\\_(ツ)_/¯`;
    button.textContent = art;
    button.style = `
    bottom: 0px;
    right: 0px;
    position: fixed;
    color: white;
    z-index: 2147483647;
    padding: 10px;
    font-size: 25px;
    text-align: center;
    font-family: monospace;
    width: 200px;
    height: 253px;
    background-repeat: no-repeat;
    background-size: contain;

    background: black;
    `;
    return button;
  }

  const button = createButton();

  function chad() {
    button.style.backgroundImage =
      "url(https://media.tenor.com/MKpqR-aLLzYAAAAM/pov-you.gif)";
    button.innerText = "";
  }

  function clipboard(text) {
    const item = new ClipboardItem({
      "text/plain": new Blob([text], { type: "text/plain" }),
    });

    navigator.clipboard
      .write([item])
      .then(() => {
        chad();
        alert("Text copied to clipboard!");
      })
      .catch((error) => {
        alert("Error while copying! " + error);
      });
  }

  button.addEventListener("click", function () {
    clipboard(element.innerText);
  });
  document.body.appendChild(button);
})();