PA UC Auto Chatter

7/1/2020, 12:00:42 PM

Per 01-07-2020. Zie de nieuwste versie.

// ==UserScript==
// @name        PA UC Auto Chatter
// @namespace   Violentmonkey Scripts
// @match       https://www.uc.pa.gov/Chat/index.aspx
// @grant       none
// @version     1.3.1
// @author      Barkin MAD
// @description 7/1/2020, 12:00:42 PM
// ==/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 = "FIRST_NAME_HERE";
const LASTNAME = "LAST_NAME_HERE";
const EMAIL = "EMAIL_HERE";
const PHONE = "PHONE_HERE";
 
// 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;
 
 
// Main execution loop
setTimeout(function() {
  document.querySelector(".cx-webchat-chat-button").click();
  setTimeout(FillDetails, 1000);
  setTimeout(StartChat, 2000);
  listenerID = setInterval(ListenMessages, 5000);
}, 4000);

// Fills user's personal details in the chat form.
function FillDetails() {
    console.log("Filling out details");
    var event = new Event('input', {
      bubbles: true,
      cancelable: true,
    });
 
    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;
}
 
// Searches for the start chat button 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() {
    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)) {
            console.log(liveMsgs[i].textContent);
            console.log("Possible Chat Session Detected. Stopping script.")
            clearInterval(listenerID)
            return;
        }
        // Disconnected from chat, close and refresh
        else if (liveMsgs[i].textContent == CHATENDPROMPT) {
            console.log("Chat end prompt detected. Reloading page...")
            document.querySelector(".cx-button-close").click();
            document.querySelector(".cx-end-confirm").click();
         
            clearInterval(listenerID);
            setTimeout(function () {
                Refresh();
            }, 1000);
        }
    }
}
 
function Refresh() {
    clearInterval(listenerID);
    location.reload();
}
长期地址
遇到问题?请前往 GitHub 提 Issues。