Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name PA UC Auto Chatter
- // @namespace Violentmonkey Scripts
- // @match https://www.uc.pa.gov/Chat/index.aspx
- // @grant none
- // @version 1.3
- // @author someone else, credits to Barkin MAD
- // @description 4/30/2020, 10:37:42 AM
- // ==/UserScript==
- // Use this section to fill in your personal details that will be enterted into the chat form
- // KEEP EVERYTHING BETWEEN THE QUOTES, DO NOT DELETE SEMI COLONS OR ANYTHING ELSE NOT INBETWEEN QUOTES Example: FIRSTNAME = "Mike";
- const FIRSTNAME = "FIRSTNAME";
- const LASTNAME = "LASTNAME";
- const EMAIL = "EMAIL";
- const PHONE = "PHONE";
- // DO NOT EDIT ANYTHING BELOW THIS MESSAGE UNLESS YOU KNOW WHAT YOU'RE DOING. Things will break.
- //.........................................................................................
- //.WWW...WWWWW...WWW...AAAA......RRRRRRRRR....NNNN....NNN..III..NNNN....NNN.....GGGGGG.....
- //.WWW...WWWWW...WWW...AAAAA.....RRRRRRRRRRR..NNNN....NNN..III..NNNN....NNN...GGGGGGGGGG...
- //.WWWW..WWWWW..WWWW...AAAAA.....RRRRRRRRRRR..NNNNN...NNN..III..NNNNN...NNN...GGGGGGGGGGG..
- //.WWWW..WWWWW..WWWW..AAAAAA.....RRR.....RRR..NNNNN...NNN..III..NNNNN...NNN..GGGG....GGGG..
- //..WWW.WWWWWWW.WWW...AAAAAAA....RRR.....RRR..NNNNNN..NNN..III..NNNNNN..NNN..GGG......GG...
- //..WWW.WWW.WWW.WWW..AAAA.AAA....RRRRRRRRRRR..NNNNNNN.NNN..III..NNNNNNN.NNN.NGGG...........
- //..WWWWWWW.WWW.WWW..AAA..AAAA...RRRRRRRRRR...NNN.NNN.NNN..III..NNN.NNN.NNN.NGGG...GGGGGG..
- //..WWWWWWW.WWWWWWW..AAAAAAAAA...RRRRRRRR.....NNN.NNNNNNN..III..NNN.NNNNNNN.NGGG...GGGGGG..
- //...WWWWWW..WWWWW..AAAAAAAAAA...RRR..RRRR....NNN..NNNNNN..III..NNN..NNNNNN..GGG...GGGGGG..
- //...WWWWW...WWWWW..AAAAAAAAAAA..RRR...RRRR...NNN..NNNNNN..III..NNN..NNNNNN..GGGG.....GGG..
- //...WWWWW...WWWWW..AAA.....AAA..RRR....RRRR..NNN...NNNNN..III..NNN...NNNNN...GGGGGGGGGGG..
- //...WWWWW...WWWWW.WAAA.....AAAA.RRR....RRRR..NNN....NNNN..III..NNN....NNNN...GGGGGGGGGG...
- //...WWWW.....WWWW.WAA......AAAA.RRR.....RRRR.NNN....NNNN..III..NNN....NNNN.....GGGGGG.....
- //.........................................................................................
- // DO NOT EDIT ANYTHING BELOW THIS MESSAGE UNLESS YOU KNOW WHAT YOU'RE DOING. Things will break.
- const SUBJECT = 2;
- const BSCHAT = [
- "Chat Started",
- "DLI Chat Connected",
- "Chat is available Monday – Friday, 7 a.m. - 6 p.m. An Unemployment Compensation Chat Agent will be with you shortly.",
- "We are experiencing a much higher than normal volume. An Unemployment Compensation Chat Agent will be with you shortly.",
- "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.",
- "Our office is closed. Please try again during our normal hours of operation.",
- "Have a great day.",
- "Chat Ended"
- ];
- 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.";
- var listenerID;
- // Bring the chat dialog up and fill it out
- setTimeout(function() {
- document.querySelector(".cx-webchat-chat-button").click();
- setTimeout(FillDetails, 1000);
- setTimeout(StartChat, 2000);
- listenerID = setInterval(ListenMessages, 5000);
- }, 4000);
- function FillDetails() {
- console.log("Filling out details");
- var event = new Event('input', {
- bubbles: true,
- cancelable: true,
- });
- // These event dispatches seemed necessary because validation errors would popup since the change event wasn't triggered
- document.getElementById("cx_webchat_form_firstname").value = FIRSTNAME;
- document.getElementById("cx_webchat_form_firstname").dispatchEvent(event);
- document.getElementById("cx_webchat_form_lastname").value = LASTNAME;
- document.getElementById("cx_webchat_form_lastname").dispatchEvent(event);
- document.getElementById("cx_webchat_form_email").value = EMAIL;
- document.getElementById("cx_webchat_form_email").dispatchEvent(event);
- document.getElementById("cx_webchat_form_phone").value = PHONE;
- document.getElementById("cx_webchat_form_phone").dispatchEvent(event);
- document.getElementById("cx_webchat_form_subject").selectedIndex = SUBJECT;
- }
- // Finds the start chat buttom on the webpage and clicks it.
- function StartChat() {
- console.log("Starting chat");
- var buttonTags = document.getElementsByTagName("button");
- var searchText = "Start Chat";
- var found;
- for (var i = 0; i < buttonTags.length; i++) {
- if (buttonTags[i].textContent == searchText) {
- found = buttonTags[i];
- break;
- }
- }
- if (found != null) {
- setTimeout(found.click(), 500);
- }
- }
- // Reads messages to see if chat ended, if so retries. If it sees a message from an agent or user it stops the script.
- function ListenMessages() {
- // I don't think this makes sense anymore for the new system, but I could be wrong
- //StartChat();
- console.log("listening for messages")
- var liveMsgs = document.getElementsByClassName("cx-message-text");
- console.log("Found " + liveMsgs.length + " messages.");
- for (var i = 0; i < liveMsgs.length; i++) {
- // Connected to chat
- if (!BSCHAT.includes(liveMsgs[i].textContent)) {
- // The messages changed slightly, if it's an automated message to indicate a failure, we should add it above later
- console.log(liveMsgs[i].textContent);
- console.log("Possible Chat Session Detected. Stopping script.")
- clearInterval(listenerID)
- return;
- }
- // Disconnected from chat
- else if (liveMsgs[i].textContent == CHATENDPROMPT) {
- console.log("Chat end prompt detected. Reloading page...")
- // close the chat window and press end chat
- document.querySelector(".cx-button-close").click();
- document.querySelector(".cx-end-confirm").click();
- clearInterval(listenerID);
- setTimeout(function () {
- Refresh();
- }, 1000);
- }
- }
- }
- function Refresh() {
- clearInterval(listenerID);
- location.reload();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement