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. // @grant GM_getValue
  58. // @grant GM_setValue
  59. // ==/UserScript==
  60.  
  61. // ==OpenUserJS==
  62. // @author duanluan
  63. // @updateURL https://raw.kkgithub.com/duanluan/tampermonkey-scripts/main/discourse-pro/dist/discourse-pro.user.js
  64. // ==/OpenUserJS==
  65.  
  66.  
  67. var host = location.host;
  68. var selector = {
  69. // 侧边栏和主内容的父容器
  70. mainOutletWrapper: '#main-outlet-wrapper',
  71. // 侧边栏
  72. sidebarWrapper: '.sidebar-wrapper',
  73. // 主内容
  74. mainOutlet: '#main-outlet'
  75. };
  76. var storeKeys = {
  77. // 侧边栏宽度
  78. sidebarWidth: 'sidebarWidth_'
  79. };
  80.  
  81. /**
  82. * 加载侧边栏和内容之前的拖拽条
  83. */
  84. var loadDragBar = function loadDragBar() {
  85. var $mainOutletWrapper = $(selector.mainOutletWrapper),
  86. $sidebarWrapper = $(selector.sidebarWrapper);
  87.  
  88. // 在侧边栏内部追加一个拖拽条
  89. $sidebarWrapper.append("\n <div class=\"drag-bar\" style=\"width: 4px; cursor: ew-resize\"></div>\n ");
  90. // 读取存储的侧边栏宽度
  91. var storeSidebarWidth = Store.get(storeKeys.sidebarWidth + host);
  92. if (storeSidebarWidth) {
  93. $mainOutletWrapper.css('grid-template-columns', "".concat(storeSidebarWidth, "px minmax(0, 1fr)"));
  94. }
  95.  
  96. // 拖拽条
  97. var $dragBar = $sidebarWrapper.find('.drag-bar');
  98. // 是否正在拖拽
  99. var isDragging = false;
  100. // 鼠标按下时的 clientX
  101. var startClientX = 0;
  102. // 鼠标按下时的侧边栏宽度
  103. var startSidebarWidth = 0;
  104. // 侧边栏宽度范围
  105. var minSidebarWidth = 180,
  106. maxSidebarWidth = 500;
  107. var newSidebarWidth = 0;
  108.  
  109. // 鼠标按下事件
  110. $dragBar.on('mousedown', function (e) {
  111. startClientX = e.clientX;
  112. startSidebarWidth = $sidebarWrapper.width();
  113. isDragging = true;
  114. // 改变鼠标样式
  115. document.body.style.cursor = 'ew-resize';
  116. // 设置拖拽条背景色
  117. $dragBar.css('background-color', '#e6e6e6');
  118. // 防止文本被选中
  119. e.preventDefault();
  120. });
  121.  
  122. // 鼠标移动事件
  123. $(document).on('mousemove', function (e) {
  124. if (!isDragging) return;
  125.  
  126. // 计算新的宽度
  127. var deltaX = e.clientX - startClientX;
  128. newSidebarWidth = startSidebarWidth + deltaX;
  129. if (newSidebarWidth >= minSidebarWidth && newSidebarWidth <= maxSidebarWidth) {
  130. $mainOutletWrapper.css('grid-template-columns', "".concat(newSidebarWidth, "px minmax(0, 1fr)"));
  131. }
  132. });
  133.  
  134. // 鼠标松开事件
  135. $(document).on('mouseup', function () {
  136. if (!isDragging) return;
  137. isDragging = false;
  138. // 恢复鼠标样式
  139. document.body.style.cursor = 'default';
  140. // 恢复拖拽条背景色
  141. $dragBar.css('background-color', 'transparent');
  142. // 记忆侧边栏宽度
  143. Store.set(storeKeys.sidebarWidth + host, newSidebarWidth);
  144. });
  145. };
  146. (function (_$) {
  147. 'use strict';
  148.  
  149. // 判断是否为 Discourse
  150. var generator = (_$ = $('meta[name="generator"]')) === null || _$ === void 0 ? void 0 : _$.attr('content');
  151. if (!generator || generator.indexOf('Discourse') == -1) return;
  152. loadDragBar();
  153. })();
  154. /******/ })()
  155. ;
  156. //# sourceMappingURL=discourse-pro.user.js.map