RaveEx

Customized UI for Rave

目前为 2019-07-18 提交的版本。查看 最新版本

// ==UserScript==
// @name         RaveEx
// @version      0.3.1
// @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 waitUntilElementLoaded = function (element, callback) {
        setTimeout(function(){
            if ($(element).length > 0 && $(element).html != "") {
                callback();
            }else {
                waitUntilElementLoaded (element, 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 mailArray = mails.split(';').concat(newMails.split(';'));
        return unique(mailArray).toString().replace(/,/g, ';');
    }
    var runCase = function () {
        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; }');

        $('[ng-click^="caseController.CollapsedFilterDropdown"]').click()
        $('[ng-click^="caseController.ShowFullCaseHistory()"]').click()
        $('[ng-click^="caseController.CollapsedSortDropdown"]').click()
        $('[ng-click^="caseController.ShowNewerFirstCaseHistory()"]').click()
        $('[ng-click^="caseController.CollapsedCommunicationsDropdown"]').click()
        $('[ng-click^="caseController.ExpandAllMessages()"]').click()
        $('[ng-click^="caseController.CollapsedCommunicationsDropdown"]').click()
        $('[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 mail = function () {
        $('[ng-click^="caseController.ShowEmailCc()"]').click()
        var emailCc = $('input[name="emailCc"]').val()
        var tamEmail = $('#leftPane').find('div.footer-section:contains("TAM")').text().trim().replace('TAM:','').trim()
        var ownerEmail = $('rct-case-summary').find('a[href^="mailto"]').attr('href').replace('mailto:','').trim()
        $('input[name="emailCc"]').val(addEmail(emailCc,ownerEmail+';'+tamEmail))
    }

    window.RaveEx = {
        "run": run,
        "mail": mail
    };
    waitUntilElementLoaded('#header-dropdown-menu', function(){
        $('#header-dropdown-menu > ul').append('<li><div><a href="Javascript:RaveEx.run()" class="ng-scope">Review</a></div></li>')
    })
    waitUntilElementLoaded('#compose-email', function(){
        $('#compose-email > div.panel-heading').append('<button class="btn btn-attach pull-right ng-scope" onclick="Javascript:RaveEx.mail()"><span translate="" class="ng-scope">Fill</span></button>')
    })




})();

QingJ © 2025

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