Advertisement
Guest User

PA UC Auto Chatter

a guest
Jul 1st, 2020
1,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.16 KB | None | 0 0
  1. // ==UserScript==
  2. // @name PA UC Auto Chatter
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.uc.pa.gov/Chat/index.aspx
  5. // @grant none
  6. // @version 1.3
  7. // @author someone else, credits to Barkin MAD
  8. // @description 4/30/2020, 10:37:42 AM
  9. // ==/UserScript==
  10.  
  11. // Use this section to fill in your personal details that will be enterted into the chat form
  12. // KEEP EVERYTHING BETWEEN THE QUOTES, DO NOT DELETE SEMI COLONS OR ANYTHING ELSE NOT INBETWEEN QUOTES Example: FIRSTNAME = "Mike";
  13.  
  14. const FIRSTNAME = "FIRSTNAME";
  15. const LASTNAME = "LASTNAME";
  16. const EMAIL = "EMAIL";
  17. const PHONE = "PHONE";
  18.  
  19. // DO NOT EDIT ANYTHING BELOW THIS MESSAGE UNLESS YOU KNOW WHAT YOU'RE DOING. Things will break.
  20. //.........................................................................................
  21. //.WWW...WWWWW...WWW...AAAA......RRRRRRRRR....NNNN....NNN..III..NNNN....NNN.....GGGGGG.....
  22. //.WWW...WWWWW...WWW...AAAAA.....RRRRRRRRRRR..NNNN....NNN..III..NNNN....NNN...GGGGGGGGGG...
  23. //.WWWW..WWWWW..WWWW...AAAAA.....RRRRRRRRRRR..NNNNN...NNN..III..NNNNN...NNN...GGGGGGGGGGG..
  24. //.WWWW..WWWWW..WWWW..AAAAAA.....RRR.....RRR..NNNNN...NNN..III..NNNNN...NNN..GGGG....GGGG..
  25. //..WWW.WWWWWWW.WWW...AAAAAAA....RRR.....RRR..NNNNNN..NNN..III..NNNNNN..NNN..GGG......GG...
  26. //..WWW.WWW.WWW.WWW..AAAA.AAA....RRRRRRRRRRR..NNNNNNN.NNN..III..NNNNNNN.NNN.NGGG...........
  27. //..WWWWWWW.WWW.WWW..AAA..AAAA...RRRRRRRRRR...NNN.NNN.NNN..III..NNN.NNN.NNN.NGGG...GGGGGG..
  28. //..WWWWWWW.WWWWWWW..AAAAAAAAA...RRRRRRRR.....NNN.NNNNNNN..III..NNN.NNNNNNN.NGGG...GGGGGG..
  29. //...WWWWWW..WWWWW..AAAAAAAAAA...RRR..RRRR....NNN..NNNNNN..III..NNN..NNNNNN..GGG...GGGGGG..
  30. //...WWWWW...WWWWW..AAAAAAAAAAA..RRR...RRRR...NNN..NNNNNN..III..NNN..NNNNNN..GGGG.....GGG..
  31. //...WWWWW...WWWWW..AAA.....AAA..RRR....RRRR..NNN...NNNNN..III..NNN...NNNNN...GGGGGGGGGGG..
  32. //...WWWWW...WWWWW.WAAA.....AAAA.RRR....RRRR..NNN....NNNN..III..NNN....NNNN...GGGGGGGGGG...
  33. //...WWWW.....WWWW.WAA......AAAA.RRR.....RRRR.NNN....NNNN..III..NNN....NNNN.....GGGGGG.....
  34. //.........................................................................................
  35. // DO NOT EDIT ANYTHING BELOW THIS MESSAGE UNLESS YOU KNOW WHAT YOU'RE DOING. Things will break.
  36.  
  37. const SUBJECT = 2;
  38. const BSCHAT = [
  39. "Chat Started",
  40. "DLI Chat Connected",
  41. "Chat is available Monday – Friday, 7 a.m. - 6 p.m. An Unemployment Compensation Chat Agent will be with you shortly.",
  42. "We are experiencing a much higher than normal volume. An Unemployment Compensation Chat Agent will be with you shortly.",
  43. "All of our chat agents are busy assisting other customers. We are unable to process your chat request at this time. Please try again later.",
  44. "Our office is closed. Please try again during our normal hours of operation.",
  45. "Have a great day.",
  46. "Chat Ended"
  47. ];
  48. const CHATENDPROMPT = "All of our chat agents are busy assisting other customers. We are unable to process your chat request at this time. Please try again later.";
  49. var listenerID;
  50.  
  51.  
  52. // Bring the chat dialog up and fill it out
  53. setTimeout(function() {
  54. document.querySelector(".cx-webchat-chat-button").click();
  55. setTimeout(FillDetails, 1000);
  56. setTimeout(StartChat, 2000);
  57. listenerID = setInterval(ListenMessages, 5000);
  58. }, 4000);
  59.  
  60. function FillDetails() {
  61. console.log("Filling out details");
  62. var event = new Event('input', {
  63. bubbles: true,
  64. cancelable: true,
  65. });
  66.  
  67. // These event dispatches seemed necessary because validation errors would popup since the change event wasn't triggered
  68. document.getElementById("cx_webchat_form_firstname").value = FIRSTNAME;
  69. document.getElementById("cx_webchat_form_firstname").dispatchEvent(event);
  70. document.getElementById("cx_webchat_form_lastname").value = LASTNAME;
  71. document.getElementById("cx_webchat_form_lastname").dispatchEvent(event);
  72. document.getElementById("cx_webchat_form_email").value = EMAIL;
  73. document.getElementById("cx_webchat_form_email").dispatchEvent(event);
  74. document.getElementById("cx_webchat_form_phone").value = PHONE;
  75. document.getElementById("cx_webchat_form_phone").dispatchEvent(event);
  76. document.getElementById("cx_webchat_form_subject").selectedIndex = SUBJECT;
  77. }
  78.  
  79. // Finds the start chat buttom on the webpage and clicks it.
  80. function StartChat() {
  81. console.log("Starting chat");
  82. var buttonTags = document.getElementsByTagName("button");
  83. var searchText = "Start Chat";
  84. var found;
  85.  
  86. for (var i = 0; i < buttonTags.length; i++) {
  87. if (buttonTags[i].textContent == searchText) {
  88. found = buttonTags[i];
  89. break;
  90. }
  91. }
  92.  
  93. if (found != null) {
  94. setTimeout(found.click(), 500);
  95. }
  96. }
  97.  
  98. // Reads messages to see if chat ended, if so retries. If it sees a message from an agent or user it stops the script.
  99. function ListenMessages() {
  100. // I don't think this makes sense anymore for the new system, but I could be wrong
  101. //StartChat();
  102. console.log("listening for messages")
  103. var liveMsgs = document.getElementsByClassName("cx-message-text");
  104. console.log("Found " + liveMsgs.length + " messages.");
  105. for (var i = 0; i < liveMsgs.length; i++) {
  106. // Connected to chat
  107. if (!BSCHAT.includes(liveMsgs[i].textContent)) {
  108. // The messages changed slightly, if it's an automated message to indicate a failure, we should add it above later
  109. console.log(liveMsgs[i].textContent);
  110. console.log("Possible Chat Session Detected. Stopping script.")
  111. clearInterval(listenerID)
  112. return;
  113. }
  114. // Disconnected from chat
  115. else if (liveMsgs[i].textContent == CHATENDPROMPT) {
  116. console.log("Chat end prompt detected. Reloading page...")
  117. // close the chat window and press end chat
  118. document.querySelector(".cx-button-close").click();
  119. document.querySelector(".cx-end-confirm").click();
  120.  
  121. clearInterval(listenerID);
  122. setTimeout(function () {
  123. Refresh();
  124. }, 1000);
  125. }
  126. }
  127. }
  128.  
  129. function Refresh() {
  130. clearInterval(listenerID);
  131. location.reload();
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement