Moodle AutoHello

Здоровается с преподавателем на лекции, как только это сделал кто-то другой

安装此脚本
作者推荐脚本

您可能也喜欢Moodle AutoPilot

安装此脚本
  1. // ==UserScript==
  2. // @name Moodle AutoHello
  3. // @namespace https://t.me/johannmosin
  4. // @version 0.1.0
  5. // @description Здоровается с преподавателем на лекции, как только это сделал кто-то другой
  6. // @author Johann Mosin
  7. // @license MIT
  8. // @match https://*.edu.vsu.ru/html5client/*
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. let messageSent = false; // Prevent sending multiple messages
  15.  
  16. function findReactProps(dom) {
  17. for (const key in dom) {
  18. if (key.startsWith('__reactInternalInstance$') || key.startsWith('__reactFiber$')) {
  19. return dom[key].return ? dom[key].return.stateNode.props : dom[key]._currentElement._owner._instance.props;
  20. }
  21. }
  22. return null;
  23. }
  24.  
  25. function autoGreet() {
  26. if (messageSent) return; // Stop if message already sent
  27.  
  28. // Check for greetings in the page text
  29. const greetings = ["здравствуйте", "здравстуйте", "Здравствуйте", "Здраствуйте"];
  30. const pageText = document.body.innerText;
  31.  
  32. if (greetings.some(greet => pageText.includes(greet))) {
  33. console.log("Greeting detected!");
  34.  
  35. // Find the input and send button
  36. const messageInput = document.querySelector('#message-input');
  37. const sendButton = document.querySelector('button[aria-label="Отправить сообщение"]');
  38.  
  39. if (messageInput && sendButton) {
  40. // Access React props
  41. const props = findReactProps(messageInput);
  42.  
  43. if (props && props.onChange) {
  44. // Create a synthetic event to update React state
  45. const syntheticEvent = {
  46. target: { value: "Здравствуйте" },
  47. currentTarget: { value: "Здравствуйте" },
  48. };
  49. props.onChange(syntheticEvent);
  50.  
  51. // Now click the send button
  52. sendButton.click();
  53.  
  54. console.log("Greeting message sent via React props!");
  55. messageSent = true; // Mark as sent to prevent multiple sends
  56.  
  57. // Stop the interval to save memory
  58. clearInterval(greetingInterval);
  59. console.log("Interval cleared to save memory.");
  60. } else {
  61. console.log("React props not found or onChange handler missing.");
  62. }
  63. } else {
  64. console.log("Message input or send button not found!");
  65. }
  66. }
  67. }
  68.  
  69. // Run the function periodically to detect greetings
  70. const greetingInterval = setInterval(autoGreet, 2000);
  71. })();