Skip to content

Instantly share code, notes, and snippets.

@SukkaW
Created July 4, 2020 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SukkaW/4565c3f2f556d0edde6ae7d4ea264fb7 to your computer and use it in GitHub Desktop.
Save SukkaW/4565c3f2f556d0edde6ae7d4ea264fb7 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name 远景资讯自动回复
// @namespace http://tampermonkey.net/
// @version 0.5
// @description try to take over the world!
// @author Sukka
// @include http://www.pcbeta.com/viewnews*.html
// @include http://www.pcbeta.com/portal.php?mod=view&aid=*
// @grant none
// ==/UserScript==
(function() {
const randomNumber = num => {
const today = new Date();
let seed = today.getTime();
function rnd(){
seed = ( seed * 9301 + 49297 ) % 233280;
return seed / ( 233280.0 );
};
return Math.ceil(rnd(seed) * num);
};
const randomPost = () => {
return `http://www.pcbeta.com/viewnews-${randomNumber(6000)}-1.html`;
}
const sleep = (s) => {
return new Promise(resolve => setTimeout(resolve, s * 1000));
}
const date = new Date();
const todayStr = date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + (date.getDate() + 1) + '日,回来看看老新闻';
const randomMsg = () => {
const msgArray = [
'打酱油,不表态',
'看看老新闻也挺有意思',
'路过,看看,挖个坟',
'会员观点不代表远景论坛官方立场',
'远景因你们而精彩',
'支持远景,科技创新',
'#远景因你们而精彩#',
'时代太快了,我都感慨我老的太快了',
'祝论坛以及全部景友身体健康',
'希望祖国越来越强盛,远景论坛越来越棒',
'加油!相信这是一个美好的开端~',
'路过,看看老文章',
'仍旧怀以感激,希望日后仍有机会在论坛内歌舞升平',
'行前应思,行前必思,行前唯思。',
'这个还真有点意思',
'大千世界勿流连,还是远景好',
'感謝分享最新資訊',
'这个是没有办法的办法',
'蒹葭苍苍,白露为霜。所谓伊人,在水一方',
'咋没人给这货头上倒瓶矿泉水',
'不以物喜 不以己悲',
'大浪淘沙始见金',
'纯净、和谐的技术交流平台',
todayStr
];
return msgArray[parseInt(randomNumber(msgArray.length) - 1)];
}
const postReply = async (num) => {
if (document.getElementById('message')) {
console.log(`今天已经回复了 ${num} 条`);
await sleep(1);
const msg = randomMsg();
document.getElementById('message').value = msg;
console.log(`即将回复的消息是:${msg}`);
console.log(`回复将在 10 秒后发送!`);
for (let i = 10; i > 0; i--) {
document.title = '(' + num + '/50) - ' + i + ': ' + msg;
if (document.hidden) {
await sleep(0.6);
} else {
await sleep(1);
}
}
localStorage.setItem('sukka_post_num', num + 1);
await sleep(1);
document.getElementById('commentsubmit_btn').click();
} else {
console.log('当前页面不可回复!可能已被删除,正在重新跳转...');
document.title = '当前页面不可回复!';
await sleep(0.5);
window.location.href = randomPost();
}
}
const main = async () => {
if (window.location.href.includes('www.pcbeta.com/portal.php?mod=view&aid=')) {
console.log('当前的资讯页面不满足 viewnews URL 格式,跳转中...');
await sleep(1);
window.location.href = randomPost();
} else if (window.location.href.includes('http://www.pcbeta.com/viewnews-')) {
const num = parseInt(localStorage.getItem('sukka_post_num')) || 0;
if (num < 50) {
await postReply(num);
} else {
document.title = '已经刷到上限了!';
if (window.confirm('已经刷到上限啦!真的要继续刷嘛?')) {
localStorage.setItem('sukka_post_num', 0);
await sleep(0.5);
window.location.href = randomPost();
}
}
}
}
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment