// ==UserScript==
// @name Discuz BBS AutoReply
// @namespace https://greasyfork.org/zh-CN/users/208194-lz0211
// @version 2.00
// @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,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)
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()
}
//修改样式
function changeStyle(){
var plc = formDOM.querySelector('.plc'),
plcStyle = plc.style.cssText,
smilie = formDOM.querySelector('#fastsmiliesdiv'),
smilieStyle = smilie.style.cssText,
editor = formDOM.querySelector('#fastposteditor'),
editorStyle = editor.style.cssText,
state = 0
var scrollDOM = document.createElement('div')
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 version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve" 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 version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve" 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>'
var fastReply = scrollDOM.querySelector('a[title=快速回复]')
scrollDOM.style.zIndex = '999'
fastReply.href = 'javascript:;'
fastReply.onclick = function(){
if(state){
state = 0
plc.style.cssText = plcStyle
smilie.style.cssText = smilieStyle
editor.style.cssText = editorStyle
}else{
state = 1
plc.style.cssText = 'background-color:#fff;position:fixed;bottom:0px;right:0px;padding:5px;z-index:99;'
smilie.style.cssText = 'display:none'
editor.style.cssText = 'margin-right:40px'
}
}
}
init()
changeStyle()
})()