52 Enhance

52 破解论坛增强脚本

目前為 2023-08-04 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 52 Enhance
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.7
  5. // @description 52 破解论坛增强脚本
  6. // @author PRO
  7. // @match https://www.52pojie.cn/*
  8. // @icon http://52pojie.cn/favicon.ico
  9. // @license gpl-3.0
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_registerMenuCommand
  13. // @grant GM_unregisterMenuCommand
  14. // @require https://gf.qytechs.cn/scripts/470224-tampermonkey-config/code/Tampermonkey%20Config.js?version=1229665
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. let idPrefix = "52-enhance-";
  20. let config_desc = {};
  21. function addDesc(id, name, default_value=true) {
  22. config_desc[id] = {
  23. name: name,
  24. value: default_value,
  25. input: "current",
  26. processor: "not",
  27. formatter: "boolean",
  28. };
  29. }
  30. addDesc("css-fix", "CSS 修复"); // 动态透明度;图标上光标不显示为 pointer
  31. addDesc("hide", "* 一键隐藏"); // 为旧版代码块添加“隐藏代码”的按钮;一键隐藏所有置顶帖;添加隐藏回复的按钮
  32. addDesc("get-to-top", "* 回到顶部"); // 双击导航栏回到顶部;修改回到顶部按钮行为为原生
  33. addDesc("emoji-fix", "* 修复 Emoji"); // 修复 Emoji 显示
  34. addDesc("hide-signature", "隐藏签名档", false); // 隐藏所有签名档
  35. addDesc("allow-tiny-signature", "允许小签名", true); // 允许小型签名档 (clientHeight <= 41)
  36. addDesc("hide-warning", "隐藏提醒", false); // 隐藏所有提醒
  37. addDesc("hide-avatar-detail", "隐藏头像详情", false); // 隐藏头像下的详情 (注册(不可用)时间等、收听按钮)
  38. addDesc("hide-rating", "隐藏评分", false); // 隐藏所有评分
  39. addDesc("hide-comment", "隐藏点评", false); // 隐藏所有点评
  40. addDesc("auto-sign", "自动签到"); // 自动签到
  41. let config = GM_config(config_desc, false);
  42. // Helper function for css
  43. function cssHelper(id, css) {
  44. let current = document.getElementById(idPrefix + id);
  45. if (css && !current) {
  46. let style = document.createElement("style");
  47. style.id = idPrefix + id;
  48. style.textContent = css;
  49. document.head.appendChild(style);
  50. } else if (!css && current) {
  51. current.remove();
  52. }
  53. }
  54. // Css fix
  55. function cssFix(enable) {
  56. let css = `
  57. #jz52top {
  58. opacity: 0.2;
  59. transition: opacity 0.2s ease-in-out;
  60. }
  61. #jz52top:hover {
  62. opacity: 0.8;
  63. }
  64. @media (any-hover: none) {
  65. #jz52top {
  66. opacity: 0.8;
  67. }
  68. #jz52top:hover {
  69. opacity: 0.8;
  70. }
  71. }
  72. .authicn {
  73. cursor: initial;
  74. }
  75. `;
  76. cssHelper("css-fix", enable ? css : null);
  77. }
  78. cssFix(config["css-fix"]);
  79. // Hide
  80. if (config["hide"]) {
  81. // let css = ".hidden { display: none; !important; }";
  82. let css = `
  83. tr.hidden { display: none; }
  84. td.hidden { pointer-events: none; background: repeating-linear-gradient(135deg, transparent 0, transparent 6px, #e7e7e7 6px, #e7e7e7 12px, transparent 12px) no-repeat 0 0, #eee; }
  85. td.hidden > div > div > em::after { content: "此回复已被隐藏"; }
  86. .plhin:hover td.hidden .hin { opacity: 0.2; }
  87. .toggle-reply { display: block; text-align: center; position: relative; top: 0.8em; }`;
  88. cssHelper("hide", css);
  89. // Hide code
  90. function toggleCode() {
  91. let code = this.parentNode.parentNode.lastChild;
  92. if (code.classList.toggle("hidden")) {
  93. this.textContent = " 显示代码";
  94. } else {
  95. this.textContent = " 隐藏代码";
  96. }
  97. }
  98. document.querySelectorAll("em.viewsource").forEach(ele => {
  99. let hide_code = document.createElement("em");
  100. hide_code.setAttribute("style", ele.getAttribute("style"));
  101. hide_code.setAttribute("num", ele.getAttribute("num"));
  102. hide_code.textContent = " 隐藏代码";
  103. hide_code.addEventListener("click", toggleCode);
  104. ele.parentNode.appendChild(hide_code);
  105. });
  106. // Hide all top threads
  107. let display = Boolean(document.querySelectorAll("tbody[id^='stickthread_']").length);
  108. let table = document.getElementById("threadlisttableid");
  109. if (display && table) {
  110. function hideAll() {
  111. document.querySelectorAll("tbody[id^='stickthread_']").forEach(ele => {
  112. let close = ele.querySelector("a.closeprev");
  113. if (close) close.click();
  114. });
  115. }
  116. let tooltip = document.querySelector("div#threadlist > div.th > table > tbody > tr > th > div.tf");
  117. let show_top = tooltip.querySelector("span#clearstickthread");
  118. show_top.removeAttribute("style");
  119. show_top.insertAdjacentHTML("beforeend", "&nbsp; ");
  120. let hide_all = document.createElement("a");
  121. hide_all.href = "javascript:;";
  122. hide_all.className = "xi2";
  123. hide_all.textContent = "隐藏置顶";
  124. hide_all.title = "隐藏置顶";
  125. hide_all.addEventListener("click", hideAll);
  126. show_top.insertAdjacentElement("beforeend", hide_all);
  127. }
  128. // Hide reply
  129. function toggleReply() {
  130. let keep = this.parentElement.parentElement;
  131. for (let ele of keep.parentElement.children) {
  132. if (ele != keep) {
  133. ele.classList.toggle("hidden");
  134. }
  135. }
  136. keep.lastElementChild.classList.toggle("hidden");
  137. }
  138. document.querySelectorAll("table.plhin tr:nth-child(4) > td.pls").forEach(ele => {
  139. let toggle_reply = document.createElement("a");
  140. toggle_reply.href = "javascript:void(0);";
  141. toggle_reply.className = "toggle-reply";
  142. toggle_reply.textContent = "隐藏/显示回复";
  143. toggle_reply.addEventListener("click", toggleReply);
  144. ele.appendChild(toggle_reply);
  145. });
  146. }
  147. // Get to top
  148. if (config["get-to-top"]) {
  149. // Double click navbar to get to top
  150. document.getElementById("nv").addEventListener("dblclick", e => {
  151. window.scrollTo({ top: 0, behavior: "smooth" });
  152. });
  153. // Change get to top button behavior (use vanilla solution)
  154. document.getElementById("goTopBtn").onclick = e => {
  155. window.scrollTo({ top: 0, behavior: "smooth" });
  156. };
  157. }
  158. // Emoji fix
  159. if (config["emoji-fix"]) {
  160. let temp = document.createElement("span");
  161. function fixEmoji(html) { // Replace patterns like `&amp;#128077;` with represented emoji
  162. return html.replace(/&(amp;)*#(\d+);/g, (match, p1, p2) => {
  163. temp.innerHTML = `&#${p2};`;
  164. // console.log(`${match} -> ${temp.textContent}`); // DEBUG
  165. return temp.textContent;
  166. });
  167. }
  168. function fix(node) {
  169. // Select text nodes
  170. let walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null, false);
  171. let textNode;
  172. while (textNode = walker.nextNode()) {
  173. textNode.nodeValue = fixEmoji(textNode.nodeValue);
  174. }
  175. }
  176. let replies = document.querySelectorAll("table.plhin td.plc div.pct > div.pcb > div.t_fsz");
  177. replies.forEach(fix);
  178. let ratings = document.querySelectorAll("tbody.ratl_l > tr");
  179. ratings.forEach(rating => fix(rating.lastElementChild));
  180. let signatures = document.querySelectorAll("div.sign");
  181. signatures.forEach(fix);
  182. }
  183. // Hide signatures
  184. function hideSignature(enable) {
  185. let css = "div.sign { display: none; }";
  186. cssHelper("hide-signature", enable ? css : null);
  187. }
  188. // Allow tiny signatures (clientHeight <= 41)
  189. function allowTinySignature(enable) {
  190. let css = "div.sign.tiny-sign { display: block; }";
  191. cssHelper("allow-tiny-signature", enable ? css : null);
  192. }
  193. // Tag tiny signatures as `tiny-sign`
  194. document.addEventListener("readystatechange", e => {
  195. if (document.readyState == "complete") {
  196. document.querySelectorAll("div.sign").forEach(ele => {
  197. if (ele.clientHeight <= 41) {
  198. ele.classList.add("tiny-sign");
  199. }
  200. });
  201. }
  202. hideSignature(config["hide-signature"]);
  203. allowTinySignature(config["allow-tiny-signature"]);
  204. });
  205. // Hide warnings
  206. function hideWarning(enable) {
  207. let css = "div[class^=vw50_kfc_p] { display: none; }";
  208. cssHelper("hide-warning", enable ? css : null);
  209. }
  210. hideWarning(config["hide-warning"]);
  211. // Hide avatar details
  212. function hideAvatarDetail(enable) {
  213. let css = "dl.credit-list, ul.xl.xl2.o.cl { display: none; }";
  214. cssHelper("hide-avatar-detail", enable ? css : null);
  215. }
  216. hideAvatarDetail(config["hide-avatar-detail"]);
  217. // Hide ratings
  218. function hideRating(enable) {
  219. let css = "div.pcb > h3.psth.xs1, dl.rate { display: none; }";
  220. cssHelper("hide-rating", enable ? css : null);
  221. }
  222. hideRating(config["hide-rating"]);
  223. // Hide comments
  224. function hideComment(enable) {
  225. let css = "div.pcb > div.cm { display: none; }";
  226. cssHelper("hide-comment", enable ? css : null);
  227. }
  228. hideComment(config["hide-comment"]);
  229. // Auto sign
  230. function autoSign(enable) {
  231. if (enable) {
  232. let sign = document.querySelector("#um > p:nth-child(3) > a:nth-child(1) > img");
  233. if (sign) {
  234. sign.click();
  235. }
  236. }
  237. }
  238. autoSign(config["auto-sign"]);
  239. // Listen to config changes
  240. let callbacks = {
  241. "css-fix": cssFix,
  242. "hide-signature": hideSignature,
  243. "allow-tiny-signature": allowTinySignature,
  244. "hide-warning": hideWarning,
  245. "hide-avatar-detail": hideAvatarDetail,
  246. "hide-rating": hideRating,
  247. "hide-comment": hideComment,
  248. "auto-sign": autoSign
  249. };
  250. window.addEventListener(GM_config_event, e => {
  251. if (e.detail.type == "set") {
  252. let callback = callbacks[e.detail.prop];
  253. if (callback && (e.detail.before !== e.detail.after)) {
  254. callback(e.detail.after);
  255. }
  256. }
  257. });
  258. })();

QingJ © 2025

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