Discord/Shapes - Rules

Logic for rotating custom texts on Discord

  1. // ==UserScript==
  2. // @name Discord/Shapes - Rules
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Logic for rotating custom texts on Discord
  6. // @author Vishanka
  7. // @match https://discord.com/channels/*
  8. // @grant none
  9. // @run-at document-idle
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Custom texts to cycle through
  16. const customRules = [
  17. "<Rule1: Type here instructions you want to have reiterated. The AI will deprioritize your prompt so it needs to be reminded.>",
  18. "<Rule2: Be mindful of the commas and syntax here, every entry except the last one needs a comma.>",
  19. "<Rule3: Put the Rules or whatever you reiterate between these brackets or otherwise the hiding script will not hide them.>",
  20. "<Rule4: You can disable the rules in the main script by unticking the checkbox.>",
  21. "<Rule5: Be mindful that this last entry doesn't have a comma You can add as many rules as you like.>"
  22. ];
  23. let currentIndex = 0;
  24.  
  25. // Function to determine the current rule index by scanning last two messages
  26. function determineCurrentIndex() {
  27. const messageItems = document.querySelectorAll('li[class^="messageListItem_"]');
  28.  
  29. if (messageItems.length >= 1) {
  30. // Check the last message first
  31. const lastMessage = Array.from(messageItems[messageItems.length - 1].querySelectorAll('span')).map(span => span.innerText).join('') || messageItems[messageItems.length - 1].innerText;
  32.  
  33. for (let i = 0; i < customRules.length; i++) {
  34. if (lastMessage.includes(`<Rule${i + 1}:`)) {
  35. currentIndex = (i + 1) % customRules.length;
  36. return;
  37. }
  38. }
  39. }
  40.  
  41. // If not found in the last message, check the second to last message
  42. if (messageItems.length >= 2) {
  43. const secondLastMessage = Array.from(messageItems[messageItems.length - 2].querySelectorAll('span')).map(span => span.innerText).join('') || messageItems[messageItems.length - 2].innerText;
  44.  
  45. for (let i = 0; i < customRules.length; i++) {
  46. if (secondLastMessage.includes(`<Rule${i + 1}:`)) {
  47. currentIndex = (i + 1) % customRules.length;
  48. return;
  49. }
  50. }
  51. }
  52. }
  53.  
  54. // Expose necessary elements to be used by the second script
  55. window.customRuleLogic = {
  56. customRules,
  57. determineCurrentIndex,
  58. getCurrentText: function() {
  59. determineCurrentIndex();
  60. const customRule = '\n' + customRules[currentIndex];
  61. currentIndex = (currentIndex + 1) % customRules.length;
  62. return customRule;
  63. }
  64. };
  65. })();