Discourse Pro

增强 Discourse 论坛。

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

  1. /******/ (() => { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ var __webpack_modules__ = ({
  4.  
  5. /***/ 545:
  6. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  7.  
  8.  
  9. // EXPORTS
  10. __webpack_require__.d(__webpack_exports__, {
  11. A: () => (/* binding */ Options)
  12. });
  13.  
  14. // EXTERNAL MODULE: ./utils/src/gm/Store.ts
  15. var Store = __webpack_require__(915);
  16. ;// CONCATENATED MODULE: ./utils/src/gm/MenuCmd.ts
  17. 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); }
  18. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19. 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); } }
  20. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  21. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  22. 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); }
  23. /**
  24. * 选项菜单
  25. */
  26. var MenuCmd = /*#__PURE__*/function () {
  27. function MenuCmd() {
  28. _classCallCheck(this, MenuCmd);
  29. }
  30. return _createClass(MenuCmd, null, [{
  31. key: "register",
  32. value:
  33. /**
  34. * 注册
  35. * @param name 名称
  36. * @param fn 点击菜单时执行的函数
  37. */
  38. function register(name, fn) {
  39. return GM_registerMenuCommand(name, fn);
  40. }
  41.  
  42. /**
  43. * 注销
  44. * @param menuCmdId 注册时返回的 ID
  45. */
  46. }, {
  47. key: "unregister",
  48. value: function unregister(menuCmdId) {
  49. GM_unregisterMenuCommand(menuCmdId);
  50. }
  51. }]);
  52. }();
  53.  
  54. ;// CONCATENATED MODULE: ./utils/src/CommonOptions.ts
  55. function CommonOptions_typeof(o) { "@babel/helpers - typeof"; return CommonOptions_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; }, CommonOptions_typeof(o); }
  56. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  57. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  58. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
  59. function CommonOptions_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  60. function CommonOptions_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, CommonOptions_toPropertyKey(descriptor.key), descriptor); } }
  61. function CommonOptions_createClass(Constructor, protoProps, staticProps) { if (protoProps) CommonOptions_defineProperties(Constructor.prototype, protoProps); if (staticProps) CommonOptions_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  62. function CommonOptions_toPropertyKey(t) { var i = CommonOptions_toPrimitive(t, "string"); return "symbol" == CommonOptions_typeof(i) ? i : i + ""; }
  63. function CommonOptions_toPrimitive(t, r) { if ("object" != CommonOptions_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != CommonOptions_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  64.  
  65.  
  66.  
  67. /**
  68. * 选项菜单
  69. */
  70. var CommonOptions = /*#__PURE__*/function () {
  71. function CommonOptions() {
  72. CommonOptions_classCallCheck(this, CommonOptions);
  73. }
  74. return CommonOptions_createClass(CommonOptions, null, [{
  75. key: "registerBoolOption",
  76. value:
  77. /**
  78. * 注册 bool 类型的选项
  79. *
  80. * @param option 选项
  81. */
  82. function registerBoolOption(option) {
  83. var _this = this;
  84. var val = option.value,
  85. valIsBool = typeof val === 'boolean';
  86. if (!valIsBool) {
  87. return;
  88. }
  89. // 注册选项和选项点击事件
  90. var currentMenuCmdId = MenuCmd.register((val ? '✅ ' : '🔲 ') + option.label, function () {
  91. // 点击后取反
  92. option.value = !option.value;
  93. Store/* default */.A.set(option.name, JSON.stringify(option));
  94.  
  95. // 重新注册
  96. MenuCmd.unregister(currentMenuCmdId);
  97. _this.registerBoolOption(option);
  98. // 刷新页面
  99. window.location.reload();
  100. });
  101.  
  102. // 保存选项 ID
  103. option.menuCmdId = currentMenuCmdId;
  104. Store/* default */.A.set(option.name, JSON.stringify(option));
  105. }
  106.  
  107. /**
  108. * 注册所有选项
  109. *
  110. * @param options 选项
  111. * @param moreOptionsUrl 更多设置页面 URL
  112. */
  113. }, {
  114. key: "registerAll",
  115. value: function registerAll(options, moreOptionsUrl) {
  116. // 注册“更多设置”选项,点击后打开新页面
  117. MenuCmd.register('更多设置', function () {
  118. window.open(moreOptionsUrl, '_blank');
  119. });
  120. var _iterator = _createForOfIteratorHelper(options),
  121. _step;
  122. try {
  123. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  124. var option = _step.value;
  125. // TODO 【调试】不保留选项的值,每次都从 Store 中获取
  126. // Store.set(option.name, null);
  127.  
  128. var storeOption = Store/* default */.A.get(option.name) ? JSON.parse(Store/* default */.A.get(option.name)) : null;
  129. // 如果选项不存在 || 版本不一致 时重置选项
  130. if (storeOption === null || !storeOption['version'] || storeOption['version'] < option.version) {
  131. Store/* default */.A.set(option.name, JSON.stringify(option));
  132. storeOption = option;
  133. }
  134. this.registerBoolOption(storeOption);
  135. }
  136. } catch (err) {
  137. _iterator.e(err);
  138. } finally {
  139. _iterator.f();
  140. }
  141. }
  142.  
  143. /**
  144. * 在 Greasy Fork 脚本详情页中加载选项
  145. *
  146. * @param scriptId 脚本 ID
  147. * @param loadOptionContentFn 加载选项内容的函数
  148. */
  149. }, {
  150. key: "loadInGreasyfork",
  151. value: function loadInGreasyfork(scriptId, loadOptionContentFn) {
  152. // 非脚本详情页结束
  153. if (location.host !== 'greasyfork.org' || location.href.indexOf('/scripts/' + scriptId) == -1) {
  154. return;
  155. }
  156. var selector = {
  157. scriptLinks: '#script-links',
  158. scriptOptions: '#script-options',
  159. scriptContent: '#script-content'
  160. };
  161. var $body = $(document.body),
  162. $scriptLinks = $(selector.scriptLinks),
  163. $scriptContent = $(selector.scriptContent);
  164.  
  165. // 添加“脚本设置”选项卡和点击事件
  166. $scriptLinks.children('li:eq(0)').after("<li><a href=\"javascript:;\" id=\"script-options\">\u811A\u672C\u8BBE\u7F6E</a></li>");
  167. $body.on('click', selector.scriptOptions, function () {
  168. // 移除其他已选中选项的样式
  169. var $currentLi = $scriptLinks.children('li.current');
  170. $currentLi.html("<a href=\"".concat(location.href, "\">").concat($currentLi.text(), "</a>"));
  171. $currentLi.removeClass('current');
  172. // 给“脚本设置”选项卡添加选中选项的样式
  173. var $scriptOptions = $(selector.scriptOptions);
  174. $scriptOptions.parent().addClass('current');
  175. loadOptionContentFn($scriptContent);
  176. });
  177. }
  178. }]);
  179. }();
  180.  
  181. ;// CONCATENATED MODULE: ./discourse-pro/src/Options.ts
  182. var _Options;
  183. function Options_typeof(o) { "@babel/helpers - typeof"; return Options_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; }, Options_typeof(o); }
  184. function Options_createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = Options_unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  185. function Options_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return Options_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Options_arrayLikeToArray(o, minLen); }
  186. function Options_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
  187. function Options_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  188. function Options_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, Options_toPropertyKey(descriptor.key), descriptor); } }
  189. function Options_createClass(Constructor, protoProps, staticProps) { if (protoProps) Options_defineProperties(Constructor.prototype, protoProps); if (staticProps) Options_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  190. function _defineProperty(obj, key, value) { key = Options_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  191. function Options_toPropertyKey(t) { var i = Options_toPrimitive(t, "string"); return "symbol" == Options_typeof(i) ? i : i + ""; }
  192. function Options_toPrimitive(t, r) { if ("object" != Options_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != Options_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  193.  
  194.  
  195.  
  196. var Options = /*#__PURE__*/function () {
  197. function Options() {
  198. Options_classCallCheck(this, Options);
  199. }
  200. return Options_createClass(Options, null, [{
  201. key: "registerBoolOption",
  202. value:
  203. /**
  204. * 注册 bool 类型的选项
  205. * @param option 选项
  206. */
  207. function registerBoolOption(option) {
  208. CommonOptions.registerBoolOption(option);
  209. }
  210.  
  211. /**
  212. * 注册所有选项
  213. */
  214. }, {
  215. key: "registerAll",
  216. value: function registerAll() {
  217. CommonOptions.registerAll(this.options, 'https://greasyfork.org/scripts/' + this.SCRIPT_ID);
  218. }
  219. }, {
  220. key: "onChangByBoolOption",
  221. value: function onChangByBoolOption(key) {
  222. var _this = this;
  223. var optionSelector = '#script-options-' + key;
  224. $(document.body).on('change', optionSelector, function () {
  225. var option = JSON.parse(Store/* default */.A.get(key));
  226. option.value = !option.value;
  227. // 重新注册选项
  228. MenuCmd.unregister(option.menuCmdId);
  229. _this.registerBoolOption(option);
  230. });
  231. }
  232.  
  233. /**
  234. * 在页面中加载选项
  235. */
  236. }, {
  237. key: "loadInGreasyfork",
  238. value: function loadInGreasyfork() {
  239. var _this2 = this;
  240. CommonOptions.loadInGreasyfork(this.SCRIPT_ID, function ($scriptContent) {
  241. // 添加脚本设置的内容
  242. var scriptContent = '';
  243. var _iterator = Options_createForOfIteratorHelper(_this2.options),
  244. _step;
  245. try {
  246. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  247. var option = _step.value;
  248. var storeOption = JSON.parse(Store/* default */.A.get(option.name)),
  249. optionName = storeOption.name,
  250. optionVal = storeOption.value;
  251. scriptContent += "<h3>".concat(option.label, "</h3>");
  252. switch (optionName) {
  253. case _this2.Keys.dragBar:
  254. scriptContent += "<label><input type=\"checkbox\" id=\"script-options-".concat(optionName, "\" ").concat(optionVal ? 'checked' : '', "> \u4FA7\u8FB9\u680F\u62D6\u62FD\u6761\uFF08\u4FA7\u8FB9\u680F\u548C\u4E3B\u5185\u5BB9\u95F4\u6DFB\u52A0\u62D6\u62FD\u6761\uFF0C\u7528\u4E8E\u8C03\u6574\u4E24\u8005\u5BBD\u5EA6\uFF09</label>");
  255. break;
  256. case _this2.Keys.widescreenMode:
  257. scriptContent += "<label><input type=\"checkbox\" id=\"script-options-".concat(optionName, "\" ").concat(optionVal ? 'checked' : '', "> \u5BBD\u5C4F\u6A21\u5F0F</label>");
  258. break;
  259. }
  260. }
  261. } catch (err) {
  262. _iterator.e(err);
  263. } finally {
  264. _iterator.f();
  265. }
  266. $scriptContent.html(scriptContent);
  267.  
  268. // 侧边栏拖拽条
  269. _this2.onChangByBoolOption(_this2.Keys.dragBar);
  270. // 宽屏模式
  271. _this2.onChangByBoolOption(_this2.Keys.widescreenMode);
  272. });
  273. }
  274. }]);
  275. }();
  276. _Options = Options;
  277. _defineProperty(Options, "SCRIPT_ID", 520817);
  278. /**
  279. * 选项 Key
  280. */
  281. _defineProperty(Options, "Keys", {
  282. dragBar: 'dragBar',
  283. widescreenMode: 'widescreenMode'
  284. });
  285. /**
  286. * 选项
  287. * @private
  288. */
  289. _defineProperty(Options, "options", [{
  290. label: '侧边栏拖拽条',
  291. name: _Options.Keys.dragBar,
  292. version: 1,
  293. value: false,
  294. menuCmdId: null
  295. }, {
  296. label: '宽屏模式',
  297. name: _Options.Keys.widescreenMode,
  298. version: 1,
  299. value: false,
  300. menuCmdId: null,
  301. token: ''
  302. }]);
  303.  
  304.  
  305. /***/ }),
  306.  
  307. /***/ 150:
  308. /***/ ((__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) => {
  309.  
  310.  
  311. // EXTERNAL MODULE: ./utils/src/gm/Store.ts
  312. var Store = __webpack_require__(915);
  313. ;// CONCATENATED MODULE: ./discourse-pro/src/module/widescreenMode.ts
  314. /**
  315. * 加载宽屏模式
  316. * @param options
  317. */
  318. function loadWidescreenMode(options) {
  319. var headerWrap = options.headerWrap,
  320. mainOutletWrapper = options.mainOutletWrapper,
  321. mainOutlet = options.mainOutlet;
  322. var $headerWrap = $(headerWrap),
  323. $mainOutletWrapper = $(mainOutletWrapper),
  324. $mainOutlet = $(mainOutlet);
  325.  
  326. // 顶部撑满
  327. $headerWrap.css('max-width', '100%');
  328. // 侧边栏和主内容撑满
  329. $mainOutletWrapper.css('max-width', '100%');
  330. // 主内容撑满
  331. $mainOutlet.css('width', '100%');
  332. loadWidescreenModeByTopic(options);
  333. }
  334.  
  335. /**
  336. * 话题页加载宽屏模式
  337. * @param options
  338. */
  339. function loadWidescreenModeByTopic(options) {
  340. var postStream = options.postStream,
  341. topicAvatar = options.topicAvatar,
  342. topicBody = options.topicBody,
  343. topicMap = options.topicMap,
  344. loadingContainer = options.loadingContainer,
  345. topicTimerInfo = options.topicTimerInfo,
  346. topicFooterBtns = options.topicFooterBtns,
  347. moreTopicsContainer = options.moreTopicsContainer;
  348. var $postStream = $(postStream),
  349. $topicAvatar = $(topicAvatar),
  350. $topicBody = $(topicBody),
  351. $topicMap = $(topicMap),
  352. $loadingContainer = $(loadingContainer),
  353. $topicTimerInfo = $(topicTimerInfo),
  354. $topicFooterBtns = $(topicFooterBtns),
  355. $moreTopicsContainer = $(moreTopicsContainer);
  356. if (location.href.indexOf('/topic/') != -1) {
  357. var postStreamWidth = $postStream.width();
  358. var topicAvatarWidth = $topicAvatar.width();
  359. var topicWidth = postStreamWidth - 45;
  360. // 话题内容撑满
  361. $topicBody.css('width', topicWidth - topicAvatarWidth + 'px');
  362. // 话题主内容后浏览量、链接、回复人等信息撑满
  363. $topicMap.css('max-width', topicWidth + 'px');
  364. // 最后一个回复后的底边框撑满
  365. $loadingContainer.css('width', topicWidth + 'px');
  366. $topicTimerInfo.css('max-width', topicWidth + 'px');
  367. // 话题底部按钮撑满
  368. $topicFooterBtns.css('max-width', topicWidth + 'px');
  369. // 更多话题列表撑满
  370. $moreTopicsContainer.css('max-width', topicWidth + 'px');
  371. }
  372. }
  373.  
  374. ;// CONCATENATED MODULE: ./discourse-pro/src/module/dragBar.ts
  375.  
  376.  
  377. function loadDragBar(options) {
  378. var mainOutletWrapper = options.mainOutletWrapper,
  379. sidebarWrapper = options.sidebarWrapper,
  380. sidebar = options.sidebar,
  381. headerSidebarToggleBtn = options.headerSidebarToggleBtn,
  382. sidebarWidthKey = options.sidebarWidthKey,
  383. minSidebarWidth = options.minSidebarWidth,
  384. maxSidebarWidth = options.maxSidebarWidth;
  385. var $mainOutletWrapper = $(mainOutletWrapper),
  386. $sidebarWrapper = $(sidebarWrapper),
  387. $sidebar = $(sidebar),
  388. $headerSidebarToggleBtn = $(headerSidebarToggleBtn);
  389.  
  390. // 侧边栏是否存在
  391. var sidebarExist = $sidebar.length > 0;
  392. if (sidebarExist) {
  393. // 读取存储的侧边栏宽度
  394. var storeSidebarWidth = Store/* default */.A.get(sidebarWidthKey);
  395. if (storeSidebarWidth) {
  396. $mainOutletWrapper.css('grid-template-columns', "".concat(storeSidebarWidth, "px minmax(0, 1fr)"));
  397. }
  398. }
  399.  
  400. // 在侧边栏内部追加一个拖拽条
  401. $sidebarWrapper.append("\n <div class=\"drag-bar\" style=\"width: 4px; cursor: ew-resize\"></div>\n ");
  402.  
  403. // 拖拽条
  404. var $dragBar = $sidebarWrapper.find('.drag-bar');
  405. // 是否正在拖拽
  406. var isDragging = false;
  407. // 鼠标按下时的 clientX
  408. var startClientX = 0;
  409. // 鼠标按下时的侧边栏宽度
  410. var startSidebarWidth = 0;
  411. // 侧边栏新宽度
  412. var newSidebarWidth = 0;
  413.  
  414. // 鼠标按下事件
  415. $dragBar.on('mousedown', function (e) {
  416. startClientX = e.clientX;
  417. startSidebarWidth = $sidebarWrapper.width() || 0;
  418. isDragging = true;
  419. // 改变鼠标样式
  420. document.body.style.cursor = 'ew-resize';
  421. // 设置拖拽条背景色
  422. $dragBar.css('background-color', '#e6e6e6');
  423. // 防止文本被选中
  424. e.preventDefault();
  425. });
  426.  
  427. // 鼠标移动事件
  428. $(document).on('mousemove', function (e) {
  429. if (!isDragging) return;
  430.  
  431. // 计算新的宽度
  432. var deltaX = e.clientX - startClientX;
  433. newSidebarWidth = Math.min(maxSidebarWidth, Math.max(minSidebarWidth, startSidebarWidth + deltaX));
  434. $mainOutletWrapper.css('grid-template-columns', "".concat(newSidebarWidth, "px minmax(0, 1fr)"));
  435. loadWidescreenModeByTopic(options);
  436. });
  437.  
  438. // 鼠标松开事件
  439. $(document).on('mouseup', function () {
  440. if (!isDragging) return;
  441. isDragging = false;
  442. // 恢复鼠标样式
  443. document.body.style.cursor = 'default';
  444. // 恢复拖拽条背景色
  445. $dragBar.css('background-color', 'transparent');
  446. // 记忆侧边栏宽度
  447. Store/* default */.A.set(sidebarWidthKey, newSidebarWidth);
  448. });
  449.  
  450. // 展开收起侧边栏按钮点击事件
  451. $headerSidebarToggleBtn.on('click', function () {
  452. sidebarExist = !sidebarExist;
  453. $mainOutletWrapper.css('grid-template-columns', "".concat(sidebarExist ? Store/* default */.A.get(sidebarWidthKey) + 'px' : '0', " minmax(0, 1fr)"));
  454. });
  455. }
  456. // EXTERNAL MODULE: ./discourse-pro/src/Options.ts + 2 modules
  457. var Options = __webpack_require__(545);
  458. ;// CONCATENATED MODULE: ./discourse-pro/src/main.ts
  459. 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); }
  460. function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
  461. function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
  462. function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  463. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  464. 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); }
  465. // ==UserScript==
  466. // @name Discourse Pro
  467. // @namespace http://tampermonkey.net/
  468. // @version 0.1.1
  469. // @description 增强 Discourse 论坛。
  470. // @author duanluan
  471. // @copyright 2024, duanluan (https://github.com/duanluan)
  472. // @license Apache-2.0; https://www.apache.org/licenses/LICENSE-2.0.txt
  473. // @homepage https://greasyfork.org/zh-CN/scripts/520817
  474. // @supportURL https://github.com/duanluan/tampermonkey-scripts/issues
  475. // @match *://greasyfork.org/*
  476. // @match *://linux.do/*
  477. // @match *://meta.appinn.net/*
  478. // @require https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js
  479. // @grant GM_getValue
  480. // @grant GM_setValue
  481. // @grant GM_registerMenuCommand
  482. // @grant GM_unregisterMenuCommand
  483. // ==/UserScript==
  484.  
  485. // ==OpenUserJS==
  486. // @author duanluan
  487. // @updateURL https://raw.kkgithub.com/duanluan/tampermonkey-scripts/main/discourse-pro/dist/discourse-pro.user.js
  488. // ==/OpenUserJS==
  489.  
  490.  
  491.  
  492.  
  493.  
  494. (function (_$) {
  495. 'use strict';
  496.  
  497. Options/* default */.A.registerAll();
  498. Options/* default */.A.loadInGreasyfork();
  499.  
  500. // 判断是否为 Discourse
  501. var generator = (_$ = $('meta[name="generator"]')) === null || _$ === void 0 ? void 0 : _$.attr('content');
  502. if (!generator || generator.indexOf('Discourse') == -1) return;
  503. var selector = {
  504. headerWrap: '.d-header>.wrap',
  505. // 侧边栏展开收起按钮
  506. headerSidebarToggleBtn: '.header-sidebar-toggle>button',
  507. // 侧边栏和主内容的父容器
  508. mainOutletWrapper: '#main-outlet-wrapper',
  509. // 侧边栏
  510. sidebarWrapper: '.sidebar-wrapper',
  511. sidebar: '#d-sidebar',
  512. // 主内容
  513. mainOutlet: '#main-outlet',
  514. // 话题内容父容器
  515. postStream: '.post-stream',
  516. // 话题头像
  517. topicAvatar: '.topic-avatar',
  518. // 话题内容
  519. topicBody: '.topic-body',
  520. // 话题主内容后浏览量、链接、回复人等信息
  521. topicMap: '.topic-map',
  522. // 最后一个回复后的底边框
  523. loadingContainer: '.loading-container',
  524. topicTimerInfo: '.topic-timer-info',
  525. // 话题底部按钮
  526. topicFooterBtns: '#topic-footer-buttons',
  527. // 更多话题列表
  528. moreTopicsContainer: '.more-topics__container'
  529. };
  530. var storeKeys = {
  531. // 侧边栏宽度
  532. sidebarWidth: 'sidebarWidth_'
  533. };
  534.  
  535. // 加载拖拽条
  536. if (JSON.parse(Store/* default */.A.get(Options/* default */.A.Keys.dragBar)).value) {
  537. loadDragBar(_objectSpread(_objectSpread({}, selector), {}, {
  538. sidebarWidthKey: storeKeys.sidebarWidth + location.host,
  539. minSidebarWidth: 180,
  540. maxSidebarWidth: 500
  541. }));
  542. }
  543. // 加载宽屏模式
  544. if (JSON.parse(Store/* default */.A.get(Options/* default */.A.Keys.widescreenMode)).value) {
  545. loadWidescreenMode(_objectSpread({}, selector));
  546. }
  547. })();
  548.  
  549. /***/ }),
  550.  
  551. /***/ 915:
  552. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  553.  
  554. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  555. /* harmony export */ A: () => (/* binding */ Store)
  556. /* harmony export */ });
  557. 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); }
  558. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  559. 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); } }
  560. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  561. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  562. 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); }
  563. /**
  564. * 存储
  565. */
  566. var Store = /*#__PURE__*/function () {
  567. function Store() {
  568. _classCallCheck(this, Store);
  569. }
  570. return _createClass(Store, null, [{
  571. key: "get",
  572. value:
  573. /**
  574. * 获取
  575. * @param key 键
  576. */
  577. function get(key) {
  578. return GM_getValue(key);
  579. }
  580.  
  581. /**
  582. * 设置
  583. * @param key 键
  584. * @param value 值
  585. */
  586. }, {
  587. key: "set",
  588. value: function set(key, value) {
  589. GM_setValue(key, value);
  590. }
  591. }]);
  592. }();
  593.  
  594.  
  595. /***/ })
  596.  
  597. /******/ });
  598. /************************************************************************/
  599. /******/ // The module cache
  600. /******/ var __webpack_module_cache__ = {};
  601. /******/
  602. /******/ // The require function
  603. /******/ function __webpack_require__(moduleId) {
  604. /******/ // Check if module is in cache
  605. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  606. /******/ if (cachedModule !== undefined) {
  607. /******/ return cachedModule.exports;
  608. /******/ }
  609. /******/ // Create a new module (and put it into the cache)
  610. /******/ var module = __webpack_module_cache__[moduleId] = {
  611. /******/ // no module.id needed
  612. /******/ // no module.loaded needed
  613. /******/ exports: {}
  614. /******/ };
  615. /******/
  616. /******/ // Execute the module function
  617. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  618. /******/
  619. /******/ // Return the exports of the module
  620. /******/ return module.exports;
  621. /******/ }
  622. /******/
  623. /************************************************************************/
  624. /******/ /* webpack/runtime/define property getters */
  625. /******/ (() => {
  626. /******/ // define getter functions for harmony exports
  627. /******/ __webpack_require__.d = (exports, definition) => {
  628. /******/ for(var key in definition) {
  629. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  630. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  631. /******/ }
  632. /******/ }
  633. /******/ };
  634. /******/ })();
  635. /******/
  636. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  637. /******/ (() => {
  638. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  639. /******/ })();
  640. /******/
  641. /************************************************************************/
  642. /******/
  643. /******/ // startup
  644. /******/ // Load entry module and return exports
  645. /******/ // This entry module is referenced by other modules so it can't be inlined
  646. /******/ __webpack_require__(545);
  647. /******/ var __webpack_exports__ = __webpack_require__(150);
  648. /******/
  649. /******/ })()
  650. ;
  651. //# sourceMappingURL=discourse-pro.user.js.map