RaveEx

Customized UI for Rave

当前为 2019-07-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         RaveEx
// @version      0.6
// @description  Customized UI for Rave
// @author       leqin
// @match        https://rave.office.net/
// @match        https://rave.office.net/cases/*
// @grant        none
// @namespace    https://gf.qytechs.cn/users/318347
// ==/UserScript==

(function() {
    'use strict';
    //debugger;
    var NAME = 'RaveEx'
    var enabled = false
    var executed = false
    var tempHistoryItemDate = Date.MinValue

    var setFeature = function (featureName, enabled) {
        setCookie (NAME+'_'+featureName, enabled, 365)
    }
    var getFeature = function (featureName) {
        getCookie (NAME+'_'+featureName)
    }
    var getCookie = function (cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for(var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    var setCookie = function (cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays*24*60*60*1000));
        var expires = "expires="+ d.toUTCString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    }
    var addGlobalStyle = function addGlobalStyle(css) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        head.appendChild(style);
    }
    var unique = function (a) {
        var prims = {"boolean":{}, "number":{}, "string":{}}, objs = [];

        return a.filter(function(item) {
            var type = typeof item;
            if(type in prims)
                return prims[type].hasOwnProperty(item) ? false : (prims[type][item] = true);
            else
                return objs.indexOf(item) >= 0 ? false : objs.push(item);
        });
    }
    var executeOrDelayUntilConditionMeet = function (condition, callback) {
        setTimeout(function(){
            if (condition()) {
                callback();
            }else {
                executeOrDelayUntilConditionMeet(condition, callback);
            }
        }, 100);
    }
    var getCurrentUrlType = function () {
        var path = window.location.pathname;
        if (path.startsWith('/cases/unassigned')) {
            return 'unassigned'
        } else if (path.startsWith('/cases/my/')) {
            return 'my'
        } else {
            return 'case'
        }
    }
    var setHistoryItem = function (element) {
        var timeString = $(element).find('.chat-footer > .pull-right').first().text().trim()
        var time = Date.parse(timeString) || 0
        //var dateString = time.toLocaleDateString()
        $(element).before('<div class="menu-bar text-center" style="margin:0;height:auto"><h4>'+timeString+'</h4></div>')
    }
    var setCaseHistory = function () {
        $('case-history').find('[ng-repeat^="historyItem"]').each(function () {
            setHistoryItem(this)
        })
    }
    var addEmail = function (mails, newMails) {
        var mailAaray = mails ? mails.split(';') : []
        var newMailArray = newMails ? newMails.split(';') : []
        return unique(mailAaray.concat(newMailArray)).toString().replace(/,/g, ';');
    }
    var runCase = function () {
        var caseController = angular.element($('#breadcrumb')).data().$scope.caseController
        addGlobalStyle('.feedback-bar { display: none !important; }'); /*hide bottom float feedback bar*/
        addGlobalStyle('.absoluteLeftPane { display: none !important; }'); /*hide left float panel (customer profile, quick facts)*/
        addGlobalStyle('.absoluteRightPane { display: none !important; }'); /*hide right float panel*/
        addGlobalStyle('.floatingLeftPane { display: none !important; }'); /*hide left float panel (customer profile, quick facts)*/
        addGlobalStyle('#incorrect-user-div { display: none !important; }');
        addGlobalStyle('.chat-bubble-ViewMore { display: none !important; }');
        caseController.ShowFullCaseHistory()
        caseController.ShowNewerFirstCaseHistory()
        caseController.ExpandAllMessages()
        $('[ng-if^="comController.CommunicationData.ToEmailAddresses"]').hide()
        $('[ng-if^="comController.CommunicationData.CcEmailAddresses"]').hide()
        $('[ng-if^="comController.CommunicationData.Subject"]').hide()
        /*hide case attachments*/
        $('[ng-if^="caseController.CaseAttachments"]').hide()
        $('[ng-repeat^="attachment in caseController.CaseAttachments"]').hide()
        addGlobalStyle('.sync-attachment-btn { display: none !important; }');
        $('[ng-if^="comController.ShowAttachments"]').hide()
        $('[ng-repeat^="attachment in comController.CommunicationData.Attachments"]').hide()
        $('#editorSection').hide()
        $('#rightPane').hide()
        $('#centerPane').removeClass('col-xs-8').addClass('col-xs-10')
        $('.attachment-container').hide()
        if (!executed) {
            setCaseHistory()
            executed = true
        }
    }
    var runUnassigned = function () {

    }
    var run = function () {
        //debugger;
        switch(getCurrentUrlType()) {
            case 'unassigned':
                // code block
                break;
            case 'case':
                runCase()
                break;
            default:
                // code block
        }
    }
    var initialResponse = function () {
        var caseController = angular.element($('#breadcrumb')).data().$scope.caseController
        if (!caseController.IsAddingInternalNote) {
            if (!caseController.IsEmailCc) {
                caseController.ShowEmailCc()
            }
            var ownerName = caseController.AgentInfo.FullName
            var ownerEmail = caseController.AgentInfo.PartnerData.Email
            var tamEmail = caseController.TAMEmail
            var caseNumber = caseController.DefaultTicketSubject
            var contactName = caseController.Request.RequestData.UserFirstName+' '+caseController.Request.RequestData.UserLastName
            var title = caseController.appContext.SelectedRequest.RequestData.Title
            var description = caseController.appContext.SelectedRequest.RequestData.UserDescription
            var emailCc = caseController.EmailCc
            var subject = title ? title : description.slice(0,100)
            var irTemplate = '<div><span>Hello '+contactName+',<br></span><div><br></div><div>Thank you for contacting Microsoft Support. My name is '+ownerName+'. &nbsp;I am the Support Professional who will be working with you on this Service Request. You may reach me using the contact information listed below, referencing the '+caseNumber+'.<br></div><div><br></div><div>If you have any questions or concerns, please let me know. <br></div><div><br></div><div>Best Regards,<br></div><span></span><br></div>'
            caseController.EmailCc = addEmail(emailCc, ownerEmail+';'+tamEmail)
            caseController.EmailSubject ? null : (caseController.EmailSubject = subject)
            $('#emailComposeBox').prepend(irTemplate)
        }
    }
    var laborReminder = function () {
        var caseController = angular.element($('#breadcrumb')).data().$scope.caseController
        var historyController = angular.element($('[ng-if^="historyController.showFullHistory"]')).data().$scope.historyController
        var ownerId = historyController.appContext.PartnerData.PartnerId
    }
    var AddIssueDescriptionTag = function (tag) {
        var caseController = angular.element($('#breadcrumb')).data().$scope.caseController
        var issueDetails = caseController.RequestDetails.RequestDetailsData.IssueDetails
        caseController.RequestDetails.RequestDetailsData.IssueDetails = tag+' '+issueDetails
        //$('#issueDetails').val(tag+" "+$('#issueDetails').val());

    }
    window.RaveEx = {
        "run": run,
        "initialResponse": initialResponse,
        "tag": AddIssueDescriptionTag
    };
    executeOrDelayUntilConditionMeet(
        function () {
            return $('#header-dropdown-menu > ul') && $('#header-dropdown-menu > ul').length
        },
        function(){
            $('#header-dropdown-menu > ul').append('<li><div><a href="Javascript:RaveEx.run()" class="ng-scope">Review</a></div></li>')
        }
    )
    executeOrDelayUntilConditionMeet(
        function () {
            return $('#compose-email') && $('#compose-email').length
        },
        function(){
            $('#compose-email > div.panel-heading').append('<button class="btn btn-attach pull-right ng-scope" onclick="Javascript:RaveEx.initialResponse()"><span translate="" class="ng-scope">Initial Response</span></button>')
        }
    )
    executeOrDelayUntilConditionMeet(
        function () {
            return $('[name="caseController.issueDetailsForm"]') && $('[name="caseController.issueDetailsForm"]').length
        },
        function(){
            $('[name="caseController.issueDetailsForm"]').append(`<div class="form-group"><div class="row"><div class="col-sm-12"><label translate="" class="ng-scope">Tags</label></div></div><div class="row"><div class="col-sm-12"><span onclick="RaveEx.tag('#Pool Split')" title="SQL Resource constraint required rebalancing.">#Pool Split  </span><span onclick="RaveEx.tag('#Auto Resolved')" title="No known action taken.">#Auto Resolved  </span><span onclick="RaveEx.tag('#R/O Failover')" title="Farm was failed over to backup.">#R/O Failover  </span><span onclick="RaveEx.tag('#App Throttle')" title="High request volume application was throttled to restore service health.">#App Throttle  </span><span onclick="RaveEx.tag('#Azure Outage')" title="High impact event caused by factors outside of SharePoint Online.">#Azure Outage  </span><span onclick="RaveEx.tag('#Client Side')" title="Any case where the customer took action to resolve the bottleneck.">#Client Side  </span></div></div></div>`)
        }
    )
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址