NGA Post Status Query

Check NGA post status.

  1. // ==UserScript==
  2. // @name NGA Post Status Query
  3. // @namespace https://gf.qytechs.cn/users/826221
  4. // @version 1.0.4
  5. // @description Check NGA post status.
  6. // @author DSakura207
  7. // @include /^https?://(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn|ngabbs\.com)/.+/
  8. // @require https://gf.qytechs.cn/scripts/39014-nga-user-script-loader/code/NGA%20User%20Script%20Loader.js?version=809809
  9. // @grant none
  10. // @license GPL-3.0-or-later
  11. // @supportURL https://github.com/DSakura207/NgaPostStatus/issues
  12. // ==/UserScript==
  13.  
  14. // This user script is inspired by https://gf.qytechs.cn/en/scripts/376589.
  15. (function () {
  16. function init($) {
  17. let b = (commonui.PostQuery = {
  18. // Bit mask for post status
  19. statusFlag: {
  20. _POST_IF_COMMENT: { flag: 1, description: "此贴是评论" },
  21. _POST_IF_HIDDEN: { flag: 2, description: "此贴已隐藏" },
  22. _POST_IF_HAVE_COMMENT: { flag: 4, description: "此贴有评论" },
  23. _POST_UNKNOWN_BIT_4: { flag: 8, description: "未知状态4" },
  24. _POST_IF_EXTRA_USER_INFO: {
  25. flag: 16,
  26. description: "此贴在列表显示更多用户信息",
  27. },
  28. _POST_IF_REPORTED: { flag: 32, description: "此贴已被标记" },
  29. _POST_IF_NO_HINT: { flag: 64, description: "此贴不产生回复提示" },
  30. _POST_IF_FREE_EDIT: { flag: 128, description: "此贴无编辑期限" },
  31. _POST_MULTI_USE_1: {
  32. flag: 256,
  33. description: "此贴仅限自己回复/回复不受注册(不可用)时间限制",
  34. },
  35. _POST_WAIT_FOR_AUDIT_1: { flag: 512, description: "此贴等待审核" },
  36. _POST_IF_LOCK: { flag: 1024, description: "此贴被锁定" },
  37. _POST_USER_PUNISHED_IN_POST: {
  38. flag: 2048,
  39. description: "此贴内有用户被处罚",
  40. },
  41. _POST_IF_HAS_AUTO_TRANSLATE: {
  42. flag: 4096,
  43. description: "此贴有版主翻译",
  44. },
  45. _POST_IF_HAS_ATTACHMENT: { flag: 8192, description: "此贴包含附件" },
  46. _POST_WAIT_FOR_AUDIT_2: { flag: 16384, description: "此贴等待审核" },
  47. _POST_IS_ST: { flag: 32768, description: "此贴是合集主题" },
  48. _POST_UNKNOWN_BIT_17: { flag: 65536, description: "未知状态17" },
  49. _POST_MULTI_USE_2: {
  50. flag: 131072,
  51. description: "不在联合版面中显示/锁定合集的全部主题",
  52. },
  53. _POST_MULTI_USE_3: {
  54. flag: 262144,
  55. description: "此贴是匿名发布/此主题新回复在前",
  56. },
  57. _POST_MULTI_USE_4: {
  58. flag: 524288,
  59. description: "此贴在主题列表中显示附件/合集子主题不上浮",
  60. },
  61. _POST_UNKNOWN_BIT_21: { flag: 1048576, description: "未知状态21" },
  62. _POST_MULTI_USE_5: {
  63. flag: 2097152,
  64. description: "版面镜像/此主题回复全部匿名",
  65. },
  66. _POST_UNKNOWN_BIT_23: { flag: 4194304, description: "未知状态23" },
  67. _POST_UNKNOWN_BIT_24: { flag: 8388608, description: "未知状态24" },
  68. _POST_MULTI_USE_6: {
  69. flag: 16777216,
  70. description: "此功能主题不上浮/此功能主题不显示子主题",
  71. },
  72. _POST_UNKNOWN_BIT_26: { flag: 33554432, description: "未知状态26" },
  73. _POST_MULTI_USE_7: {
  74. flag: 67108864,
  75. description: "此贴未通过审核/在主题列表中显示图片",
  76. },
  77. _POST_SHOW_RECENT_REPLY: {
  78. flag: 134217728,
  79. description: "在主题列表中显示最近回复",
  80. },
  81. _POST_UNKNOWN_BIT_29: { flag: 268435456, description: "未知状态29" },
  82. _POST_UNKNOWN_BIT_30: { flag: 536870912, description: "未知状态30" },
  83. _POST_ONLY_ONE_REPLY: {
  84. flag: 1073741824,
  85. description: "此贴只能回复一次",
  86. },
  87. _POST_UNKNOWN_BIT_32: { flag: 2147483648, description: "未知状态32" },
  88. },
  89. f: function (e) {
  90. const pidElement = $(e.currentTarget).parent().children("a[id]");
  91. console.debug(e.currentTarget);
  92. if (pidElement.length != 1) {
  93. console.error(
  94. "Expected 1 element, got " + pidElement.length + " elements"
  95. );
  96. return;
  97. }
  98. let pid = $(pidElement[0]).attr("id").match(/(\d+)/)[0];
  99. console.debug("PID from anchor: " + pid);
  100. if (pid == 0) {
  101. console.debug("Not a reply post, use TID!");
  102. let params = new URLSearchParams(
  103. document.location.search.substring(1)
  104. );
  105. let tid = params.get("tid");
  106. console.debug("TID is " + tid);
  107. $.get(`/read.php?tid=${tid}&__output=11`).done(function (data) {
  108. b.showData(data, tid, "thread");
  109. });
  110. } else {
  111. console.debug("PID is " + pid);
  112. $.get(`/read.php?pid=${pid}&__output=11`).done(function (data) {
  113. b.showData(data, pid, "post");
  114. });
  115. }
  116. },
  117. showData: function (data, pid, postType) {
  118. const typeName = postType.toUpperCase();
  119. const postData = data;
  120. // Post status
  121. const typeFlags = postData["data"]["__R"][0]["type"];
  122. // Thread status
  123. let typeFlags2 = postData["data"]["__T"]["type"];
  124. // POST status object
  125. let postStatusObj = {};
  126. // Thread status object
  127. let postStatusObj2 = {};
  128. // commonui.alert content string
  129. let postStatusString = "";
  130. // Produce thread main or reply post status object.
  131. for (const [info, mask] of Object.entries(b.statusFlag)) {
  132. // Hack for JavaScript bitwise operation.
  133. // Thanks for https://stackoverflow.com/questions/6798111/bitwise-operations-on-32-bit-unsigned-ints
  134. let rc = (mask.flag & typeFlags) >>> 0;
  135. let rc2 = (mask.flag & typeFlags2) >>> 0;
  136. if (rc == mask.flag && postType === "post") {
  137. postStatusObj[info] = mask.description;
  138. postStatusString += (mask.description + ";");
  139. }
  140. if (rc2 == mask.flag && postType === "thread") {
  141. postStatusObj2[info] = mask.description;
  142. postStatusString += (mask.description + ";");
  143. }
  144. }
  145. // Output status object for reference
  146. console.debug(postStatusObj);
  147. console.debug(postStatusObj2);
  148. // Return when status is normal (0).
  149. if (postStatusString.length == 0) {
  150. return;
  151. }
  152. commonui.alert(postStatusString, `${typeName} ${pid}`);
  153. },
  154. r: function () {
  155. // Ensure only one handler is attached
  156. $("div.postInfo")
  157. .off("dblclick.PostQuery")
  158. .on("dblclick.PostQuery", b.f);
  159. },
  160. mo: new MutationObserver(function () {
  161. b.r();
  162. }),
  163. });
  164.  
  165. b.r();
  166.  
  167. b.mo.observe($("body")[0], {
  168. childList: true,
  169. subtree: true,
  170. });
  171. }
  172.  
  173. (function check() {
  174. try {
  175. init(commonui.userScriptLoader.$);
  176. } catch (e) {
  177. setTimeout(check, 50);
  178. }
  179. })();
  180. })();

QingJ © 2025

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