PA UC Autochatter

9/26/2020

当前为 2020-10-06 提交的版本,查看 最新版本

// ==UserScript==
// @name        PA UC Autochatter
// @namespace   Violentmonkey Scripts
// @match       https://www.uc.pa.gov/Chat/index.aspx
// @grant       none
// @version     3.1
// @author      Barkin MAD
// @require https://code.jquery.com/jquery-3.5.1.min.js
// @description 9/26/2020
// ==/UserScript==

// In the below 4 fields enter your relevant information inbetween the quotes to be sent into chat. Do NOT delete anything that is not inbetween the quotes or it will break. Example: FIRSTNAME = "Dimitri";
const FIRSTNAME = 'First Name Here';
const LASTNAME = 'Last Name Here';
const EMAIL = 'Email here';
const PHONE = 'Phone Here';

// Warning! Do not edit anything below this message unless you know what you're doing. Things can 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.....
//.........................................................................................
// Warning! Do not edit anything below this message unless you know what you're doing. Things can break.

const SUBJECT = 1;
const WAITING_INTERVAL = 100;
const MSG_WAITING_INTERVAL = 1000;
const OPEN_CHAT_CLASS = '.cx-webchat-chat-button';
const CHAT_CLASS = '.cx-webchat';
const MESSAGE_CLASS = '.cx-message-text';

var IN_QUEUE_PROMPT = "Chat is available Monday – Friday, 7 a.m. - 6 p.m.   An Unemployment Compensation Chat Agent will be with you shortly.";
const CHATENDPROMPTS = ["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."];

var PAULAResponses = {
    "Hello, I'm PAULA the Unemployment Compensation Virtual Assistant.": '',
    "Are you an employer? If you are contacting us about PUA or have a PUA claim, please answer NO.": 'No.',
    "Okay. You can ask me questions like, How do I file an unemployment claim?, or How do I know if I am eligible for unemployment?, So how can I help you today.": 'What is my payment status?',
    "Is there anything else I can help you with? Type YES or NO. If you have another question type YES and you will be prompted to ask it.": "Can I speak to an agent?",
    "Please feel free to ask your question now.": "Can I speak to an agent?",
    "What else can I help you with?": "Can I speak to an agent?"
};
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"
];

function onOpenChatReady(callback) {
    console.log('Waiting for start chat button to load...');
    var startButtonReady = setInterval(function () {
        // Close chat if it was left open
        $('.cx-end-confirm').trigger('click');
        $('.cx-button-close').trigger('click');

        if ($(OPEN_CHAT_CLASS).length) {
            clearInterval(startButtonReady);
            callback()
        }
    }, WAITING_INTERVAL);
}

function startChat() {
    $(OPEN_CHAT_CLASS).trigger('click');
}

function onChatReady(callback) {
    console.log('Waiting for chat window to open...');
    var chatReady = setInterval(function () {
        if ($(CHAT_CLASS).length) {
            clearInterval(chatReady);
            callback();
        }
    }, WAITING_INTERVAL);
}

function submitChatDetails() {
    console.log('Filling in form 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;

    $(".cx-submit.cx-btn.cx-btn-primary.i18n").trigger("click");
    listenPAULA();
}

function listenPAULA() {
    console.log('Having a word with the chat bot...');
    lastMsgText = '';

    msgListenerInterval = setInterval(function () {
        currMsgText = ''
        try {
            currMsgText = $(MESSAGE_CLASS).slice(-1)[0].textContent;
        } catch (e) {}

        response = PAULAResponses[currMsgText];

        if (CHATENDPROMPTS.indexOf(currMsgText) > -1) {
            console.log('Chat was ended, refreshing and trying again...');
            clearInterval(msgListenerInterval);
            reset();
            return;
        }

        if (currMsgText != lastMsgText && response != undefined) {
            sendMessage(response);
        }

        lastMsgText = currMsgText;
    }, MSG_WAITING_INTERVAL);
}

function sendMessage(msg) {
    msgTextArea = $('#cx_input');
    msgSendButton = $('div.cx-send.cx-icon.i18n');
    msgTextArea[0].value = msg;
    msgSendButton.trigger('click');
}

function reset() {
    location.reload();
}

function Main() {
    onOpenChatReady(function () {
        startChat();
        onChatReady(submitChatDetails);
    });
}

Main();
长期地址
遇到问题?请前往 GitHub 提 Issues。