Moodle Copy

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

目前为 2023-04-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Moodle Copy
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4.1
  5. // @description Copies the current question to clipboard in the moodle quiz. Make sure to change the @match statement to your quiz website.
  6. // @author Anonim Arı
  7. // @match https://ayva.itu.edu.tr/mod/quiz/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=edu.tr
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. document.addEventListener(
  17. "contextmenu",
  18. (e) => {
  19. e.returnValue = true;
  20. e.stopPropagation && e.stopPropagation();
  21. },
  22. true
  23. );
  24.  
  25. const element = document.querySelector(
  26. 'form > div > div > div[class="content"]'
  27. );
  28.  
  29. if (!element) return console.log("Element not found");
  30.  
  31. function createButton() {
  32. const button = document.createElement("button");
  33. const art = \\_(ツ)_/¯`;
  34. button.textContent = art;
  35. button.style = `
  36. bottom: 0px;
  37. right: 0px;
  38. position: fixed;
  39. color: white;
  40. z-index: 2147483647;
  41. padding: 10px;
  42. font-size: 25px;
  43. text-align: center;
  44. font-family: monospace;
  45. width: 200px;
  46. height: 253px;
  47. background-repeat: no-repeat;
  48. background-size: contain;
  49.  
  50. background: black;
  51. `;
  52. return button;
  53. }
  54.  
  55. const button = createButton();
  56.  
  57. function chad() {
  58. button.style.backgroundImage =
  59. "url(https://media.tenor.com/MKpqR-aLLzYAAAAM/pov-you.gif)";
  60. button.innerText = "";
  61. }
  62.  
  63. function clipboard(text) {
  64. const item = new ClipboardItem({
  65. "text/plain": new Blob([text], { type: "text/plain" }),
  66. });
  67.  
  68. navigator.clipboard
  69. .write([item])
  70. .then(() => {
  71. chad();
  72. alert("Text copied to clipboard!");
  73. })
  74. .catch((error) => {
  75. alert("Error while copying! " + error);
  76. });
  77. }
  78.  
  79. button.addEventListener("click", function () {
  80. clipboard(element.innerText);
  81. });
  82. document.body.appendChild(button);
  83. })();