【油猴脚本】Discuz!论坛发回帖数限制倒计时
本帖最后由 Velens 于 2023-10-8 23:32 编辑工作之余经常在论坛发表文章,几乎每个论坛都会开启灌水预防功能,但是没有插件显示下次发回帖时间,定闹钟或者记事本又太过麻烦,于是通过油猴脚本显示回复限制倒计时。
功能介绍:
开启功能开关菜单,配置自动存储读取
1、设置每小时发回帖数限制(全局)
2、到点系统通知提醒(全局)
3、提供4个自定地址
显示回复限制倒计时,点击倒计时按钮可在当前页面开关通知提醒
自定地址优先于全局设置,可单独设置不同论坛的每小时发回帖数限制
脚本安装:
油猴脚本安装地址:Discuz!,https://greasyfork.org/zh-CN/scripts/476968
截图展示:
脚本代码:
// ==UserScript==
// @name Discuz!
// @Icon https://www.discuz.vip/favicon.ico
// @namespace https://greasyfork.org/users/878514
// @version 20231008
// @description设置每小时发回帖数限制,显示回复限制倒计时,到点系统通知提醒,提供4个自定地址,配置持久化
// @AuThor Velens
// @match *://*/forum.php*
// @match *://*/forum-*.html
// @match *://*/thread-*.html
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @license MIT
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
// @grant GM_notification
// @grant GM_xmlhttpRequest
// @connect *
// ==/UserScript==
/* globals jQuery, $, waitForKeyElements */
let tieshu = GM_getValue("tieshu",0),tieshuMenu = tieshu;
let flagNotice = GM_getValue("flagNotice",false),flagNoticenow = false,flagNoticeMenu;
let baseHref = $("base").attr("href");
let baseTitle = baseHref.replace(/(http|https):\/\//,"").replace(/\//,"");
let tieshu1 = GM_getValue("tieshu1"),tieshuMenu1 = tieshu1,baseHref1 = GM_getValue("baseHref1"),baseTitle1;
let tieshu2 = GM_getValue("tieshu2"),tieshuMenu2 = tieshu2,baseHref2 = GM_getValue("baseHref2"),baseTitle2;
let tieshu3 = GM_getValue("tieshu3"),tieshuMenu3 = tieshu3,baseHref3 = GM_getValue("baseHref3"),baseTitle3;
let tieshu4 = GM_getValue("tieshu4"),tieshuMenu4 = tieshu4,baseHref4 = GM_getValue("baseHref4"),baseTitle4;
if(tieshu == 0){tieshuMenu = "关闭"};
GM_registerMenuCommand("贴数限制:" + tieshuMenu,tieShu)
function tieShu(){
tieshu = prompt("请输入每小时发回帖数限制(关闭:0)", GM_getValue("tieshu"));
if(tieshu != null && tieshu >= 0 && Number.isInteger(Number(tieshu)) && tieshu != GM_getValue("tieshu")){
GM_setValue("tieshu",tieshu);
location.reload();}
else{tieshu = GM_getValue("tieshu");}
};
if(flagNotice){flagNoticeMenu = "开启"}
else{flagNoticeMenu = "关闭"};
GM_registerMenuCommand("到点提醒:" + flagNoticeMenu,flagNoticef)
function flagNoticef(){
flagNotice = !GM_getValue("flagNotice");
GM_setValue("flagNotice",flagNotice);
location.reload();
};
if(tieshu1 == 0){tieshuMenu1 = "关闭"}
if(!baseHref1){baseTitle1 = "网址";tieshuMenu1 = "帖数"}
else{baseTitle1 = baseHref1.replace(/(http|https):\/\//,"").replace(/\//,"")};
GM_registerMenuCommand("自定1:" + baseTitle1 + "," + tieshuMenu1,baseHref1f)
function baseHref1f(){
baseHref1 = $("base").attr("href");
tieshu1 = prompt("请输入每小时发回帖数限制(关闭:0)", tieshu1);
if(tieshu1 != null && tieshu1 >= 0 && Number.isInteger(Number(tieshu1)) && tieshu1 != GM_getValue("tieshu1")){
GM_setValue("tieshu1",tieshu1);
location.reload();}
else{
tieshu1 = GM_getValue("tieshu1");
if(baseHref1 != GM_getValue("baseHref1")){location.reload();}}
GM_setValue("baseHref1",baseHref1);
};
if(tieshu2 == 0){tieshuMenu2 = "关闭"}
if(!baseHref2){baseTitle2 = "网址";tieshuMenu2 = "帖数"}
else{baseTitle2 = baseHref2.replace(/(http|https):\/\//,"").replace(/\//,"")};
GM_registerMenuCommand("自定2:" + baseTitle2 + "," + tieshuMenu2,baseHref2f)
function baseHref2f(){
baseHref2 = $("base").attr("href");
tieshu2 = prompt("请输入每小时发回帖数限制(关闭:0)", tieshu2);
if(tieshu2 != null && tieshu2 >= 0 && Number.isInteger(Number(tieshu2)) && tieshu2 != GM_getValue("tieshu2")){
GM_setValue("tieshu2",tieshu2);
location.reload();}
else{
tieshu2 = GM_getValue("tieshu2");
if(baseHref2 != GM_getValue("baseHref2")){location.reload();}}
GM_setValue("baseHref2",baseHref2);
};
if(tieshu3 == 0){tieshuMenu3 = "关闭"}
if(!baseHref3){baseTitle3 = "网址";tieshuMenu3 = "帖数"}
else{baseTitle3 = baseHref3.replace(/(http|https):\/\//,"").replace(/\//,"")};
GM_registerMenuCommand("自定3:" + baseTitle3 + "," + tieshuMenu3,baseHref3f)
function baseHref3f(){
baseHref3 = $("base").attr("href");
tieshu3 = prompt("请输入每小时发回帖数限制(关闭:0)", tieshu3);
if(tieshu3 != null && tieshu3 >= 0 && Number.isInteger(Number(tieshu3)) && tieshu3 != GM_getValue("tieshu3")){
GM_setValue("tieshu3",tieshu3);
location.reload();}
else{
tieshu3 = GM_getValue("tieshu3");
if(baseHref3 != GM_getValue("baseHref3")){location.reload();}}
GM_setValue("baseHref3",baseHref3);
};
if(tieshu4 == 0){tieshuMenu4 = "关闭"}
if(!baseHref4){baseTitle4 = "网址";tieshuMenu4 = "帖数"}
else{baseTitle4 = baseHref4.replace(/(http|https):\/\//,"").replace(/\//,"")};
GM_registerMenuCommand("自定4:" + baseTitle4 + "," + tieshuMenu4,baseHref4f)
function baseHref4f(){
baseHref4 = $("base").attr("href");
tieshu4 = prompt("请输入每小时发回帖数限制(关闭:0)", tieshu4);
if(tieshu4 != null && tieshu4 >= 0 && Number.isInteger(Number(tieshu4)) && tieshu4 != GM_getValue("tieshu4")){
GM_setValue("tieshu4",tieshu4);
location.reload();}
else{
tieshu4 = GM_getValue("tieshu4");
if(baseHref4 != GM_getValue("baseHref4")){location.reload();}}
GM_setValue("baseHref4",baseHref4);
};
if(baseHref == baseHref1){tieshu = tieshu1};
if(baseHref == baseHref2){tieshu = tieshu2};
if(baseHref == baseHref3){tieshu = tieshu3};
if(baseHref == baseHref4){tieshu = tieshu4};
if($("#g_upmine").text() && tieshu != 0){
var numPage = Math.ceil(tieshu/20);
GM_xmlhttpRequest({
method: "get",
url: baseHref + "home.php?mod=space&do=thread&view=me&type=reply&from=space&page=" + numPage,
onload: function(resHome) {
const pid = resHome.responseText.match(/ptid=\d+&pid=\d+/g);
if(pid.length >= tieshu - 20*(numPage-1) && tieshu > 0){
const pidNum= pid.map(value => value.match(/\d+/g));
let i = 0,j = 0,t;
for ( i = 0; i < pidNum.length; i++){
for (j = 0; j < pidNum.length; j++){
if (pidNum > pidNum){
t = pidNum;
pidNum = pidNum;
pidNum = t;
}}}
const pidNew = pidNum;
GM_xmlhttpRequest({
method: "get",
url: baseHref + "forum.php?mod=redirect&goto=findpost&ptid=" + pidNew + "&pid=" + pidNew,
onload: function(resTime) {
let pidIndex = resTime.responseText.indexOf("authorposton" + pidNew);
let pidTime = resTime.responseText.substring(pidIndex+21,pidIndex+80);
pidTime = pidTime.match(/\d+-\d+-\d+ \d+:\d+/);
var pidTimestamp = Date.parse(pidTime) + 3600000;
var nowTime = Date.now();
var waitTime = Math.ceil((pidTimestamp - nowTime)/60000);
if(waitTime > 0){
var buttonTime = "<button class='limitTime'></button>";
$("body").append(buttonTime);
$('.limitTime').click(function () {
if(flagNotice){flagNotice = false;}
else{flagNoticenow = !flagNoticenow;}
if(flagNotice || flagNoticenow){GM_addStyle(`.limitTime{border: 2px solid #00FF00;}`);}
else{GM_addStyle(`.limitTime{border: 2px solid #444;}`);}
})
$(".limitTime").attr("title", "每小时发回帖数限制 " + tieshu + "\n发表于 " + pidTime);
$(".limitTime").text("回复限制 " + waitTime + " 分钟");
if(flagNotice || flagNoticenow){GM_addStyle(`.limitTime{border: 2px solid #00FF00;}`);}
else{GM_addStyle(`.limitTime{border: 2px solid #444;}`);}
GM_addStyle(`.limitTime{position:fixed;top:163px;right:0px;white-space:pre-wrap;opacity:0.8;border-radius:10px;}`);
var myVar = setInterval(waitVar, 10000);}
function waitVar(){
var nowTime = Date.now();
var waitTime = Math.ceil((pidTimestamp - nowTime)/60000);
if(waitTime > 0){
$(".limitTime").text("回复限制 " + waitTime + " 分钟");
}else{
clearInterval(myVar);
GM_addStyle(`.limitTime{display:none;}`);
if(flagNotice || flagNoticenow){
flagNotice = false;
flagNoticenow = false;
GM_notification({title: baseTitle,text:"每小时发回帖数限制已解除",image:baseHref + "favicon.ico"});}
}
}
}
})
}}
});
}
回个帖支持一下 厉害,偶要是会写就好了。 这个我能用到{:1_907:} 感谢分享 感谢感谢啊 可以可以,水贴必备,有些论坛就得倒数3分钟或者10分钟 感谢分享,用了