This website requires JavaScript.

随笔

by  莫名丶恕  

slack指定消息触发自动回复脚本

/**
 * @description:
 * isAllowFun [Function] getAllow(name,time,text)
 * text [string]
 */
function sendMessage(isAllowFun,text){
    const flagStr = 'data-xxx-flag'
    setInterval(()=>{
        const msgReply = document.querySelector('.p-workspace__primary_view_footer .ql-editor')
        const msgSend = document.querySelector('.p-workspace__primary_view_footer .c-wysiwyg_container__suffix .c-button-unstyled')
        if (isAllowFun() && !msgReply.getAttribute(flagStr)) {
            msgReply.innerHTML = `<p>${text}</p>`
            msgReply.setAttribute(flagStr, 'true')
            setTimeout(()=>{
                msgSend.click()
            },300)
        }
    },1500)
}
/**
 * @description:
 * name [string] xxx
 * time [string] [晚上 8:40]
 * text [string]
 */
function getAllow(name,time,text){
    try {
        const domList = document.querySelectorAll(`[data-stringify-text="${name}"]`)
        const lastDom =domList[domList.length-1]
        const targetDom = lastDom.nextElementSibling
        const parentDom=targetDom.parentNode
        if(targetDom.getAttribute('data-stringify-text')>time && parentDom.innerText.includes(text)){
            return true
        }else {
            return false
        }
    }catch {
        return false
    }
}
sendMessage(()=>getAllow("xxx","[晚上 9:06]",'xxx'),`xxx`)
相关推荐