52 Enhance

Minimalistic enhancements for 52pojie.

目前为 2023-07-31 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 52 Enhance
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.0
  5. // @description Minimalistic enhancements for 52pojie.
  6. // @author PRO
  7. // @match https://www.52pojie.cn/*
  8. // @icon http://52pojie.cn/favicon.ico
  9. // @grant none
  10. // @license gpl-3.0
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_registerMenuCommand
  14. // @grant GM_unregisterMenuCommand
  15. // @require https://gf.qytechs.cn/scripts/470224-tampermonkey-config/code/Tampermonkey%20Config.js?version=1216049
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. let config_desc = {
  21. "css-fix": { // 动态透明度;图标上光标不显示为 pointer
  22. "name": "CSS 修复",
  23. "value": true,
  24. "processor": GM_config_builtin_processors.boolean
  25. },
  26. "hide": { // 为旧版代码块添加“隐藏代码”的按钮;一键隐藏所有置顶帖;添加隐藏回复的按钮
  27. "name": "一键隐藏",
  28. "value": true,
  29. "processor": GM_config_builtin_processors.boolean
  30. },
  31. "get-to-top": { // 双击导航栏回到顶部;修改回到顶部按钮行为为原生
  32. "name": "回到顶部",
  33. "value": true,
  34. "processor": GM_config_builtin_processors.boolean
  35. },
  36. "emoji-fix": { // 修复 Emoji 显示
  37. "name": "修复 Emoji",
  38. "value": true,
  39. "processor": GM_config_builtin_processors.boolean
  40. },
  41. };
  42. let config = GM_config(config_desc);
  43. // Css fix
  44. if (config["css-fix"]) {
  45. let css = document.createElement("style");
  46. css.textContent = `
  47. #jz52top {
  48. opacity: 0.2;
  49. transition: opacity 0.2s ease-in-out;
  50. }
  51. #jz52top:hover {
  52. opacity: 0.8;
  53. }
  54. @media (any-hover: none) {
  55. #jz52top {
  56. opacity: 0.8;
  57. }
  58. #jz52top:hover {
  59. opacity: 0.8;
  60. }
  61. }
  62. .authicn {
  63. cursor: initial;
  64. }
  65. `;
  66. document.head.appendChild(css);
  67. }
  68. // Hide
  69. if (config["hide"]) {
  70. // Hide code
  71. function toggleCode() {
  72. let code = this.parentNode.parentNode.lastChild;
  73. if (code.style.display == "none") {
  74. code.style.display = "";
  75. this.textContent = " 隐藏代码";
  76. } else {
  77. code.style.display = "none";
  78. this.textContent = " 显示代码";
  79. }
  80. }
  81. document.querySelectorAll("em.viewsource").forEach(ele => {
  82. let hide_code = document.createElement("em");
  83. hide_code.setAttribute("style", ele.getAttribute("style"));
  84. hide_code.setAttribute("num", ele.getAttribute("num"));
  85. hide_code.textContent = " 隐藏代码";
  86. hide_code.addEventListener("click", toggleCode);
  87. ele.parentNode.appendChild(hide_code);
  88. });
  89. // Hide all top threads
  90. let display = Boolean(document.querySelectorAll("tbody[id^='stickthread_']").length);
  91. let table = document.getElementById("threadlisttableid");
  92. if (display && table) {
  93. function hideAll() {
  94. document.querySelectorAll("tbody[id^='stickthread_']").forEach(ele => {
  95. let close = ele.querySelector("a.closeprev");
  96. if (close) close.click();
  97. });
  98. }
  99. let tooltip = document.querySelector("div#threadlist > div.th > table > tbody > tr > th > div.tf");
  100. let show_top = tooltip.querySelector("span#clearstickthread");
  101. show_top.removeAttribute("style");
  102. show_top.insertAdjacentHTML("beforeend", "  ");
  103. let hide_all = document.createElement("a");
  104. hide_all.href = "javascript:;";
  105. hide_all.className = "xi2";
  106. hide_all.textContent = "隐藏置顶";
  107. hide_all.title = "隐藏置顶";
  108. hide_all.addEventListener("click", hideAll);
  109. show_top.insertAdjacentElement("beforeend", hide_all);
  110. }
  111. // Hide reply
  112. function toggleReplyHeader() {
  113. let reply = this.parentNode.parentNode.parentNode.nextSibling;
  114. if (reply.style.display == "none") {
  115. reply.style.display = "";
  116. } else {
  117. reply.style.display = "none";
  118. }
  119. }
  120. let headers = document.querySelectorAll("div.pti > div.authi");
  121. headers.forEach(header => {
  122. let pipe = document.createElement("span");
  123. pipe.classList.add("pipe");
  124. pipe.textContent = "|";
  125. let toggle = document.createElement("a");
  126. toggle.href = "javascript:void(0);";
  127. toggle.textContent = "隐藏/显示";
  128. toggle.addEventListener("click", toggleReplyHeader);
  129. if (header.querySelector("span.none")) {
  130. pipe.classList.add("show");
  131. toggle.classList.add("show");
  132. }
  133. header.insertAdjacentElement("beforeend", pipe);
  134. header.insertAdjacentElement("beforeend", toggle);
  135. });
  136. function toggleReplyFooter() {
  137. let reply = this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.firstChild.lastChild.lastElementChild;
  138. if (reply.style.display == "none") {
  139. reply.style.display = "";
  140. } else {
  141. reply.style.display = "none";
  142. }
  143. }
  144. let footers = document.querySelectorAll("td.plc >div.po.hin > div.pob.cl > p");
  145. footers.forEach(footer => {
  146. let toggle = document.createElement("a");
  147. toggle.href = "javascript:void(0);";
  148. toggle.textContent = "隐藏/显示";
  149. toggle.addEventListener("click", toggleReplyFooter);
  150. footer.insertAdjacentElement("beforeend", toggle);
  151. });
  152. }
  153. // Get to top
  154. if (config["get-to-top"]) {
  155. // Double click navbar to get to top
  156. document.getElementById("nv").addEventListener("dblclick", e => {
  157. window.scrollTo({ top: 0, behavior: "smooth" });
  158. });
  159. // Change get to top button behavior (use vanilla solution)
  160. document.getElementById("goTopBtn").onclick = e => {
  161. window.scrollTo({ top: 0, behavior: "smooth" });
  162. };
  163. }
  164. // Emoji fix
  165. if (config["emoji-fix"]) {
  166. let temp = document.createElement("span");
  167. function fixEmoji(html) { // Replace patterns like `👍` with represented emoji
  168. return html.replace(/&(amp;)*#(\d+);/g, (match, p1, p2) => {
  169. temp.innerHTML = `&#${p2};`;
  170. console.log(`${match} -> ${temp.textContent}`);
  171. return temp.textContent;
  172. });
  173. }
  174. function fix(node) {
  175. // Select text nodes
  176. let walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null, false);
  177. let textNode;
  178. while (textNode = walker.nextNode()) {
  179. textNode.nodeValue = fixEmoji(textNode.nodeValue);
  180. }
  181. }
  182. let replies = document.querySelectorAll("table.plhin td.plc div.pct > div.pcb > div.t_fsz");
  183. replies.forEach(fix);
  184. let ratings = document.querySelectorAll("tbody.ratl_l > tr");
  185. ratings.forEach(rating => fix(rating.lastElementChild));
  186. }
  187. })();

QingJ © 2025

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