Greasy Fork

Greasy Fork is available in English.

收件箱一键已读

nexusphp 未读消息一键已读

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         收件箱一键已读
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  nexusphp 未读消息一键已读
// @author       yigezhanghao
// @icon         https://www.google.com/s2/favicons?domain=greasyfork.org
// @grant        none
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @match        https://pt.keepfrds.com/messages.php*
// @match        https://hdsky.me/messages.php*
// @match        https://pterclub.com/messages.php*
// @match        https://springsunday.net/messages.php*
// @match        https://ourbits.club/messages.php*
// @match        https://pthome.net/messages.php*
// @match        https://www.tjupt.org/messages.php*
// ==/UserScript==

var markread = async unreadMsgIds => {
  console.log('mark read:', unreadMsgIds)
  var { origin, pathname } = window.location
  var url = origin + pathname
  var params = {
    action: 'moveordel',
    markread: '设为已读',
    box: '1',
  }
  var data =
    $.param(params) +
    '&' +
    unreadMsgIds.map(id => 'messages%5B%5D=' + id).join('&')
  await $.post(url, data)
}

var getUnreadMsgIds = html => {
  var unreadMsgIds = []
  $(html)
    .find('table:last > tbody > tr')
    .slice(1, -2)
    .each(function () {
      // alt is Read or Unread
      var alt = $(this).find('td:first > img').attr('alt')
      if (alt === 'Unread') {
        var msgId = $(this).find('td:last > input').val()
        unreadMsgIds.push(msgId)
      }
    })
  return unreadMsgIds
}

var isLastUnread = html => {
  var rows = $(html).find('table:last > tbody > tr')
  var lastRow = rows.get(-3)
  var alt = $(lastRow).find('td:first > img').attr('alt')
  return alt === 'Unread' ? true : false
}

var handleNextPage = html => {
  var currentPageEle = $(html).find('p[align="center"] > font:contains("-")')
  var nextPageLink = currentPageEle.next().attr('href')
  $.get(nextPageLink).done(e => clearPageUnread(e))
}

var hasNextPage = html => {
  var currentPageEle = $(html).find('p[align="center"] > font:contains("-")')
  return currentPageEle.next().length === 0 ? false : true
}

var clearPageUnread = async html => {
  var unreadMsgIds = getUnreadMsgIds(html)
  if (unreadMsgIds.length === 0) {
    $('#result').text('已读完毕!')
    return
  } else {
    await markread(unreadMsgIds)
    if (isLastUnread(html) && hasNextPage(html)) {
      handleNextPage(html)
    } else {
      $('#result').text('已读完毕!')
      location.reload()
    }
  }
}

var onClickClear = () => {
  $('#result').text('已读中...')
  clearPageUnread(document)
}

;(function () {
  'use strict'
  var searchBtn = $('input[value="给我搜"]')
  var clearBtn = `<input id="clear-btn" class="btn" type="button" value="一键已读" style="margin-left: 20px;">`
  searchBtn.after(clearBtn)
  var searchRow = searchBtn.closest('table')
  searchRow.after(
    '<div id="result" style="margin-top: 20px; font-size: 20px; color: #616161;"></div>'
  )
  $('#clear-btn').click(onClickClear)
})()