Discuz BBS AutoReply

论坛快速回复脚本

目前為 2018-10-31 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Discuz BBS AutoReply
// @namespace    https://greasyfork.org/zh-CN/users/208194-lz0211
// @version      1.0
// @description  论坛快速回复脚本
// @match        *://bbs.*/*thread*
// @match        *://*thread*
// @include      *://bbs.*/*thread*
// @include      *://*thread*
// @exclude      *://*action=newthread*
// @license      MIT
// ==/UserScript==
(function(sites){
    sites = sites || {}
    var url = document.URL,
        name = 'default',
        key = 'defaut_reply',
        formSelector = '#fastpostform',
        inputSelector = '#fastpostmessage',
        submitSelector = '#fastpostsubmit',
        expressions = ['。', '!', '……', '@~~~', '#^_^#', 'O(∩_∩)O~', '(*^__^*)', '└(^o^)┘', '‘(*>﹏<*)′ ~', '(@^_^@)~', '^_^o ~~~', 'O(∩_∩)O~∑', '(*@ο@*)', '((o(^_ ^)o))', '~@^_^@~ ', '(*∩_∩*)', '(~ o ~)~zZ ', '=^_^=', '~^o^~', '(*@?@*)', '*@_@*'],
        messages = ['顶楼主', '多谢楼主分享', '楼主辛苦了', '先回复一下', '看帖必回帖', '支持楼主分享', '后排围观', '路过打酱油的', '留名', '楼主写的真棒', '向楼主学习', '希望楼主发更多好帖', '楼主好人', '伸手党路过', 'Mark一下', '好贴,先收藏了', '抱走收藏,不客气了', '不错,支持卤煮', '楼主加油~~', '必须顶起', '好人一生平安','卤煮好厉害','潜水冒泡不说话'],
        interval = 15000,
        push = [].push,
        formDOM,inputDOM,submitDOM
    //随机返回数组元素
    function randomSelect(array){
        return array[Math.floor(Math.random() * array.length)]
    }
    //生成随机回复
    function radomReplyText(){
        var a = randomSelect(messages)
        var b = randomSelect(messages)
        var c = randomSelect(expressions)
        while (a == b) {
            b = randomSelect(messages)
        }
        var text = a + b + c
        inputDOM.value = inputDOM.innerText = text;
    }
    function now(){
        return Date.now()
    }
    function reply(){
        if (localStorage.getItem(key) < now() - interval || !localStorage.getItem(key)) {
            localStorage.setItem(key, now())
        } else {
            console.log("距离上次回复时间不足15秒,请勿频繁灌水,以免被封!")
            alert("距离上次回复时间不足15秒,请勿频繁灌水,以免被封!")
        }
    }
    //初始化
    function init(){
        var reg,site,k,formStyle,height,body,randomBtn,times = 0
        for(k in sites){
            site = sites[name]
            if(!site || !site.match) break
            reg = new RegExp(site.match)
            if(reg.test(url)){
                name = k
                key = name + '_key'
                formSelector = site.formSelector || formSelector
                inputSelector = site.inputSelector || inputSelector
                submitSelector = site.submitSelector || submitSelector
                interval = site.interval || interval
                Array.isArray(site.expressions) && push.apply(expressions,site.expressions)
                Array.isArray(site.messages) && push.apply(messages,site.messages)
                break
            }
        }
        formDOM = document.querySelector(formSelector)
        inputDOM = document.querySelector(inputSelector)
        submitDOM = document.querySelector(submitSelector)
        formStyle = formDOM.style.cssText
        height = formDOM.offsetHeight
        formDOM.style.cssText = formStyle + ';background-color:#fff;position:fixed;bottom:0px;'
        body = document.querySelector('body')
        body.style.cssText = body.style.cssText + 'margin-bottom:' + height + 'px'
        randomBtn = submitDOM.cloneNode()
        randomBtn.innerHTML = '<strong>随机回复</strong>'
        randomBtn.type = 'button'
        randomBtn.onclick = radomReplyText
        submitDOM.parentNode.insertBefore(randomBtn,submitDOM)
        submitDOM.addEventListener('click',reply)
        function smiles(){
            if(times > 20) return
            if(typeof smilies_array === 'undefined'){
                times += 1
                return setTimeout(smiles,500)
            }
            if(!Array.isArray(smilies_array)) return
            smilies_array.forEach(function(group){
                if(!Array.isArray(group)) return
                group.forEach(function(page){
                    if(!Array.isArray(page)) return
                    push.apply(expressions,page.map(function(arr){return arr[1]}))
                })
            })
        }
        smiles()
    }
    init()
})()