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.2
  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. function createButton() {
  26. const button = document.createElement("button");
  27. const art = \\_(ツ)_/¯`;
  28. button.textContent = art;
  29. button.style = `
  30. bottom: 0px;
  31. right: 0px;
  32. position: fixed;
  33. color: white;
  34. z-index: 2147483647;
  35. padding: 10px;
  36. font-size: 25px;
  37. text-align: center;
  38. font-family: monospace;
  39. width: 200px;
  40. height: 253px;
  41. background-repeat: no-repeat;
  42. background-size: contain;
  43.  
  44. background: black;
  45. `;
  46. return button;
  47. }
  48.  
  49. const button = createButton();
  50.  
  51. function chad(button) {
  52. button.style.backgroundImage =
  53. "url(https://media.tenor.com/MKpqR-aLLzYAAAAM/pov-you.gif)";
  54. button.innerText = "";
  55. }
  56.  
  57. function clipboard(text) {
  58. const item = new ClipboardItem({
  59. "text/plain": new Blob([text], { type: "text/plain" }),
  60. });
  61.  
  62. navigator.clipboard
  63. .write([item])
  64. .then(() => {
  65. chad(button);
  66. alert("Text copied to clipboard!");
  67. })
  68. .catch((error) => {
  69. alert("Error while copying! " + error);
  70. });
  71. }
  72.  
  73. function copyContent() {
  74. const content = document.querySelector(
  75. 'form > div > div > div[class="content"]'
  76. );
  77. if (!content) return alert("Eleman bulunamadi");
  78. clipboard(content.innerText);
  79. }
  80.  
  81. button.addEventListener("click", function () {
  82. copyContent();
  83. });
  84. document.body.appendChild(button);
  85. })();