Continuation Mode

Keeps the drawings from the previous turns

  1. // ==UserScript==
  2. // @name Continuation Mode
  3. // @match https://sketchful.io/
  4. // @grant none
  5. // @version 1.0
  6. // @author Bell
  7. // @description Keeps the drawings from the previous turns
  8. // jshint esversion: 6
  9. // @namespace https://greasyfork.org/users/281093
  10. // ==/UserScript==
  11.  
  12. const canvas = document.getElementById("canvas");
  13. const ctx = canvas.getContext("2d");
  14.  
  15. function parseSystemMessage(string) {
  16. if (string.startsWith("The word was:"))
  17. freezeCanvas();
  18. else if (string.endsWith("is drawing now!"))
  19. unfreezeCanvas();
  20. }
  21.  
  22. const checkChat = (mutations) => {
  23. mutations.forEach(mutation => {
  24. if (!mutation.addedNodes[0] || !mutation.addedNodes[0].classList.contains("chatAdmin"))
  25. return;
  26. parseSystemMessage(mutation.addedNodes[0].textContent);
  27. });
  28. };
  29.  
  30. const chat = document.querySelector("#gameChatList");
  31. const chatObserver = new MutationObserver(checkChat);
  32. chatObserver.observe(chat, {
  33. childList: true
  34. });
  35.  
  36. function freezeCanvas() {
  37. ctx.fillRect = () => {};
  38. }
  39.  
  40. function unfreezeCanvas() {
  41. ctx.fillRect = ctx.constructor.prototype.fillRect;
  42. }