收件箱一键已读

nexusphp 未读消息一键已读

  1. // ==UserScript==
  2. // @name 收件箱一键已读
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description nexusphp 未读消息一键已读
  6. // @author yigezhanghao
  7. // @icon https://www.google.com/s2/favicons?domain=gf.qytechs.cn
  8. // @grant none
  9. // @require https://code.jquery.com/jquery-3.6.0.min.js
  10. // @match https://pt.keepfrds.com/messages.php*
  11. // @match https://hdsky.me/messages.php*
  12. // @match https://pterclub.com/messages.php*
  13. // @match https://springsunday.net/messages.php*
  14. // @match https://ourbits.club/messages.php*
  15. // @match https://pthome.net/messages.php*
  16. // @match https://www.tjupt.org/messages.php*
  17. // ==/UserScript==
  18.  
  19. var markread = async unreadMsgIds => {
  20. console.log('mark read:', unreadMsgIds)
  21. var { origin, pathname } = window.location
  22. var url = origin + pathname
  23. var params = {
  24. action: 'moveordel',
  25. markread: '设为已读',
  26. box: '1',
  27. }
  28. var data =
  29. $.param(params) +
  30. '&' +
  31. unreadMsgIds.map(id => 'messages%5B%5D=' + id).join('&')
  32. await $.post(url, data)
  33. }
  34.  
  35. var getUnreadMsgIds = html => {
  36. var unreadMsgIds = []
  37. $(html)
  38. .find('table:last > tbody > tr')
  39. .slice(1, -2)
  40. .each(function () {
  41. // alt is Read or Unread
  42. var alt = $(this).find('td:first > img').attr('alt')
  43. if (alt === 'Unread') {
  44. var msgId = $(this).find('td:last > input').val()
  45. unreadMsgIds.push(msgId)
  46. }
  47. })
  48. return unreadMsgIds
  49. }
  50.  
  51. var isLastUnread = html => {
  52. var rows = $(html).find('table:last > tbody > tr')
  53. var lastRow = rows.get(-3)
  54. var alt = $(lastRow).find('td:first > img').attr('alt')
  55. return alt === 'Unread' ? true : false
  56. }
  57.  
  58. var handleNextPage = html => {
  59. var currentPageEle = $(html).find('p[align="center"] > font:contains("-")')
  60. var nextPageLink = currentPageEle.next().attr('href')
  61. $.get(nextPageLink).done(e => clearPageUnread(e))
  62. }
  63.  
  64. var hasNextPage = html => {
  65. var currentPageEle = $(html).find('p[align="center"] > font:contains("-")')
  66. return currentPageEle.next().length === 0 ? false : true
  67. }
  68.  
  69. var clearPageUnread = async html => {
  70. var unreadMsgIds = getUnreadMsgIds(html)
  71. if (unreadMsgIds.length === 0) {
  72. $('#result').text('已读完毕!')
  73. return
  74. } else {
  75. await markread(unreadMsgIds)
  76. if (isLastUnread(html) && hasNextPage(html)) {
  77. handleNextPage(html)
  78. } else {
  79. $('#result').text('已读完毕!')
  80. location.reload()
  81. }
  82. }
  83. }
  84.  
  85. var onClickClear = () => {
  86. $('#result').text('已读中...')
  87. clearPageUnread(document)
  88. }
  89.  
  90. ;(function () {
  91. 'use strict'
  92. var searchBtn = $('input[value="给我搜"]')
  93. var clearBtn = `<input id="clear-btn" class="btn" type="button" value="一键已读" style="margin-left: 20px;">`
  94. searchBtn.after(clearBtn)
  95. var searchRow = searchBtn.closest('table')
  96. searchRow.after(
  97. '<div id="result" style="margin-top: 20px; font-size: 20px; color: #616161;"></div>'
  98. )
  99. $('#clear-btn').click(onClickClear)
  100. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址