Discourse Pro

增强 Discourse 论坛。

目前為 2024-12-15 提交的版本,檢視 最新版本

  1. /******/ (() => { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ var __webpack_modules__ = ({
  4.  
  5. /***/ "./utils/src/gm/Store.ts":
  6. /*!*******************************!*\
  7. !*** ./utils/src/gm/Store.ts ***!
  8. \*******************************/
  9. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  10.  
  11. __webpack_require__.r(__webpack_exports__);
  12. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  13. /* harmony export */ "default": () => (/* binding */ Store)
  14. /* harmony export */ });
  15. 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); }
  16. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17. 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); } }
  18. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  19. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  20. 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); }
  21. /**
  22. * 存储
  23. */
  24. var Store = /*#__PURE__*/function () {
  25. function Store() {
  26. _classCallCheck(this, Store);
  27. }
  28. return _createClass(Store, null, [{
  29. key: "get",
  30. value:
  31. /**
  32. * 获取
  33. * @param key 键
  34. */
  35. function get(key) {
  36. return GM_getValue(key);
  37. }
  38.  
  39. /**
  40. * 设置
  41. * @param key 键
  42. * @param value 值
  43. */
  44. }, {
  45. key: "set",
  46. value: function set(key, value) {
  47. GM_setValue(key, value);
  48. }
  49. }]);
  50. }();
  51.  
  52.  
  53. /***/ })
  54.  
  55. /******/ });
  56. /************************************************************************/
  57. /******/ // The module cache
  58. /******/ var __webpack_module_cache__ = {};
  59. /******/
  60. /******/ // The require function
  61. /******/ function __webpack_require__(moduleId) {
  62. /******/ // Check if module is in cache
  63. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  64. /******/ if (cachedModule !== undefined) {
  65. /******/ return cachedModule.exports;
  66. /******/ }
  67. /******/ // Create a new module (and put it into the cache)
  68. /******/ var module = __webpack_module_cache__[moduleId] = {
  69. /******/ // no module.id needed
  70. /******/ // no module.loaded needed
  71. /******/ exports: {}
  72. /******/ };
  73. /******/
  74. /******/ // Execute the module function
  75. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  76. /******/
  77. /******/ // Return the exports of the module
  78. /******/ return module.exports;
  79. /******/ }
  80. /******/
  81. /************************************************************************/
  82. /******/ /* webpack/runtime/define property getters */
  83. /******/ (() => {
  84. /******/ // define getter functions for harmony exports
  85. /******/ __webpack_require__.d = (exports, definition) => {
  86. /******/ for(var key in definition) {
  87. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  88. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  89. /******/ }
  90. /******/ }
  91. /******/ };
  92. /******/ })();
  93. /******/
  94. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  95. /******/ (() => {
  96. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  97. /******/ })();
  98. /******/
  99. /******/ /* webpack/runtime/make namespace object */
  100. /******/ (() => {
  101. /******/ // define __esModule on exports
  102. /******/ __webpack_require__.r = (exports) => {
  103. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  104. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  105. /******/ }
  106. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  107. /******/ };
  108. /******/ })();
  109. /******/
  110. /************************************************************************/
  111. var __webpack_exports__ = {};
  112. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  113. (() => {
  114. /*!***********************************!*\
  115. !*** ./discourse-pro/src/main.ts ***!
  116. \***********************************/
  117. __webpack_require__.r(__webpack_exports__);
  118. /* harmony import */ var _utils_gm_Store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @utils/gm/Store */ "./utils/src/gm/Store.ts");
  119. // ==UserScript==
  120. // @name Discourse Pro
  121. // @namespace http://tampermonkey.net/
  122. // @version 0.0.1
  123. // @description 增强 Discourse 论坛。
  124. // @author duanluan
  125. // @copyright 2024, duanluan (https://github.com/duanluan)
  126. // @license Apache-2.0; https://www.apache.org/licenses/LICENSE-2.0.txt
  127. // @homepage https://greasyfork.org/zh-CN/scripts/520817
  128. // @supportURL https://github.com/duanluan/tampermonkey-scripts/issues
  129. // @match *://linux.do/*
  130. // @match *://meta.appinn.net/*
  131. // @require https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js
  132. // @resource css https://cdn.jsdelivr.net/npm/layer-src@3.5.1/src/theme/default/layer.min.css
  133. // @require https://cdn.jsdelivr.net/npm/layer-src@3.5.1/src/layer.min.js
  134. // @grant GM_addStyle
  135. // @grant GM_getResourceText
  136. // @grant GM_getValue
  137. // @grant GM_setValue
  138. // ==/UserScript==
  139.  
  140. // ==OpenUserJS==
  141. // @author duanluan
  142. // @updateURL https://raw.kkgithub.com/duanluan/tampermonkey-scripts/main/discourse-pro/dist/discourse-pro.user.js
  143. // ==/OpenUserJS==
  144.  
  145.  
  146. var host = location.host;
  147. var selector = {
  148. // 侧边栏和主内容的父容器
  149. mainOutletWrapper: '#main-outlet-wrapper',
  150. // 侧边栏
  151. sidebarWrapper: '.sidebar-wrapper',
  152. // 主内容
  153. mainOutlet: '#main-outlet'
  154. };
  155. var storeKeys = {
  156. // 侧边栏宽度
  157. sidebarWidth: 'sidebarWidth_'
  158. };
  159.  
  160. /**
  161. * 加载侧边栏和内容之前的拖拽条
  162. */
  163. var loadDragBar = function loadDragBar() {
  164. var $mainOutletWrapper = $(selector.mainOutletWrapper),
  165. $sidebarWrapper = $(selector.sidebarWrapper);
  166.  
  167. // 在侧边栏内部追加一个拖拽条
  168. $sidebarWrapper.append("\n <div class=\"drag-bar\" style=\"width: 4px; cursor: ew-resize\"></div>\n ");
  169. // 读取存储的侧边栏宽度
  170. var storeSidebarWidth = _utils_gm_Store__WEBPACK_IMPORTED_MODULE_0__["default"].get(storeKeys.sidebarWidth + host);
  171. if (storeSidebarWidth) {
  172. $mainOutletWrapper.css('grid-template-columns', "".concat(storeSidebarWidth, "px minmax(0, 1fr)"));
  173. }
  174.  
  175. // 拖拽条
  176. var $dragBar = $sidebarWrapper.find('.drag-bar');
  177. // 是否正在拖拽
  178. var isDragging = false;
  179. // 鼠标按下时的 clientX
  180. var startClientX = 0;
  181. // 鼠标按下时的侧边栏宽度
  182. var startSidebarWidth = 0;
  183. // 侧边栏宽度范围
  184. var minSidebarWidth = 180,
  185. maxSidebarWidth = 500;
  186. var newSidebarWidth = 0;
  187.  
  188. // 鼠标按下事件
  189. $dragBar.on('mousedown', function (e) {
  190. startClientX = e.clientX;
  191. startSidebarWidth = $sidebarWrapper.width();
  192. isDragging = true;
  193. // 改变鼠标样式
  194. document.body.style.cursor = 'ew-resize';
  195. // 设置拖拽条背景色
  196. $dragBar.css('background-color', '#e6e6e6');
  197. // 防止文本被选中
  198. e.preventDefault();
  199. });
  200.  
  201. // 鼠标移动事件
  202. $(document).on('mousemove', function (e) {
  203. if (!isDragging) return;
  204.  
  205. // 计算新的宽度
  206. var deltaX = e.clientX - startClientX;
  207. newSidebarWidth = startSidebarWidth + deltaX;
  208. if (newSidebarWidth >= minSidebarWidth && newSidebarWidth <= maxSidebarWidth) {
  209. $mainOutletWrapper.css('grid-template-columns', "".concat(newSidebarWidth, "px minmax(0, 1fr)"));
  210. }
  211. });
  212.  
  213. // 鼠标松开事件
  214. $(document).on('mouseup', function () {
  215. if (!isDragging) return;
  216. isDragging = false;
  217. // 恢复鼠标样式
  218. document.body.style.cursor = 'default';
  219. // 恢复拖拽条背景色
  220. $dragBar.css('background-color', 'transparent');
  221. // 记忆侧边栏宽度
  222. _utils_gm_Store__WEBPACK_IMPORTED_MODULE_0__["default"].set(storeKeys.sidebarWidth + host, newSidebarWidth);
  223. });
  224. };
  225. (function (_$) {
  226. 'use strict';
  227.  
  228. // 判断是否为 Discourse
  229. var generator = (_$ = $('meta[name="generator"]')) === null || _$ === void 0 ? void 0 : _$.attr('content');
  230. if (!generator || generator.indexOf('Discourse') == -1) return;
  231.  
  232. // 加载 CSS
  233. GM_addStyle(GM_getResourceText('css'));
  234. // layer 图标未知原因失效,手动添加样式
  235. $(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>");
  236. loadDragBar();
  237. })();
  238. })();
  239.  
  240. /******/ })()
  241. ;
  242. //# sourceMappingURL=discourse-pro.user.js.map