Discourse Pro

增强 Discourse 论坛。

当前为 2024-12-15 提交的版本,查看 最新版本

  1. /******/ (() => { // webpackBootstrap
  2. /******/ "use strict";
  3. var __webpack_exports__ = {};
  4.  
  5. ;// CONCATENATED MODULE: ./utils/src/gm/Store.ts
  6. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  7. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
  9. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  10. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  11. function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  12. /**
  13. * 存储
  14. */
  15. var Store = /*#__PURE__*/function () {
  16. function Store() {
  17. _classCallCheck(this, Store);
  18. }
  19. return _createClass(Store, null, [{
  20. key: "get",
  21. value:
  22. /**
  23. * 获取
  24. * @param key 键
  25. */
  26. function get(key) {
  27. return GM_getValue(key);
  28. }
  29.  
  30. /**
  31. * 设置
  32. * @param key 键
  33. * @param value 值
  34. */
  35. }, {
  36. key: "set",
  37. value: function set(key, value) {
  38. GM_setValue(key, value);
  39. }
  40. }]);
  41. }();
  42.  
  43. ;// CONCATENATED MODULE: ./discourse-pro/src/main.ts
  44. // ==UserScript==
  45. // @name Discourse Pro
  46. // @namespace http://tampermonkey.net/
  47. // @version 0.0.1
  48. // @description 增强 Discourse 论坛。
  49. // @author duanluan
  50. // @copyright 2024, duanluan (https://github.com/duanluan)
  51. // @license Apache-2.0 https://www.apache.org/licenses/LICENSE-2.0.txt
  52. // @homepage https://greasyfork.org/zh-CN/scripts/520817
  53. // @supportURL https://github.com/duanluan/tampermonkey-scripts/issues
  54. // @match *://linux.do/*
  55. // @match *://meta.appinn.net/*
  56. // @require https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js
  57. // @resource css https://cdn.jsdelivr.net/npm/layer-src@3.5.1/src/theme/default/layer.min.css
  58. // @require https://cdn.jsdelivr.net/npm/layer-src@3.5.1/src/layer.min.js
  59. // @grant GM_addStyle
  60. // @grant GM_getResourceText
  61. // @grant GM_getValue
  62. // @grant GM_setValue
  63. // ==/UserScript==
  64.  
  65. // ==OpenUserJS==
  66. // @author duanluan
  67. // @updateURL https://raw.kkgithub.com/duanluan/tampermonkey-scripts/main/discourse-pro/dist/discourse-pro.user.js
  68. // ==/OpenUserJS==
  69.  
  70.  
  71. var host = location.host;
  72. var selector = {
  73. // 侧边栏和主内容的父容器
  74. mainOutletWrapper: '#main-outlet-wrapper',
  75. // 侧边栏
  76. sidebarWrapper: '.sidebar-wrapper',
  77. // 主内容
  78. mainOutlet: '#main-outlet'
  79. };
  80. var storeKeys = {
  81. // 侧边栏宽度
  82. sidebarWidth: 'sidebarWidth_'
  83. };
  84.  
  85. /**
  86. * 加载侧边栏和内容之前的拖拽条
  87. */
  88. var loadDragBar = function loadDragBar() {
  89. var $mainOutletWrapper = $(selector.mainOutletWrapper),
  90. $sidebarWrapper = $(selector.sidebarWrapper);
  91.  
  92. // 在侧边栏内部追加一个拖拽条
  93. $sidebarWrapper.append("\n <div class=\"drag-bar\" style=\"width: 4px cursor: ew-resize\"></div>\n ");
  94. // 读取存储的侧边栏宽度
  95. var storeSidebarWidth = Store.get(storeKeys.sidebarWidth + host);
  96. if (storeSidebarWidth) {
  97. $mainOutletWrapper.css('grid-template-columns', "".concat(storeSidebarWidth, "px minmax(0, 1fr)"));
  98. }
  99.  
  100. // 拖拽条
  101. var $dragBar = $sidebarWrapper.find('.drag-bar');
  102. // 是否正在拖拽
  103. var isDragging = false;
  104. // 鼠标按下时的 clientX
  105. var startClientX = 0;
  106. // 鼠标按下时的侧边栏宽度
  107. var startSidebarWidth = 0;
  108. // 侧边栏宽度范围
  109. var minSidebarWidth = 180,
  110. maxSidebarWidth = 500;
  111. var newSidebarWidth = 0;
  112.  
  113. // 鼠标按下事件
  114. $dragBar.on('mousedown', function (e) {
  115. startClientX = e.clientX;
  116. startSidebarWidth = $sidebarWrapper.width();
  117. isDragging = true;
  118. // 改变鼠标样式
  119. document.body.style.cursor = 'ew-resize';
  120. // 设置拖拽条背景色
  121. $dragBar.css('background-color', '#e6e6e6');
  122. // 防止文本被选中
  123. e.preventDefault();
  124. });
  125.  
  126. // 鼠标移动事件
  127. $(document).on('mousemove', function (e) {
  128. if (!isDragging) return;
  129.  
  130. // 计算新的宽度
  131. var deltaX = e.clientX - startClientX;
  132. newSidebarWidth = startSidebarWidth + deltaX;
  133. if (newSidebarWidth >= minSidebarWidth && newSidebarWidth <= maxSidebarWidth) {
  134. $mainOutletWrapper.css('grid-template-columns', "".concat(newSidebarWidth, "px minmax(0, 1fr)"));
  135. }
  136. });
  137.  
  138. // 鼠标松开事件
  139. $(document).on('mouseup', function () {
  140. if (!isDragging) return;
  141. isDragging = false;
  142. // 恢复鼠标样式
  143. document.body.style.cursor = 'default';
  144. // 恢复拖拽条背景色
  145. $dragBar.css('background-color', 'transparent');
  146. // 记忆侧边栏宽度
  147. Store.set(storeKeys.sidebarWidth + host, newSidebarWidth);
  148. });
  149. };
  150. (function (_$) {
  151. 'use strict';
  152.  
  153. // 判断是否为 Discourse
  154. var generator = (_$ = $('meta[name="generator"]')) === null || _$ === void 0 ? void 0 : _$.attr('content');
  155. if (!generator || generator.indexOf('Discourse') == -1) return;
  156.  
  157. // 加载 CSS
  158. GM_addStyle(GM_getResourceText('css'));
  159. // layer 图标未知原因失效,手动添加样式
  160. $(document.head).append("<style>\n .layui-layer-ico{background:url('https://cdn.jsdelivr.net/npm/layer-src@3.5.1/dist/theme/default/icon.png') no-repeat}\n .layui-layer-ico1{background-position:-30px 0}\n .layui-layer-ico2{background-position:-60px 0}\n .layui-layer-ico3{background-position:-90px 0}\n .layui-layer-ico4{background-position:-120px 0}\n .layui-layer-ico5{background-position:-150px 0}\n .layui-layer-ico6{background-position:-180px 0}\n </style>");
  161. loadDragBar();
  162. })();
  163. /******/ })()
  164. ;
  165. //# sourceMappingURL=discourse-pro.user.js.map