Greasy Fork

Greasy Fork is available in English.

Discuz BBS AutoReply

论坛快速回复脚本

当前为 2019-02-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Discuz BBS AutoReply
// @namespace    http://greasyfork.icu/zh-CN/users/208194-lz0211
// @version      2.10
// @description  论坛快速回复脚本
// @include      *://*game-*
// @include      *://*thread*
// @include      *://*forum.php*
// @include      *://bbs.*
// @include      *://www.lltxt.com/*
// @include      *://www.paipai.fm/*
// @include      *://muchong.com/*
// @include      *://www.3dmgame.com/*
// @exclude      *://*action=newthread*
// @license      MIT
// ==/UserScript==
(function(sites){
    sites = Object.assign({},sites, {
        'muchong.com':{
            formSelector:'#postcomment',
            inputSelector:'#replymessage',
            submitSelector:'#replysubmit',
            postBoxSelector:'.forum_Reply',
            smilieSelector:'td[align="right"]',
        },
        'www.3dmgame.com':{
            formSelector:'#Comments_wrap',
            inputSelector:'#Ct_content',
            submitSelector:'button.postbtn[onclick="ct_post()"]',
            postBoxSelector:'.Cs_postwrap',
            expressions:['[微笑]','[爱心]','[委屈]','[害羞]','[闭嘴]','[犯困]','[大哭]','[尴尬]','[生气]','[可爱]','[赞个]','[怀疑]','[汗]','[鄙视]','[呆]','[辣]','[坏笑]','[机智]','[晕]','[思考]'],
            style:function(){
                var timer = setInterval(function(){
                    var doms = document.querySelectorAll('.popFace');
                    if(doms.length > 0){
                        [].forEach.call(doms,function(dom){dom.style.right='160px'});
                        clearInterval(timer);
                    }
                },50)
            }
        },
        'www.galgamez.cc':{
            postBoxSelector:'.postcontent'
        },
        'www.lkong.net':{
            postBoxSelector:'.hasfsl'
        },
        'www.lltxt.com':{
            formSelector:'form[name="FORM"]',
            inputSelector:'textarea[name="atc_content"]',
            submitSelector:'input[name="Submit"]',
            postBoxSelector:'.f_one:nth-child(2)',
            smileName:'faces',
            addSmiles:function(obj){for(var k in obj) push.apply(expressions,obj[k].map(function(s){return '[s:'+s+']'}))}
        },
        'www.paipai.fm':{
            inherit:'www.lltxt.com',
            submitSelector:'button[name="Submit"]',
            postBoxSelector:'tr[class="vt"] > td:nth-child(2)',
        },
    });
    var url = document.URL,
        name = 'default',
        key = 'defaut_reply',
        formSelector = '#fastpostform',
        inputSelector = '#fastpostmessage',
        submitSelector = '#fastpostsubmit',
        postBoxSelector = '.plc',
        smilieSelector = '#fastsmiliesdiv',
        editorSelector = '#fastposteditor',
        smileName = 'smilies_array',
        expressions = ['。', '!', '……', '@~~~', '#^_^#', 'O(∩_∩)O~', '(*^__^*)', '└(^o^)┘', '‘(*>﹏<*)′ ~', '(@^_^@)~', '^_^o ~~~', 'O(∩_∩)O~∑', '(*@ο@*)', '((o(^_ ^)o))', '~@^_^@~ ', '(*∩_∩*)', '(~ o ~)~zZ ', '=^_^=', '~^o^~', '(*@?@*)', '*@_@*'],
        messages = ['顶楼主', '多谢楼主分享', '楼主辛苦了', '先回复一下', '看帖必回帖', '支持楼主分享', '后排围观', '路过打酱油的', '留名', '楼主写的真棒', '向楼主学习', '希望楼主发更多好帖', '楼主好人', '伸手党路过', 'Mark一下', '好贴,先收藏了', '抱走收藏,不客气了', '不错,支持卤煮', '楼主加油~~', '必须顶起', '好人一生平安','卤煮好厉害','潜水冒泡不说话'],
        interval = 15000,
        push = [].push,
        styleFn = function(){},
        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 getConfig(name){
        var site = sites[name]
        if(!site.inherit) return site
        return Object.assign({},getConfig(site.inherit),site)
    }
    function init(){
        var reg,site,k,randomBtn
        for(k in sites){
            site = getConfig(k)
            if(!site) break
            reg = new RegExp(site.match || k)
            if(reg.test(url)){
                name = k
                key = name + '_key'
                formSelector = site.formSelector || formSelector
                inputSelector = site.inputSelector || inputSelector
                submitSelector = site.submitSelector || submitSelector
                postBoxSelector = site.postBoxSelector || postBoxSelector
                smilieSelector = site.smilieSelector || smilieSelector
                editorSelector = site.editorSelector || editorSelector
                styleFn = site.style || styleFn
                smileName = site.smileName || smileName
                addSmiles = site.addSmiles || addSmiles
                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)
        //console.log(formDOM,inputDOM,submitDOM)
        randomBtn = submitDOM.cloneNode()
        randomBtn.innerHTML = '<strong>随机回复</strong>'
        randomBtn.value = '随机回复'
        randomBtn.type = 'button'
        randomBtn.name = 'random'
        randomBtn.style.display = 'inline'
        randomBtn.onclick = radomReplyText
        submitDOM.style.display = 'inline'
        submitDOM.parentNode.insertBefore(randomBtn,submitDOM)
        submitDOM.addEventListener('click',reply)
    }
    //表情
    function smiles(times){
        times = times || 0
        if(times > 20) return
        if(new Function('return typeof '+smileName)() === 'undefined') return setTimeout(function(){smiles(++times)},500)
        new Function('addSmiles','addSmiles('+smileName+')')(addSmiles)
    }
    function addSmiles(smilies_array){
        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]}))
            })
        })
    }
    //修改样式
    function changeStyle(){
        var plc = formDOM.querySelector(postBoxSelector),
            smilie = formDOM.querySelector(smilieSelector),
            editor = formDOM.querySelector(editorSelector),
            plcStyle = plc && plc.style.cssText,
            smilieStyle = smilie && smilie.style.cssText,
            editorStyle = editor && editor.style.cssText,
            state = 0
        var scrollDOM = document.createElement('div')
        console.log(plc,smilie,editor)
        function switchStyle(){
            if(state){
                state = 0
                plc && (plc.style.cssText = plcStyle)
                smilie && (smilie.style.cssText = smilieStyle)
                editor && (editor.style.cssText = editorStyle)
            }else{
                state = 1
                plc && (plc.style.cssText = 'background-color:#fff;position:fixed;bottom:0px;right:0px;padding:5px;z-index:99;margin-right:0px;')
                smilie && (smilie.style.cssText = 'display:none')
                editor && (editor.style.cssText = 'margin-right:40px')
            }
        }
        document.body.appendChild(scrollDOM)
        scrollDOM.style.cssText = 'left:auto;right:0px;visibility:visible;position:fixed;bottom:40px;display:block;margin:-30px 0 0 2px;width:40px;background:#f4f4f4;border:1px #cdcdcd solid;border-radius:3px;border-top:0;cursor:pointer;word-wrap:break-word;'
        scrollDOM.innerHTML = '<a title="快速回复" style="display:block;width:30px;height:24px;padding:3px 5px;line-height:12px;text-align:center;color:#787878;text-decoration:none;border-top:1px #cdcdcd solid;background:none;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" style="height:20px;margin-top:2px"><path d="M850,80H150C73,80,10,143,10,220v420c0,77,63,140,140,140h70v140h70l140-140h420c77,0,140-63,140-140V220C990,143,927,80,850,80z M290,500c-42,0-70-28-70-70c0-42,28-70,70-70c42,0,70,28,70,70C360,472,332,500,290,500z M500,500c-42,0-70-28-70-70c0-42,28-70,70-70c42,0,70,28,70,70C570,472,542,500,500,500z M710,500c-42,0-70-28-70-70c0-42,28-70,70-70s70,28,70,70C780,472,752,500,710,500z" style="fill:#a9b7b7"></path></svg></a><a title="返回顶部" onclick="window.scrollTo(0,0)" style="display:block;width:30px;height:24px;padding:3px 5px;line-height:12px;text-align:center;color:#787878;text-decoration:none;border-top:1px #cdcdcd solid;background:none;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" style="height:20px;margin-top:2px"><path d="M319.3,783.7h361.1v77.3H319.3V783.7z" style="fill:#a9b7b7"></path><path d="M319.3,938.4h361.1V990H319.3V938.4z" style="fill:#a9b7b7"></path><path d="M319.3,216.3h361.1v490H319.3V216.3z" style="fill:#a9b7b7"></path><path d="M500,10l438.4,464.4H61.5L500,10z" style="fill:#a9b7b7"></path></svg></a></div>'
        scrollDOM.style.zIndex = '999'
        var fastReply = scrollDOM.querySelector('a[title=快速回复]')
        fastReply.href = 'javascript:;'
        fastReply.onclick = switchStyle
        //switchStyle()
    }
    init()
    smiles(0)
    changeStyle()
    styleFn()
})()