lorrylockie / CCO 文档签名内容填充

// ==UserScript==
// @name         CCO 文档签名内容填充
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       lorrylockie
// @license MIT
// @match        https://*.taobao.com/app/xspace/mail-signature/index.html
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const $ = document.querySelector.bind(document);
    window.tcallback = function(res){
        if(res && res.content && res.content.userList.length > 0){
            let v = res.content.userList[0];
            $('#ms-nickname span').innerText = v.nickNameCn;
            $('#ms-realname span').innerText = v.name;
            $('#ms-department span').innerText = v.deptDesc.replace(/.*-CCO技术部-/g,'');
            $('#ms-mobile span').innerText = v.officePhone;
            $('#ms-title span').innerText = v.jobDesc;
            $('#ms-email span').innerText = v.email;
        }
    }

    function jsonp(name){
        if(!name) return;
        const script = document.createElement('script') ;
        script.src="https://work.alibaba-inc.com/work/xservice/sns/suggestion/suggestionAt.jsonp?callback=tcallback&key="+encodeURIComponent(name);
        document.body.appendChild(script);
    }

    const input = $('#ms-nickname span');
    const obs = new MutationObserver(function(mutations, observer){
        setTimeout(()=>{
            jsonp(input.innerText);
        },200);
    })
    obs.observe(input, { childList:true });
})();