ep-bot

copy answer to clipboard

  1. // ==UserScript==
  2. // @name ep-bot
  3. // @namespace http://tampermonkey.net/
  4. // @version 4.0
  5. // @description copy answer to clipboard
  6. // @author EP-bot
  7. // @match https://app.educationperfect.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. /*
  13. MIT License
  14.  
  15. Copyright (c) 2025 EP-bot
  16.  
  17. Permission is hereby granted, free of charge, to any person obtaining a copy
  18. of this software and associated documentation files (the "Software"), to deal
  19. in the Software without restriction, including without limitation the rights
  20. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  21. copies of the Software, and to permit persons to whom the Software is
  22. furnished to do so, subject to the following conditions:
  23.  
  24. The above copyright notice and this permission notice shall be included in all
  25. copies or substantial portions of the Software.
  26.  
  27. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  30. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  31. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  32. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. SOFTWARE.
  34. */
  35.  
  36. (function () {
  37. 'use strict';
  38. let dictionary = {};
  39. function replaceSemicolons(text) { return text.replace(/;/g, ','); }
  40. function extractTextPairs() {
  41. const newDict = {};
  42. const pairs = document.querySelectorAll('.targetLanguage.question-label');
  43. pairs.forEach(pair => {
  44. const base = pair.parentElement.querySelector('.baseLanguage.question-label');
  45. if (base) {
  46. let q = replaceSemicolons(pair.textContent.trim());
  47. let a = replaceSemicolons(base.textContent.trim());
  48. if (q && a) { newDict[q] = a; newDict[a] = q; }
  49. }
  50. });
  51. const same = Object.keys(newDict).length === Object.keys(dictionary).length && Object.keys(newDict).every(k => dictionary[k] === newDict[k]);
  52. if (!same && Object.keys(newDict).length > 0) { dictionary = newDict; }
  53. }
  54. function getStartsWithHint() {
  55. const hintElement = document.querySelector('span[ng-if="hint"]');
  56. if (hintElement && hintElement.textContent.includes("starts with")) {
  57. const match = hintElement.textContent.match(/starts with '(\w)'/);
  58. return match ? match[1] : null;
  59. }
  60. return null;
  61. }
  62. function filterAnswer(answer, startsWith) {
  63. if (!startsWith) return answer;
  64. const options = answer.split(', ').filter(word => word.toLowerCase().startsWith(startsWith.toLowerCase()));
  65. return options.length > 0 ? options[0] : answer;
  66. }
  67. const observer = new MutationObserver(mutations => {
  68. for (const mutation of mutations) {
  69. const node = mutation.target;
  70. if (node && node.nodeType === Node.ELEMENT_NODE && node.id === 'question-text') {
  71. const originalText = node.textContent.trim();
  72. if (dictionary[originalText]) {
  73. const answer = dictionary[originalText];
  74. const startsWith = getStartsWithHint();
  75. const finalAnswer = filterAnswer(answer, startsWith);
  76. navigator.clipboard.writeText(finalAnswer);
  77. }
  78. }
  79. }
  80. });
  81. observer.observe(document.body, { childList: true, subtree: true, characterData: true });
  82. setInterval(extractTextPairs, 200);
  83. })();