吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3321|回复: 57
收起左侧

[其他原创] 【油猴脚本】Discuz!论坛发回帖数限制倒计时

  [复制链接]
Velens 发表于 2023-10-8 23:02
本帖最后由 Velens 于 2023-10-8 23:32 编辑

工作之余经常在论坛发表文章,几乎每个论坛都会开启灌水预防功能,但是没有插件显示下次发回帖时间,定闹钟或者记事本又太过麻烦,于是通过油猴脚本显示回复限制倒计时。


功能介绍:
开启功能开关菜单,配置自动存储读取
1、设置每小时发回帖数限制(全局)
2、到点系统通知提醒(全局)
3、提供4个自定地址
显示回复限制倒计时,点击倒计时按钮可在当前页面开关通知提醒
自定地址优先于全局设置,可单独设置不同论坛的每小时发回帖数限制


脚本安装:
油猴脚本安装地址:Discuz!,
https://greasyfork.org/zh-CN/scripts/476968


截图展示:
1.jpg

2.jpg



脚本代码:
[Java] 纯文本查看 复制代码
// ==UserScript==
// [url=home.php?mod=space&uid=170990]@name[/url]         Discuz!
// [url=home.php?mod=space&uid=593100]@Icon[/url]         https://www.discuz.vip/favicon.ico
// [url=home.php?mod=space&uid=467642]@namespace[/url]    https://greasyfork.org/users/878514
// [url=home.php?mod=space&uid=1248337]@version[/url]      20231008
// @description  设置每小时发回帖数限制,显示回复限制倒计时,到点系统通知提醒,提供4个自定地址,配置持久化
// [url=home.php?mod=space&uid=686208]@AuThor[/url]       Velens
// [url=home.php?mod=space&uid=195849]@match[/url]        *://*/forum.php*
// @match        *://*/forum-*.html
// @match        *://*/thread-*.html
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @license      MIT
// [url=home.php?mod=space&uid=609072]@grant[/url]        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[i][1] > pidNum[j][1]){
                            t = pidNum[i];
                            pidNum[i] = pidNum[j];
                            pidNum[j] = t;
                        }}}
                const pidNew = pidNum[tieshu - 20*(numPage-1)-1];
                GM_xmlhttpRequest({
                    method: "get",
                    url: baseHref + "forum.php?mod=redirect&goto=findpost&ptid=" + pidNew[0] + "&pid=" + pidNew[1],
                    onload: function(resTime) {
                        let pidIndex = resTime.responseText.indexOf("authorposton" + pidNew[1]);
                        let pidTime = resTime.responseText.substring(pidIndex+21,pidIndex+80);
                        pidTime = pidTime.match(/\d+-\d+-\d+ \d+:\d+/)[0];
                        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"});}
                            }
                        }
                    }
                })
            }}
    });
}

免费评分

参与人数 15吾爱币 +21 热心值 +14 收起 理由
onedayday-wb + 2 我很赞同!
不如相忘于江湖 + 1 谢谢@Thanks!
wushaominkk + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
cangou + 1 + 1 用这个水贴会不会被罚呢?
tanjihu + 1 + 1 我很赞同!
尹铭 + 1 + 1 谢谢@Thanks!
wydangie + 1 + 1 鼓励转贴优秀软件安全工具和文档!
benmagic + 1 + 1 谢谢@Thanks!
lyh122 + 1 + 1 我很赞同!
zzhaoxue + 1 + 1 热心回复!
461735945 + 1 + 1 用心讨论,共获提升!
cartersun + 1 + 1 热心回复!
zpolar + 1 + 1 热心回复!
qqycra + 1 + 1 我很赞同!
为之奈何? + 1 + 1 我很赞同!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

hk9186 发表于 2023-10-9 03:10
回个帖支持一下
头像被屏蔽
xiliang 发表于 2023-10-9 06:25
qdhjysd 发表于 2023-10-9 06:54
头像被屏蔽
southerlywindly 发表于 2023-10-9 07:23
提示: 该帖被管理员或版主屏蔽
qqycra 发表于 2023-10-9 07:34
这个我能用到
lcx02008 发表于 2023-10-9 07:39
感谢分享
yunshang518 发表于 2023-10-9 07:50
感谢感谢啊
披星代月 发表于 2023-10-9 07:53
可以可以,水贴必备,有些论坛就得倒数3分钟或者10分钟
cxx0515 发表于 2023-10-9 08:07
感谢分享,用了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-21 21:38

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表