UseDesk Button

Usedesk QoL improvments

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         UseDesk Button
// @namespace    http://tampermonkey.net/
// @version      1.3.2
// @description  Usedesk QoL improvments
// @author       Jonty
// @match        https://www.tampermonkey.net/index.php?version=4.13.6138&ext=iikm&updated=true
// @icon         https://bcg-hub.herokuapp.com/static/extension%20logo.jpg
// @grant        none
// @include      https://secure.usedesk.ru/tickets/*
// ==/UserScript==

var sender;

(function() {
    'use strict';

    // Your code here...
	var counterBtn = 0;
	var counterTxt = 0;
    var payload;
    var attachment = '';

    function postDataToWebhook(data, author, theme, email, attachment){
        //url to webhook
        const webHookUrl="https://bcg-hub.herokuapp.com/usedeskresender";
        //https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
        var oReq = new XMLHttpRequest();
        var myJSONStr = payload ={
            "origin": "*",
            "text": data,
            "theme": theme,
            "author": author,
            "mail": email,
            "attach": attachment,
        };

        //register method called after data has been sent method is executed
        oReq.addEventListener("load", reqListener);
        oReq.open("POST", webHookUrl, true);
        oReq.setRequestHeader('Content-Type', 'application/json');
        oReq.send(JSON.stringify(myJSONStr));
    }

    function respResult(id, resp, name){
        //url to webhook
        const webHookUrl="https://bcg-hub.herokuapp.com/autoreplyhandler";
        //https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
        var oReq = new XMLHttpRequest();
        var myJSONStr = payload ={
            "origin": "*",
            "id": id,
            "result": resp,
            "name": name,
        };

        //register method called after data has been sent method is executed
        oReq.addEventListener("load", reqListener);
        oReq.open("POST", webHookUrl, true);
        oReq.setRequestHeader('Content-Type', 'application/json');
        oReq.send(JSON.stringify(myJSONStr));
    }

    //callback method after webhook is executed
    function reqListener () {
        console.log(this.responseText);
    }

    let txt = document.querySelectorAll('.horizontal-scroll');
	txt.forEach(function(userItem) {
		userItem.setAttribute('id', 'txt' + counterTxt);
		counterTxt += 1;
	});

	let div = document.querySelectorAll('.rating');
	div.forEach(function(userItem) {
		let btn = userItem.parentNode;
  		btn.innerHTML += '<div class="mail-sender" style="width: 130px; padding: 0px; padding-right: 10px; vertical-align: middle;"><button id=' + counterBtn + ' onclick="sender(this.id)" class="btn-helper" style="border-radius: 3px; border: 1px solid transparent; padding: 6px; width: 130px; background-color: #00a651; color: #ffffff">Отправить в HR чат</button></div>';
		counterBtn += 1;
    });

    /*Тест окончен
    let id = window.location.href.slice(34)
    let comCheckTextDiv = document.querySelectorAll('.mail-text-private');
    comCheckTextDiv.forEach(function(userItem) {
        let comCheckTestStr = 'Рекомендуемый ответ';
        if (userItem.textContent.indexOf(comCheckTestStr) > 0) {
            let comCheckBtnPlace = userItem.previousSibling.previousSibling.firstChild.nextSibling.insertAdjacentHTML("afterend", '<div class="mail-sender" style="width:600px; padding:0px; padding-right:10px; padding-bottom:10px; vertical-align:middle; display:inline-block;"><p id="respQ">Подходящий вариант имени?</p><button id="good '+id+'" class="btn-success btn" onclick="resp(this.id)">Хорошо</button><button id="bad '+id+'" class="btn-danger btn" onclick="resp(this.id)">Плохо</button></div>');
            console.log(comCheckBtnPlace);
        }
    });

    window.resp = function (btnID) {
        let preTicketID = btnID;
        let ticketID = preTicketID.slice(-8);
        let result = preTicketID.slice(0, -8);
        console.log(result);
        let sourceBlock = document.getElementById(btnID).parentNode.parentNode.nextSibling.nextSibling.textContent;
        let re = /Добрый день, (.*)!/g;
        let name = sourceBlock.match(re)[0];
        respResult(ticketID, result, name);
    };
    */


    window.sender = function (btnID) {
        let textID = 'txt' + btnID;
        let message = document.getElementById(textID).innerHTML;
        let parentOfBtn = document.getElementById(btnID).parentNode;
        let parentOfPOB = parentOfBtn.parentNode.innerHTML;
        let preMail = document.getElementsByClassName('change-contact');
        let mail = preMail[0].getAttribute('data-value');
        //let childOfCOPOPOB = childOfPOPOB.;

        let theme = document.getElementsByClassName('ticket-title')[0].textContent

        let parentOfMsg = document.getElementById(textID).parentNode;
        let potentialAttach = parentOfMsg.nextElementSibling;
        console.log(potentialAttach);
        if (potentialAttach != null) {
            if (potentialAttach.className === 'mail-attachments  ') {
                let attach = potentialAttach.querySelectorAll('.attach-image-link');
                attach.forEach(function(userItem) {
                    let attachmentLink = userItem.getAttribute('href');
                    attachment += attachmentLink + '\n';
                });
            }
        }

        console.log(message);
        console.log(mail);
        console.log(attachment);
        console.log(theme);
        postDataToWebhook(message, parentOfPOB, theme, mail, attachment);
        attachment = '';
    };

    function blockRemover () {
        let stringCheck = "D2D ID";
        let checker = 0
        let targetMessage = document.getElementsByClassName('mail-text');
        for (let text_block of targetMessage) {
            if (text_block.textContent.indexOf(stringCheck) > 0) {
                checker++;
            }
        }
        console.log(checker)
        if (checker == 0) {
            let block = document.querySelector('[data-block-id="9912"]');
            block.remove();
        }
    }

    window.onload = blockRemover;
})();