Greasy Fork

Greasy Fork is available in English.

98手机网页一键评分

修改帖子底部的评分按钮,实现自动评分

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         98手机网页一键评分
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  修改帖子底部的评分按钮,实现自动评分
// @author       bbbyqq
// @match        *://*/forum.php?mod=viewthread*
// @license      bbbyqq
// @grant        GM_addStyle
// ==/UserScript==

(function () {
    'use strict'

    if (document.querySelector('#thread_btn_bar .btn:nth-child(4) span')?.innerText === '评分') {
      document.querySelector('#thread_btn_bar .btn:nth-child(4) span').innerText = '一键评分'
    }

    if (document.querySelector('#thread_btn_bar .btn:nth-child(4) span')?.innerText.includes('评分')) {
      // 为一键评分按钮添加点击事件
      document.querySelector('#thread_btn_bar .btn:nth-child(4)').addEventListener('click', function () {
        let attempts = 0
        let maxAttempts = 200
        let interval = setInterval(() => {
          const scoreElement = document.querySelector('#ntcmsg_popmenu #score8')
          // 元素存在,获取评分区间最大值,进行赋值操作
          if (scoreElement) {
            clearInterval(interval)
            scoreElement.value = Number(document.querySelector('#ntcmsg_popmenu table tr:nth-child(2) td:nth-child(3)').innerText.replace(/[^\d]/g, ''))
            document.querySelector('#ntcmsg_popmenu .pop_btn input[type=submit]').click()
          } else {
            attempts++
            if (attempts >= maxAttempts) {
              // 20秒还是检查不到元素,停止一键评分
              clearInterval(interval)
            }
          }
        }, 100)
      })
    }
  }
)
()