Linux.po

对 linux.do 的增强脚本

目前为 2025-01-20 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Linux.po
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.6
  5. // @description 对 linux.do 的增强脚本
  6. // @author PRO-2684
  7. // @match https://linux.do/*
  8. // @run-at document-start
  9. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAABOxJREFUWEfNV0tslFUU/s7/nmmHmWE6NRUqKZXER9OIuNFA3Ei6w6CUWiPGjRiaSLtoWZi4MnFBu2gxgYgLjRgqtNHIrsGFBqIbAdPUR4LQYIXGTseZ6WPmfx+9f+dvphRIDWPxzm7+e8/3nXPPOfc7hLssZiYAKhHZ4RZm3gtgD4Am27Z3EpEsvjGzp2naRQCTAM4R0ZcVZzQADhHxnaAEyKrFzALYKRtPADjuOE7n2NgYLly4iPHxcVy6dEVAl88SduzYjtbWVuzatRNtbW1QVXUYQBcR5ct2lm1WAq4iwMxa6DUzD7qu2z04OIRjxz7A1NQNF4BfUxOTa2pqZKKl48yMxcVFb3Fx3gMgNTZuUQ4ffhs9Pd1QFGXoHxI95X3LtkMSKwgws05EFjNvBDAxMjLacOhQF7LZjF1XV6/GYjESoJ7nwff9FZGTJAmyLAdk5ufneXZ2xkml0tqJE8fR3r5vGkALEf0VYqwiEHpeLBY3RyKRqb6+IxgY6DfT6YeMWCwGx3EC42tZgqSqqoIIMpk/zd7ePqO//yhKpVJjNBr9ozLKQQTCOy97nu3oeAVnz56xmpqa9Tt5uxYSYk8YlcnJa9b+/R36mTOfi79T5UgEOUEi28MMZeZbfX1HGgYG+q3m5m26ZVlrxbrnPl3Xce3aVau3t0/v7z86TUQPlx0nQSBIDJFwo6Oj3e3t7WZz8zbDtperryokNE0TJMyRkVFj376Xg8QMsMNSy2Qyufr6ehE4RCKRVUl2vyzEdZRKJVFEmJmZQTqdTooSDQjYtn365s2bnRMTE3Y8Htc8z0e5wu4Xd/m8yF9ZllAoFOyWlhZt06ZNw5qmvRoQyOVybBgGDMMQaX7H5lQ1JgCbpkmmaSKZTBLlcrm9RPQFM7ue5ylVBLqrKVmWXSJSmPklKhQKHzPzG+ImAIi+vR4rwCKiTyifz38D4HkAoo0Gj8s6rBDrW0FA9Pf1Ar7dN08QWFt//Y/C8r8g8MCv4MEm4QMvw7ARAeyC16cRgWQXKDcikdz5fI4hGWBlfVoxuSbBN5FIJJeenPy8e5rMG53y3GWb1aQGXim3qlaBJIGcvO1t2K6xsWU4EVPKjxFzgnKZXHysfukpkqoGudKQ6H8ACm0z4GRaPEV5+olZe5LInmUejPz2WXf0+wMmElEDfnUFCSQNyBfN4rOnjNKjrw3VEfUI7BWSLOvxrdrLbzVov560EI/q8KsjySDpQKFo2Y8d1Bee/nA6JVdIsrIiCgRiocAb3SiyG77bDeX3ry3EI7ooDrCI3b+VCQyIwYkUoFCy3Ede0OeeOw+liFQ8HsjzJVEaXlKoDbNF3gwVU7U/HoT2y0cmamFAiQK+GJTWmpwSIKmAWwQWYNqPv2ksPHUScNCYitJqWR6SuMqsbyOygkjUYsK4fqohOv46YMJGBCpkgwKtJiJye6WQtOSx0F6eySjBgQGt2PopzK0HppUFtAjPQ4wQ856jWZZ5UFrwuo3J92Bcfx9YdFwQfEEl+FUuDx4ceGBIqFEVc+s7MJvehV8rD6XWOppVXMfyIJljTvjAcWnB7VQzX0HNnoc8dwly4YeV+PFn4G3YASe1G076Rfi1yrAEdIlSq8yz2wv8rpklBpafAVWUaHholnkv+dgjWWiC5+6sEDIeZOWir2OSJZyrqxjPRak9cY/x/G9pa4SNlgBs7AAAAABJRU5ErkJggg==
  10. // @license gpl-3.0
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_deleteValue
  14. // @grant GM_registerMenuCommand
  15. // @grant GM_unregisterMenuCommand
  16. // @grant GM_addValueChangeListener
  17. // @require https://github.com/PRO-2684/GM_config/releases/download/v1.2.1/config.min.js#md5=525526b8f0b6b8606cedf08c651163c2
  18. // ==/UserScript==
  19.  
  20. (function () {
  21. 'use strict';
  22. const { name, version } = GM_info.script;
  23. const idPrefix = "linux-po-";
  24. const configDesc = {
  25. $default: {
  26. autoClose: false,
  27. },
  28. appearance: {
  29. name: "🎨 外观",
  30. title: "外观",
  31. type: "folder",
  32. items: {
  33. sidebarManager: {
  34. name: "⬅️ 侧栏管理",
  35. title: "允许你隐藏侧栏中的各个部分",
  36. type: "folder",
  37. items: {
  38. $default: {
  39. value: false,
  40. input: "current",
  41. processor: "not",
  42. title: (prop, value, desc) => desc.name,
  43. formatter: (prop, value, desc) => `${desc.name}: ${value ? "🫥" : "👀"}`,
  44. },
  45. customCategories: { name: "自定义板块" },
  46. externalLinks: { name: "外部链接" },
  47. categories: { name: "类别" },
  48. tags: { name: "标签" },
  49. messages: { name: "消息" },
  50. channels: { name: "频道" },
  51. directMessages: { name: "直接消息" },
  52. chat: { name: "聊天" },
  53. bottomMenu: { name: "底部菜单" },
  54. },
  55. },
  56. postManager: {
  57. name: "📝 帖子管理",
  58. title: "允许你隐藏帖子的各个部分",
  59. type: "folder",
  60. items: {
  61. $default: {
  62. value: false,
  63. input: "current",
  64. processor: "not",
  65. title: (prop, value, desc) => desc.name,
  66. formatter: (prop, value, desc) => `${desc.name}: ${value ? "🫥" : "👀"}`,
  67. },
  68. secondaryName: { name: "次要名称" },
  69. userTitle: { name: "头衔" },
  70. userStatus: { name: "自定义状态" },
  71. posterIcon: {
  72. name: "🍰",
  73. title: "加入社区纪念日以及生日图标 (discourse-cakeday)",
  74. },
  75. flair: {
  76. name: "资质",
  77. title: "展示在头像右下角",
  78. },
  79. },
  80. },
  81. },
  82. },
  83. accessibility: {
  84. name: "♿ 辅助功能",
  85. title: "辅助功能",
  86. type: "folder",
  87. items: {
  88. largerClickArea: {
  89. name: "👆 增大点击区域",
  90. title: "增大帖子列表中各帖子的可点击区域 (仅支持左键)",
  91. type: "bool",
  92. value: true,
  93. },
  94. showPostsFloor: {
  95. name: "🔢 显示楼层",
  96. title: "在帖子中显示楼层",
  97. type: "bool",
  98. value: false,
  99. },
  100. atBeforeUsername: {
  101. name: "👤 @用户名",
  102. title: "在用户名前添加 @ 符号",
  103. type: "bool",
  104. value: false,
  105. },
  106. },
  107. },
  108. };
  109. const config = new GM_config(configDesc);
  110.  
  111. // Helper function for css
  112. function injectCSS(id, css) {
  113. const style = document.head.appendChild(document.createElement("style"));
  114. style.id = idPrefix + id;
  115. style.textContent = css;
  116. return style;
  117. }
  118. function cssHelper(id, enable) {
  119. const current = document.getElementById(idPrefix + id);
  120. if (current) {
  121. current.disabled = !enable;
  122. } else if (enable) {
  123. injectCSS(id, dynamicStyles[id]);
  124. }
  125. }
  126. /**
  127. * Generates CSS for hiding given sidebar section.
  128. */
  129. function hideSidebarSection(section) {
  130. return `#d-sidebar > .sidebar-sections div.sidebar-section[data-section-name="${section}"] { display: none; }`;
  131. }
  132. /**
  133. * Generates CSS for hiding given post section.
  134. */
  135. function hidePostSection(section) {
  136. return `.post-stream > .topic-post > article .names > .${section} { display: none; }`;
  137. }
  138.  
  139. // Dynamic styles
  140. const dynamicStyles = {
  141. "appearance.sidebarManager.customCategories": hideSidebarSection("community"),
  142. "appearance.sidebarManager.externalLinks": hideSidebarSection("外部链接"),
  143. "appearance.sidebarManager.categories": hideSidebarSection("categories"),
  144. "appearance.sidebarManager.tags": hideSidebarSection("tags"),
  145. "appearance.sidebarManager.messages": hideSidebarSection("messages"),
  146. "appearance.sidebarManager.channels": hideSidebarSection("chat-channels"),
  147. "appearance.sidebarManager.directMessages": hideSidebarSection("chat-dms"),
  148. "appearance.sidebarManager.chat": "#d-sidebar > button[data-key='chat'] { display: none; }",
  149. "appearance.sidebarManager.bottomMenu": "#d-sidebar > div.sidebar-footer-wrapper { display: none; }",
  150. "appearance.postManager.secondaryName": hidePostSection("second"),
  151. "appearance.postManager.userTitle": hidePostSection("user-title"),
  152. "appearance.postManager.userStatus": hidePostSection("user-status-message-wrap"),
  153. "appearance.postManager.posterIcon": hidePostSection("poster-icon"),
  154. "appearance.postManager.flair": ".topic-avatar > .post-avatar > .avatar-flair { display: none; }",
  155. "accessibility.largerClickArea": ".topic-list-item > .main-link { cursor: pointer; }",
  156. "accessibility.showPostsFloor": `.post-stream > .topic-post > article[id^='post_'] {
  157. &::after {
  158. content: attr(id) '#'; color: var(--primary-med-or-secondary-med);
  159. position: absolute; right: 0; top: calc(0.8em + 1px);
  160. text-indent: -2.4em; overflow: hidden; /* Dirty trick to hide leading "post_" */
  161. }
  162. .embedded-posts > .reply .post-link-arrow > a.post-info::after {
  163. content: attr(href) '#'; display: inline-flex;
  164. text-indent: -7.4em; overflow: hidden; /* Dirty trick to hide leading "/t/topic/\\d{6}/" */
  165. }
  166. }
  167. .timeline-container > .topic-timeline > .timeline-scrollarea-wrapper > .timeline-date-wrapper > .now-date[href^='/t/topic/']::after {
  168. content: attr(href) '#'; display: inline-flex; margin-left: 0.2em;
  169. text-indent: -7.4em; overflow: hidden; /* Dirty trick to hide leading "/t/topic/\\d{6}/" */
  170. }`,
  171. "accessibility.atBeforeUsername": `
  172. span.username > a::before { content: "@"; }
  173. div.username::before { content: "@"; }
  174. `,
  175. };
  176. for (const prop in dynamicStyles) {
  177. cssHelper(prop, config.get(prop));
  178. }
  179.  
  180. // Accessibility
  181. // Larger click area
  182. let largerClickAreaEnabled = false;
  183. /**
  184. * Handles the click event when larger click area is enabled.
  185. * @param {MouseEvent} e
  186. */
  187. function largerClickAreaHandler(e) {
  188. if (e.defaultPrevented || !e.isTrusted) return;
  189. e.preventDefault();
  190. const mainLink = e.target.closest(".topic-list-item > .main-link");
  191. if (mainLink) {
  192. const title = mainLink.querySelector(".title.raw-link.raw-topic-link");
  193. title?.click();
  194. }
  195. }
  196. /**
  197. * Enables or disables the larger click area feature.
  198. * @param {boolean} enable
  199. */
  200. function largerClickArea(enable) {
  201. if (enable && !largerClickAreaEnabled) {
  202. document.body.addEventListener("click", largerClickAreaHandler);
  203. largerClickAreaEnabled = true;
  204. } else if (!enable && largerClickAreaEnabled) {
  205. document.body.removeEventListener("click", largerClickAreaHandler);
  206. largerClickAreaEnabled = false;
  207. }
  208. }
  209.  
  210. // Callbacks
  211. const callbacks = {
  212. "accessibility.largerClickArea": largerClickArea,
  213. };
  214. for (const [prop, callback] of Object.entries(callbacks)) {
  215. callback(config.get(prop));
  216. }
  217. config.addEventListener("set", e => {
  218. if (e.detail.prop in dynamicStyles) {
  219. cssHelper(e.detail.prop, e.detail.after);
  220. }
  221. if (e.detail.prop in callbacks) {
  222. callbacks[e.detail.prop](e.detail.after);
  223. }
  224. });
  225.  
  226. // https://linux.do/emojis.json
  227. })();
  228.  

QingJ © 2025

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