Sleazy Fork is available in English.

保国逛色花

最好用的98堂(原色花堂)脚本 高级搜索 自动签到 快速复制 快速评分 划词搜索 图片预览 快速收藏

  1. // ==UserScript==
  2. // @name 保国逛色花
  3. // @namespace https://www.sehuatang.net
  4. // @version 100.8
  5. // @description 最好用的98堂(原色花堂)脚本 高级搜索 自动签到 快速复制 快速评分 划词搜索 图片预览 快速收藏
  6. // @author 性感风骚马保国
  7. // @match *://*.sehuatang.net/*
  8. // @match *://*.sehuatang.org/*
  9. // @match *://*.sehuatang.*/*
  10. // @match *://*.jq2t4.com/*
  11. // @match *://*.0krgb.com/*
  12. // @match *://*.xxjsnc.co/*
  13. // @match *://*.o4vag.com/*
  14. // @match *://*.weterytrtrr.*/*
  15. // @match *://*.qweqwtret.*/*
  16. // @match *://*.retreytryuyt.*/*
  17. // @match *://*.qwerwrrt.*/*
  18. // @match *://*.ds5hk.app/*
  19. // @match *://*.30fjp.com/*
  20. // @match *://*.18stm.cn/*
  21. // @match *://*.xo6c5.com/*
  22. // @match *://*.mzjvl.com/*
  23. // @match *://*.9xr2.app/*
  24. // @match *://*.kzs1w.com/*
  25. // @match *://*.nwurc.com/*
  26. // @match *://*.zbkz6.app/*
  27. // @match *://*.ql75t.cn/*
  28. // @match *://*.0uzb0.app/*
  29. // @match *://*.d2wpb.com/*
  30. // @match *://*.5aylp.com/*
  31. // @match *://*.8otvk.app/*
  32. // @match *://*.05kx.cc/*
  33. // @match *://*.1yxg2.com/*
  34. // @match *://*.6r5gy.co/*
  35. // @match *://*.mmpbg.co/*
  36. // @match *://*.kofqo.com/*
  37. // @match *://*.kofqo.net/*
  38. // @match *://*.5rmt2.net/*
  39. // @match *://*.n8cv.net/*
  40. // @grant GM_getValue
  41. // @grant GM_setValue
  42. // @grant GM_registerMenuCommand
  43. // @grant GM_xmlhttpRequest
  44. // @license GPL-3.0 License
  45. // ==/UserScript==
  46.  
  47. (async function () {
  48. "use strict";
  49. /* global showWindow */
  50. /* global stopRandomSelection */
  51. /* global setanswer */
  52.  
  53. // #region 全局变量
  54.  
  55. /**
  56. * activeTooltips: 用于记录当前页面中活动的工具提示数量。这可以用于管理和控制页面上显示的提示。
  57. */
  58. let activeTooltips = 0;
  59.  
  60. /**
  61. * DEFAULT_TID_OPTIONS: 存储默认的板块列表。
  62. * 每个板块都有一个唯一的value和一个对应的label。
  63. * 这个常量可以被用于下拉列表、搜索过滤等。
  64. */
  65. const DEFAULT_TID_OPTIONS = [
  66. { value: 95, label: "综合区" },
  67. { value: 166, label: "AI区" },
  68. { value: 141, label: "原创区" },
  69. { value: 142, label: "转帖区" },
  70. { value: 96, label: "投诉区" },
  71. { value: 97, label: "出售区" },
  72. { value: 143, label: "悬赏区" },
  73. { value: 2, label: "国产原创" },
  74. { value: 36, label: "亚洲无码" },
  75. { value: 37, label: "亚洲有码" },
  76. { value: 103, label: "中文字幕" },
  77. { value: 107, label: "三级写真" },
  78. { value: 160, label: "VR视频区" },
  79. { value: 104, label: "素人有码" },
  80. { value: 38, label: "欧美无码" },
  81. { value: 151, label: "4K原版" },
  82. { value: 152, label: "韩国主播" },
  83. { value: 39, label: "动漫原创" },
  84. { value: 154, label: "文学区原创人生" },
  85. { value: 135, label: "文学区乱伦人妻" },
  86. { value: 137, label: "文学区青春校园" },
  87. { value: 138, label: "文学区武侠玄幻" },
  88. { value: 136, label: "文学区激情都市" },
  89. { value: 139, label: "文学区TXT下载" },
  90. { value: 145, label: "原档自提字幕区" },
  91. { value: 146, label: "原档自译字幕区" },
  92. { value: 121, label: "原档字幕分享区" },
  93. { value: 159, label: "原档新作区" },
  94. { value: 41, label: "在线国产自拍" },
  95. { value: 109, label: "在线中文字幕" },
  96. { value: 42, label: "在线日韩无码" },
  97. { value: 43, label: "在线日韩有码" },
  98. { value: 44, label: "在线欧美风情" },
  99. { value: 45, label: "在线卡通动漫" },
  100. { value: 46, label: "在线剧情三级" },
  101. { value: 155, label: "图区原创自拍" },
  102. { value: 125, label: "图区转帖自拍" },
  103. { value: 50, label: "图区华人街拍" },
  104. { value: 48, label: "图区亚洲性爱" },
  105. { value: 49, label: "图区欧美性爱" },
  106. { value: 117, label: "图区卡通动漫" },
  107. { value: 165, label: "图区套图下载" },
  108. ];
  109.  
  110. /**
  111. * baseURL: 获取当前页面的主机URL,用于构建其他URL。
  112. */
  113. const baseURL = `https://${window.location.host}`;
  114.  
  115. // #endregion
  116.  
  117. // #region 获取用户设置
  118.  
  119. /**
  120. * 获取用户设置。
  121. * 从用户脚本的存储中检索各种设置,并为每个设置返回其值或默认值。
  122. * 这些设置可以用于改变脚本的行为、外观和功能。
  123. *
  124. * @returns {Object} 返回一个对象,该对象包含了所有的用户设置。
  125. */
  126. function getSettings() {
  127. /**
  128. * 从脚本存储中获取JSON值。
  129. * 如果检索到的值不是有效的JSON,则返回默认值。
  130. *
  131. * @param {string} key - 存储的键名。
  132. * @param {string} defaultValue - 如果无法检索到或解析值,则返回的默认JSON值。
  133. * @returns {any} 返回解析的JSON值或默认值。
  134. */
  135. const getJSONValue = (key, defaultValue) => {
  136. const value = GM_getValue(key, defaultValue);
  137. try {
  138. return JSON.parse(value);
  139. } catch {
  140. return JSON.parse(defaultValue);
  141. }
  142. };
  143.  
  144. return {
  145. logoText: GM_getValue("logoText", "保国爱你"), // 评分文字和特效文字
  146. tipsText: GM_getValue("tipsText", "马保国友情提示"), // 评分文字和特效文字
  147. imageSize: GM_getValue("imageSize", "50px"), // 图片的大小
  148. imageUrl: GM_getValue(
  149. "imageUrl",
  150. "/uc_server/data/avatar/000/46/26/94_avatar_big.jpg"
  151. ), // 图片的URL
  152. blockMedals: GM_getValue("blockMedals", 0), // 是否阻止显示勋章
  153. resizeMedals: GM_getValue("resizeMedals", 0), // 是否调整勋章的大小
  154. replaceMedals: GM_getValue("replaceMedals", 0), // 是否替换勋章
  155. excludeGroup: getJSONValue("excludeGroup", "[]"), // 要排除的组
  156. TIDGroup: getJSONValue("TIDGroup", "[]"), // TID分组
  157. displayBlockedTips: GM_getValue("displayBlockedTips", true), // 是否显示消息
  158. autoPagination: GM_getValue("autoPagination", true), // 是否开启自动分页
  159. showImageButton: GM_getValue("showImageButton", "hide"), // 是否显示图片按钮
  160. lastCheckedUpdate: GM_getValue("lastCheckedUpdate", 0), // 最后一次检查更新的时间
  161. enableTitleStyle: GM_getValue("enableTitleStyle", true), // 是否启用标题样式
  162. titleStyleSize: GM_getValue("titleStyleSize", 20), // 标题字体大小
  163. titleStyleWeight: GM_getValue("titleStyleWeight", 700), // 标题字体粗细
  164.  
  165. excludeOptions: GM_getValue("excludeOptions", [
  166. "度盘",
  167. "夸克",
  168. "内容隐藏",
  169. "搬运",
  170. "SHA1",
  171. ]), // 要排除的选项
  172. excludePostOptions: GM_getValue("excludePostOptions", ["度盘", "夸克"]), // 要排除的选项
  173. blockedUsers: GM_getValue("blockedUsers", [
  174. "老灯法师",
  175. "树根520",
  176. "豪大大鸡排",
  177. "林哲",
  178. "aa142150",
  179. "如果有重来",
  180. "Lcc123456cc",
  181. ]), // 被屏蔽的用户
  182. orderFids: getJSONValue("orderFids", "[]"), // FID的顺序
  183. showAvatar: GM_getValue("showAvatar", true), // 是否显示用户头像
  184. maxGradeThread: GM_getValue("maxGradeThread", 10),
  185. defaultSwipeToSearch: GM_getValue("defaultSwipeToSearch", true), // 是否开启划词搜索
  186. displayThreadImages: GM_getValue("displayThreadImages", false),
  187. displayThreadBuyInfo: GM_getValue("displayThreadBuyInfo", true), ///帖子是否显示购买次数
  188. isShowWatermarkMessage: GM_getValue("isShowWatermarkMessage", true),
  189. showDown: GM_getValue("showDown", true), // 是否显示下载附件
  190. showCopyCode: GM_getValue("showCopyCode", true), // 是否显示复制代码
  191. showFastPost: GM_getValue("showFastPost", true), // 是否显示快速发帖
  192. showFastReply: GM_getValue("showFastReply", true), // 是否显示快速回复
  193. showQuickGrade: GM_getValue("showQuickGrade", true), // 是否显示快速评分
  194. showQuickStar: GM_getValue("showQuickStar", true), // 是否显示快速收藏
  195. showClickDouble: GM_getValue("showClickDouble", true), // 是否显示一键二连
  196. showViewRatings: GM_getValue("showViewRatings", true), // 是否显示查看评分
  197. showPayLog: GM_getValue("showPayLog", true), // 是否显示购买记录
  198. showFastCopy: GM_getValue("showFastCopy", true), // 是否显示复制帖子
  199. blockingResolved: GM_getValue("blockingResolved", true), // 是否显示屏蔽解决
  200. isOnlyShowMoney: GM_getValue("isOnlyShowMoney", false), // 是否只显示现金帖
  201. blockingIndex: GM_getValue("blockingIndex", false), // 是否屏蔽首页热门
  202. qiandaoTip: GM_getValue("qiandaoTip", true), // 是否显示签到提示
  203. menuButtonIsVisible: GM_getValue("menuButtonIsVisible", true), // 是否显示按钮容器
  204. };
  205. }
  206.  
  207. // #endregion
  208.  
  209. // #region 样式
  210.  
  211. /**
  212. * 添加自定义样式到页面中。
  213. * 此函数会创建一个<style>元素,并定义了一些自定义的CSS样式,然后将其添加到文档的头部。
  214. */
  215.  
  216. function addStyles() {
  217. // 创建一个新的<style>元素
  218. const style = document.createElement("style");
  219.  
  220. // 定义我们需要的自定义样式
  221. style.innerHTML = `
  222.  
  223. /* --- 通用自定义按钮的样式 --- */
  224. .bgsh-customBtn, .bgsh-searchBtn, .bgsh-quickTopicadminToPostBtn, .bgsh-quickReplyToPostBtn,.bgsh-QuickMiscReportBtn,.bgsh-quickReportadToPostBtn,.bgsh-quickGradeToPostBtn ,.bgsh-openAllUrlBtn,.bgsh-fastPMButtonBtn,.bgsh-quickReplyEditToPostBtn,.bgsh-setAnswerToPostBtn {
  225. padding: 8px 15px;
  226.  
  227. margin-bottom: 8px;
  228. margin-right: 8px;
  229. width: 100%;
  230. border: none;
  231. outline: none;
  232. white-space: pre-line; /* 保留换行符,但仍然合并连续的空白 */
  233. border-radius: 8px;
  234. font-size: 13px;
  235. font-weight: 500;
  236. color: #ffffff;
  237. cursor: pointer;
  238. box-shadow: -5px -5px 8px #F6CEEC, 5px 5px 8px #BC78EC;
  239. transition: 0.8s;
  240. }
  241.  
  242. /* quickTopicadminToPostBtn按钮的设置 */
  243. .bgsh-quickTopicadminToPostBtn ,.bgsh-quickReplyToPostBtn,.bgsh-quickReplyEditToPostBtn,.bgsh-setAnswerToPostBtn{
  244. width: auto;
  245. float: right;
  246. box-shadow: -5px -5px 8px #F6CEEC, 5px 5px 8px #C346C2;
  247. }
  248.  
  249. /* quickGradeToPostBtn按钮的设置 */
  250. .bgsh-quickGradeToPostBtn,.bgsh-QuickMiscReportBtn,.bgsh-quickReportadToPostBtn {
  251. width: auto;
  252. float: left;
  253. box-shadow: -5px -5px 8px #F6CEEC, 5px 5px 8px #EA5455;
  254.  
  255. }
  256. /* quickGradeToPostBtn按钮的设置 */
  257. .bgsh-fastPMButtonBtn {
  258. width: auto;
  259. float: left;
  260. box-shadow: -5px -5px 8px #F6CEEC, 5px 5px 8px #EA5455;
  261.  
  262. }
  263. /* openAllUrlBtn按钮的设置 */
  264. .bgsh-openAllUrlBtn {
  265. width: 100px;
  266. font-size: 16px;
  267. padding: 0;
  268. box-shadow: 0 0px 0px #ccc;
  269. }
  270.  
  271. /* 按钮的最大宽度设置 */
  272. .bgsh-searchBtn {
  273. max-width: 400px;
  274. background-color: #0D25B9;
  275. }
  276.  
  277. /* 按钮的悬停效果 */
  278. .bgsh-customBtn:hover {
  279. transform: scale(1.05);
  280. background-color: #ABDCFF;
  281. box-shadow: inset 5px 5px 10px #7367F0, inset -5px -5px 10px #CE9FFC;
  282. }
  283.  
  284. /* 按钮的悬停效果 */
  285. .bgsh-searchBtn:hover {
  286. transform: scale(1.05);
  287. background-color: #5961F9;
  288. box-shadow: inset 5px 5px 10px #7367F0, inset -5px -5px 10px #CE9FFC;
  289. }
  290.  
  291. /* 按钮的悬停效果 */
  292. .bgsh-quickTopicadminToPostBtn:hover ,.bgsh-quickReplyToPostBtn:hover ,.bgsh-QuickMiscReportBtn:hover,.bgsh-quickReportadToPostBtn:hover,.bgsh-fastPMButtonBtn:hover,.bgsh-quickReplyEditToPostBtn:hover,.bgsh-setAnswerToPostBtn:hover{
  293. transform: scale(1.05);
  294. background-color: #32CCBC;
  295. box-shadow: inset 5px 5px 10px #1D6FA3, inset -5px -5px 10px #65FDF0;
  296. }
  297.  
  298. /* 按钮的悬停效果 */
  299. .bgsh-quickGradeToPostBtn:hover {
  300. transform: scale(1.05);
  301. background-color: #FDD819;
  302. box-shadow: inset 5px 5px 10px #E96D71, inset -5px -5px 10px #FAD7A1;
  303. }
  304.  
  305. /* --- 自定义的搜索框样式 --- */
  306. .advanced-search {
  307. position: fixed;
  308. right: calc(150px + 1vh);
  309. top: 100px;
  310. z-index: 1000;
  311. background: #fff;
  312. border: 1px solid #ddd;
  313. padding: 10px;
  314. display: grid; /* 使用网格布局 */
  315. grid-template-columns: auto auto; /* 两列的宽度根据内容自适应 */
  316. column-gap: 20px; /* 列之间的间隙 */
  317. }
  318.  
  319. /* 添加间距 */
  320. .advanced-search .bgsh-forget {
  321. max-height: 580px; /* 设置最大高度限制 */
  322. overflow: visible; /* 确保超出部分内容可见 */
  323. display: flex;
  324. flex-wrap: wrap;
  325. flex-direction: column;
  326.  
  327. }
  328.  
  329. /* --- 复选框样式 --- */
  330. .bgsh-forget .bgsh-checkbox-label {
  331. display: block;
  332. position: relative;
  333. cursor: pointer;
  334. font-size: 22px;
  335. line-height: 22px;
  336. margin-right: 10px;
  337. }
  338. .bgsh-label-text {
  339. display: inline-block;
  340. font-weight: 500;
  341. left: 12%;
  342. font-size: 13px;
  343. }
  344. .bgsh-forget .bgsh-checkbox-label input {
  345. opacity: 0;
  346. cursor: pointer;
  347. }
  348.  
  349. /* 复选框的自定义样式 */
  350. .bgsh-checkbox-label .bgsh-checkbox-custom {
  351. position: absolute;
  352. top: 0;
  353. left: 0;
  354. height: 20px;
  355. width: 20px;
  356. background-color: #ecf0f3;
  357. border-radius: 5px;
  358. border: none;
  359. box-shadow: inset 3px 3px 3px #cbced1, inset -3px -3px 3px #fff;
  360. }
  361.  
  362. /* 复选框选中状态样式 */
  363. .bgsh-checkbox-label input:checked ~ .bgsh-checkbox-custom {
  364. box-shadow: -4px -4px 4px #feffff, 4px 4px 4px #161b1d2f;
  365. }
  366.  
  367. /* 复选框标志样式 */
  368. .bgsh-checkbox-label .bgsh-checkbox-custom::after {
  369. position: absolute;
  370. content: "";
  371. left: 10px;
  372. top: 10px;
  373. height: 0;
  374. width: 0;
  375. border-radius: 5px;
  376. border: solid #635f5f;
  377. border-width: 0 3px 3px 0;
  378. transform: rotate(0deg) scale(0);
  379. opacity: 1;
  380. transition: all 0.3s ease-out;
  381. }
  382.  
  383. /* 复选框选中状态下的标志样式 */
  384. .bgsh-checkbox-label input:checked ~ .bgsh-checkbox-custom::after {
  385. transform: rotate(45deg) scale(1);
  386. left: 7px;
  387. top: 3px;
  388. width: 4px;
  389. height: 8px;
  390. }
  391.  
  392. /* 自定义复选框的indeterminate标志样式 */
  393. .bgsh-checkbox-label .bgsh-checkbox-custom::before {
  394. position: absolute;
  395. content: "";
  396. left: 5px;
  397. top: 9px;
  398. width: 10px;
  399. height: 2px;
  400. background-color: #635f5f;
  401. opacity: 0;
  402. transition: opacity 0.3s ease-out;
  403. }
  404.  
  405. /* 当复选框处于indeterminate状态时的样式 */
  406. .bgsh-checkbox-label input:indeterminate ~ .bgsh-checkbox-custom::before {
  407. opacity: 1;
  408. }
  409.  
  410. .bgsh-dateInput {
  411. border: 1px solid #d4d4d4; /* 边框 */
  412. border-radius: 5px; /* 圆角 */
  413. background-color: #fff; /* 背景颜色 */
  414. transition: border 0.3s; /* 过渡效果 */
  415. margin: 0 5px; /* 左右边距 */
  416. width: 150px; /* 设定宽度 */
  417. }
  418.  
  419. /* 聚焦时的样式 */
  420. .bgsh-dateInput:focus {
  421. border-color: #007BFF; /* 聚焦时的边框颜色 */
  422. outline: none; /* 去除默认的轮廓 */
  423. box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); /* 聚焦时的阴影效果 */
  424. }
  425.  
  426. /* 鼠标悬浮时的样式 */
  427. .bgsh-dateInput:hover {
  428. border-color: #b3b3b3; /* 鼠标悬浮时的边框颜色 */
  429. }
  430.  
  431. .bgsh-watermark-wrapper {
  432. position: fixed;
  433. top: 0;
  434. left: 0;
  435. width: 100%;
  436. height: 100%;
  437. pointer-events: none; /* 确保水印不会阻止按钮点击等交互 */
  438. }
  439.  
  440. .bgsh-watermark-text {
  441. position: absolute;
  442. text-align: center;
  443. font-size: 30px;
  444. color: red;
  445. font-weight: bold;
  446. overflow: hidden;
  447. box-sizing: border-box;
  448. display: flex;
  449. align-items: center;
  450. justify-content: center;
  451. flex-direction: row; /* 改为行方向 */
  452. }
  453.  
  454. .bgsh-watermark-text .icon {
  455. width: 30px;
  456. height: 30px;
  457. fill: red;
  458. margin: 0 5px; /* 修改图标的间距 */
  459. }
  460.  
  461.  
  462. `;
  463.  
  464. // 将<style>元素添加到文档的头部
  465. document.head.appendChild(style);
  466. }
  467.  
  468. // #endregion
  469.  
  470. // #region 消息提示
  471.  
  472. /**
  473. * 在页面中显示一个淡出的提示消息。
  474. * 使用该函数可以在页面中临时显示一个提示消息,该消息在一段时间后会自动淡出并消失。
  475. *
  476. * @param {string} message - 需要显示的提示消息内容。
  477. */
  478. function showTooltip(message) {
  479. const tooltip = document.createElement("span");
  480.  
  481. // 设定提示消息的初始样式
  482. const tooltipStyles = {
  483. position: "fixed",
  484. top: `calc(33.33% + ${activeTooltips * 80}px)`,
  485. left: "50%",
  486. transform: "translate(-50%, -50%)",
  487. backgroundColor: "#333",
  488. color: "#fff",
  489. padding: "20px 40px",
  490. borderRadius: "10px",
  491. zIndex: "1000",
  492. transition: "opacity 0.5s",
  493. fontSize: "24px",
  494. opacity: "1", // 默认透明度为1
  495. };
  496. var settings = getSettings();
  497. Object.assign(tooltip.style, tooltipStyles); // 使用Object.assign将样式批量应用到元素上
  498. tooltip.innerText = `${settings.tipsText}:` + message;
  499. document.body.appendChild(tooltip);
  500.  
  501. activeTooltips++;
  502.  
  503. // 淡出效果函数
  504. const fadeOut = (element, duration = 500) => {
  505. let opacity = 1;
  506. const timer = setInterval(function () {
  507. opacity -= 50 / duration;
  508. if (opacity <= 0) {
  509. clearInterval(timer);
  510. element.style.display = "none"; // or "hidden", depending on the desired final state
  511. } else {
  512. element.style.opacity = opacity;
  513. }
  514. }, 50);
  515. };
  516.  
  517. setTimeout(() => {
  518. fadeOut(tooltip);
  519. setTimeout(() => {
  520. document.body.removeChild(tooltip);
  521. activeTooltips--;
  522. }, 500);
  523. }, 2000);
  524. }
  525. // #endregion
  526.  
  527. // #region Tampermonkey 菜单命令注册
  528. /**
  529. * 注册一个命令到Tampermonkey的上下文菜单,允许用户访问“保国逛色花”的设置界面。
  530. */
  531. GM_registerMenuCommand("保国逛色花设置", () => {
  532. createSettingsUI(getSettings());
  533. });
  534. // #endregion
  535.  
  536. // #region 设置界面HTML构造
  537.  
  538. /**
  539. * 生成“保国逛色花”设置界面的HTML内容
  540. * @param {Object} settings - 当前的设置数据
  541. * @returns {string} - 设置界面的HTML字符串
  542. */
  543. function generateSettingsHTML(settings) {
  544. return `
  545. <div class='bgsh-setting-box'>
  546. <div class='bgsh-setting-box-container '>
  547. <div class="bgsh-setting-first">
  548.  
  549. <label for="tipsText">提示文字</label>
  550. <input type="text" id="tipsTextInput" value="${
  551. settings.tipsText
  552. }">
  553. <br>
  554. <label for="logoText">评分/特效文字</label>
  555. <input type="text" id="logoTextInput" value="${
  556. settings.logoText
  557. }">
  558. <br>
  559. <label for="imageSize">勋章尺寸:</label>
  560. <input type="text" id="imageSizeInput" value="${
  561. settings.imageSize
  562. }">
  563. <br>
  564. <label for="imageUrl">替换勋章图片链接:</label>
  565. <input type="text" id="imageUrlInput" value="${
  566. settings.imageUrl
  567. }">
  568. <br>
  569. <label for="maxGradeThread">主贴评分最大值:</label>
  570. <input type="number" id="maxGradeThread" value="${
  571. settings.maxGradeThread
  572. }">
  573. <br>
  574. <!--勋章隐藏设置-->
  575. <fieldset>
  576. <label>隐藏勋章</label>
  577. <br>
  578. <label>
  579. <input type="radio" name="blockMedals" value="0" ${
  580. settings.blockMedals === 0 ? "checked" : ""
  581. }>
  582. 不隐藏
  583. </label>
  584. <label>
  585. <input type="radio" name="blockMedals" value="1" ${
  586. settings.blockMedals === 1 ? "checked" : ""
  587. }>
  588. 隐藏所有
  589. </label>
  590. <label>
  591. <input type="radio" name="blockMedals" value="2" ${
  592. settings.blockMedals === 2 ? "checked" : ""
  593. }>
  594. 隐藏女优勋章
  595. </label>
  596. </fieldset>
  597. <!--勋章尺寸修改设置-->
  598. <fieldset>
  599. <label>修改勋章尺寸</label>
  600. <br>
  601. <label>
  602. <input type="radio" name="resizeMedals" value="0" ${
  603. settings.resizeMedals === 0 ? "checked" : ""
  604. }>
  605. 不修改
  606. </label>
  607. <label>
  608. <input type="radio" name="resizeMedals" value="1" ${
  609. settings.resizeMedals === 1 ? "checked" : ""
  610. }>
  611. 修改所有
  612. </label>
  613. <label>
  614. <input type="radio" name="resizeMedals" value="2" ${
  615. settings.resizeMedals === 2 ? "checked" : ""
  616. }>
  617. 修改女优勋章
  618. </label>
  619. </fieldset>
  620. <!--勋章替换设置-->
  621. <fieldset>
  622. <label>替换勋章</label>
  623. <br>
  624. <label>
  625. <input type="radio" name="replaceMedals" value="0" ${
  626. settings.replaceMedals === 0 ? "checked" : ""
  627. }>
  628. 不替换
  629. </label>
  630. <label>
  631. <input type="radio" name="replaceMedals" value="1" ${
  632. settings.replaceMedals === 1 ? "checked" : ""
  633. }>
  634. 替换所有
  635. </label>
  636. <label>
  637. <input type="radio" name="replaceMedals" value="2" ${
  638. settings.replaceMedals === 2 ? "checked" : ""
  639. }>
  640. 替换女优勋章
  641. </label>
  642. </fieldset>
  643. <label class='bgsh-setting-checkbox-label' for="displayBlockedTipsCheckbox">
  644. <input type='checkbox' id="displayBlockedTipsCheckbox" ${
  645. settings.displayBlockedTips ? "checked" : ""
  646. }>
  647. <span class='bgsh-setting-checkbox-custom'></span>
  648. <span>显示黑名单屏蔽提示(每行一个)</span>
  649. <br>
  650. <span>提示:含黑名单用户和黑名单关键字</span>
  651. <br>
  652. </label>
  653. <label class='bgsh-setting-checkbox-label' for="enableTitleStyleCheckbox">
  654. <input type='checkbox' id="enableTitleStyleCheckbox" ${
  655. settings.enableTitleStyle ? "checked" : ""
  656. }>
  657. <span class='bgsh-setting-checkbox-custom'></span>
  658. <span>启用帖子标题样式</span>
  659. </label>
  660. <br>
  661.  
  662. <label for="titleStyleSize">字体大小</label>
  663. <input type="text" id="titleStyleSizeInput" value="${
  664. settings.titleStyleSize
  665. }">
  666. <br>
  667.  
  668. <label for="titleStyleWeight">字体粗细</label>
  669. <input type="text" id="titleStyleWeightInput" value="${
  670. settings.titleStyleWeight
  671. }">
  672.  
  673.  
  674.  
  675. <br>
  676. <label class='bgsh-setting-checkbox-label' for="showAvatarCheckbox">
  677. <input type='checkbox' id="showAvatarCheckbox" ${
  678. settings.showAvatar ? "checked" : ""
  679. }>
  680. <span class='bgsh-setting-checkbox-custom'></span>
  681. <span>显示用户头像</span>
  682. </label>
  683. <br>
  684. <label class='bgsh-setting-checkbox-label' for="autoPaginationCheckbox">
  685. <input type='checkbox' id="autoPaginationCheckbox" ${
  686. settings.autoPagination ? "checked" : ""
  687. }>
  688. <span class='bgsh-setting-checkbox-custom'></span>
  689. <span>启用自动翻页</span>
  690. </label>
  691. <br>
  692. <label class='bgsh-setting-checkbox-label' for="defaultSwipeToSearchCheckbox">
  693. <input type='checkbox' id="defaultSwipeToSearchCheckbox" ${
  694. settings.defaultSwipeToSearch ? "checked" : ""
  695. }>
  696. <span class='bgsh-setting-checkbox-custom'></span>
  697. <span>启用划词搜索</span>
  698. </label>
  699. <br>
  700. <label class='bgsh-setting-checkbox-label' for="displayThreadImagesCheckbox" >
  701. <input type='checkbox' id="displayThreadImagesCheckbox" ${
  702. settings.displayThreadImages ? "checked" : ""
  703. }>
  704. <span class='bgsh-setting-checkbox-custom'></span>
  705. <span>启用图片预览</span>
  706. </label>
  707. <br>
  708. <label class='bgsh-setting-checkbox-label' for="displayThreadBuyInfoCheckbox" >
  709. <input type='checkbox' id="displayThreadBuyInfoCheckbox" ${
  710. settings.displayThreadBuyInfo ? "checked" : ""
  711. }>
  712. <span class='bgsh-setting-checkbox-custom'></span>
  713. <span>显示购买次数</span>
  714. </label>
  715. <br>
  716.  
  717.  
  718.  
  719. <label class='bgsh-setting-checkbox-label' for="isShowWatermarkMessageCheckbox">
  720. <input type='checkbox' id="isShowWatermarkMessageCheckbox" ${
  721. settings.isShowWatermarkMessage ? "checked" : ""
  722. }>
  723. <span class='bgsh-setting-checkbox-custom'></span>
  724. <span>启用点击特效</span>
  725. </label>
  726. <br>
  727. <label class='bgsh-setting-checkbox-label' for="showDownCheckbox">
  728. <input type='checkbox' id="showDownCheckbox" ${
  729. settings.showDown ? "checked" : ""
  730. }>
  731. <span class='bgsh-setting-checkbox-custom'></span>
  732. <span>启用下载附件</span>
  733. </label>
  734. <br>
  735. <label class='bgsh-setting-checkbox-label' for="showCopyCodeCheckbox">
  736. <input type='checkbox' id="showCopyCodeCheckbox" ${
  737. settings.showCopyCode ? "checked" : ""
  738. }>
  739. <span class='bgsh-setting-checkbox-custom'></span>
  740. <span>启用复制代码</span>
  741. </label>
  742. <br>
  743. <label class='bgsh-setting-checkbox-label' for="showFastPostCheckbox">
  744. <input type='checkbox' id="showFastPostCheckbox" ${
  745. settings.showFastPost ? "checked" : ""
  746. }>
  747. <span class='bgsh-setting-checkbox-custom'></span>
  748. <span>启用快速发帖</span>
  749. </label>
  750. <br>
  751. <label class='bgsh-setting-checkbox-label' for="showFastReplyCheckbox">
  752. <input type='checkbox' id="showFastReplyCheckbox" ${
  753. settings.showFastReply ? "checked" : ""
  754. }>
  755. <span class='bgsh-setting-checkbox-custom'></span>
  756. <span>启用快速回复</span>
  757. </label>
  758. <br>
  759. <label class='bgsh-setting-checkbox-label' for="showQuickGradeCheckbox">
  760. <input type='checkbox' id="showQuickGradeCheckbox" ${
  761. settings.showQuickGrade ? "checked" : ""
  762. }>
  763. <span class='bgsh-setting-checkbox-custom'></span>
  764. <span>启用快速评分</span>
  765. </label>
  766. <br>
  767. <label class='bgsh-setting-checkbox-label' for="showQuickStarCheckbox">
  768. <input type='checkbox' id="showQuickStarCheckbox" ${
  769. settings.showQuickStar ? "checked" : ""
  770. }>
  771. <span class='bgsh-setting-checkbox-custom'></span>
  772. <span>启用快速收藏</span>
  773. </label>
  774. <br>
  775. <label class='bgsh-setting-checkbox-label' for="showClickDoubleCheckbox">
  776. <input type='checkbox' id="showClickDoubleCheckbox" ${
  777. settings.showClickDouble ? "checked" : ""
  778. }>
  779. <span class='bgsh-setting-checkbox-custom'></span>
  780. <span>启用一键二连</span>
  781. </label>
  782. <br>
  783. <label class='bgsh-setting-checkbox-label' for="showViewRatingsCheckbox">
  784. <input type='checkbox' id="showViewRatingsCheckbox" ${
  785. settings.showViewRatings ? "checked" : ""
  786. }>
  787. <span class='bgsh-setting-checkbox-custom'></span>
  788. <span>启用查看评分</span>
  789. </label>
  790. <br>
  791. <label class='bgsh-setting-checkbox-label' for="showPayLogCheckbox">
  792. <input type='checkbox' id="showPayLogCheckbox" ${
  793. settings.showPayLog ? "checked" : ""
  794. }>
  795. <span class='bgsh-setting-checkbox-custom'></span>
  796. <span>启用购买记录</span>
  797. </label>
  798. <br>
  799. <label class='bgsh-setting-checkbox-label' for="showFastCopyCheckbox">
  800. <input type='checkbox' id="showFastCopyCheckbox" ${
  801. settings.showFastCopy ? "checked" : ""
  802. }>
  803. <span class='bgsh-setting-checkbox-custom'></span>
  804. <span>启用复制帖子</span>
  805. </label>
  806. <br>
  807. <label class='bgsh-setting-checkbox-label' for="blockingIndexCheckbox">
  808. <input type='checkbox' id="blockingIndexCheckbox" ${
  809. settings.blockingIndex ? "checked" : ""
  810. }>
  811. <span class='bgsh-setting-checkbox-custom'></span>
  812. <span>屏蔽首页热门</span>
  813. </label>
  814. <br>
  815. <label class='bgsh-setting-checkbox-label' for="qiandaoTipCheckbox">
  816. <input type='checkbox' id="qiandaoTipCheckbox" ${
  817. settings.qiandaoTip ? "checked" : ""
  818. }>
  819. <span class='bgsh-setting-checkbox-custom'></span>
  820. <span>签到提示</span>
  821. </label>
  822. <br>
  823.  
  824.  
  825. </div>
  826. <div class="bgsh-setting-second">
  827. <!--高级搜索排除关键字设置-->
  828. <label for="excludeOptionsTextarea">高级搜索排除关键字(每行一个):</label>
  829. <br>
  830. <textarea id="excludeOptionsTextarea">${settings.excludeOptions.join(
  831. "\n"
  832. )}</textarea>
  833. <br>
  834. <!--黑名单用户名设置-->
  835. <label for="blockedUsersList">黑名单屏蔽的用户名(每行一个):</label>
  836. <br>
  837. <textarea id="blockedUsersList">${settings.blockedUsers.join(
  838. "\n"
  839. )}</textarea>
  840. <br>
  841. <!--帖子列表页黑名单关键字设置-->
  842. <label for="excludePostOptionsTextarea">帖子列表页黑名单关键字(每行一个):</label>
  843. <br>
  844. <textarea id="excludePostOptionsTextarea">${settings.excludePostOptions.join(
  845. "\n"
  846. )}</textarea>
  847. <br>
  848.  
  849. </div>
  850. </div>
  851.  
  852. <!--保存和关闭按钮-->
  853. <div class="bgsh-setting-button">
  854. <button id="saveButton">保存</button>
  855. <button id="closeButton">关闭</button>
  856.  
  857. </div>
  858. </div>
  859.  
  860.  
  861.  
  862. `;
  863. }
  864.  
  865. // #endregion
  866.  
  867. // #region 设置界面生成与事件绑定
  868.  
  869. /**
  870. * 创建并显示设置界面
  871. * @param {Object} settings - 当前的设置数据
  872. */
  873. function createSettingsUI(settings) {
  874. // 若之前的设置界面存在,先进行移除
  875. const existingContainer = document.getElementById("settingsUIContainer");
  876. if (existingContainer) {
  877. existingContainer.remove();
  878. }
  879.  
  880. // 添加设置界面的样式
  881. generateSettingsStyles();
  882.  
  883. // 根据当前设置生成界面内容
  884. const containerHTML = generateSettingsHTML(settings);
  885.  
  886. // 创建界面容器,并添加到页面
  887. const container = document.createElement("div");
  888. container.id = "settingsUIContainer";
  889. container.innerHTML = containerHTML;
  890. document.body.appendChild(container);
  891.  
  892. // 为“保存”和“关闭”按钮绑定事件
  893. const saveButton = document.getElementById("saveButton");
  894. const closeButton = document.getElementById("closeButton");
  895.  
  896. // 保存按钮点击后,保存设置并隐藏界面
  897. saveButton.addEventListener("click", function () {
  898. saveSettings(settings);
  899. container.style.display = "none";
  900. });
  901.  
  902. // 关闭按钮点击后,直接隐藏界面
  903. closeButton.addEventListener(
  904. "click",
  905. () => (container.style.display = "none")
  906. );
  907. }
  908.  
  909. // #endregion
  910.  
  911. // #region 设置界面样式
  912.  
  913. /**
  914. * 生成并应用设置界面的样式
  915. */
  916. function generateSettingsStyles() {
  917. const style = `
  918. /* 通用样式,应用于所有元素 */
  919. #settingsUIContainer * {
  920. /* 设置默认字体 */
  921. box-sizing: border-box;
  922. /* 使用边框盒模型 */
  923. margin: 0px;
  924. /* 外边距设置为0 */
  925. padding: 0px;
  926. /* 内边距设置为0 */
  927. font-family: "Inter", Arial, Helvetica, sans-serif;
  928. }
  929.  
  930. #settingsUIContainer {
  931. position: fixed;
  932. top: 50%;
  933. left: 50%;
  934. transform: translate(-50%, -50%);
  935. width: 666px;
  936. z-index: 9999;
  937. }
  938.  
  939. /* 文本选择时的背景色 */
  940. #settingsUIContainer *::selection {
  941. background-color: #c7c9ca;
  942. /* 文本选择时的背景色 */
  943. }
  944.  
  945. /* 盒子 */
  946. #settingsUIContainer .bgsh-setting-box {
  947. margin: auto;
  948. /* 水平居中对齐 */
  949. box-sizing: border-box;
  950. padding: 20px 20px;
  951. /* 圆角 */
  952. background-color: #ecf0f3;
  953. box-shadow: -8px -8px 8px #feffff, 8px 8px 8px #161b1d2f;
  954. /* 阴影 */
  955. overflow-y: auto; /* 当内容超出容器高度时,自动添加垂直滚动条 */
  956. height: 92vh; /* 设置高度为视口的 92% */
  957. max-height: 888px; /* 设置最大高度*/
  958. display: flex; /* 设置为flex容器 */
  959. flex-direction: column; /* 子元素在垂直方向上排列 */
  960. }
  961.  
  962. /* 标签样式 */
  963. #settingsUIContainer label {
  964. font-size: 13px;
  965. font-weight: 500;
  966. color: #858686;
  967. /* 字体颜色 */
  968. }
  969.  
  970. /* 复选框标签样式 */
  971. #settingsUIContainer .bgsh-setting-checkbox-label {
  972. display: block;
  973. /* 块级元素 */
  974. position: relative;
  975. /* 相对定位 */
  976. cursor: pointer;
  977. /* 鼠标指针样式为手型 */
  978. font-size: 13px;
  979. /* 字体大小 */
  980. line-height: 22px;
  981. /* 行高 */
  982. }
  983.  
  984. /* 复选框标签中的文本样式 */
  985. #settingsUIContainer span {
  986. color: #8f8c8c;
  987. /* 字体颜色 */
  988. display: inline-block;
  989. /* 内联块级元素 */
  990. position: absolute;
  991. /* 绝对定位 */
  992. /* width: 100%; */
  993. /* 宽度100%(此行已注释掉) */
  994. font-weight: 500;
  995. /* 字体粗细 */
  996. left: 12%;
  997. /* 左边距设置为12% */
  998. font-size: 13px;
  999. /* 字体大小 */
  1000. }
  1001.  
  1002. /* 输入框样式 */
  1003. #settingsUIContainer input[type="text"],
  1004. #settingsUIContainer input[type="number"] {
  1005. width: 100%;
  1006. height: 35px;
  1007. padding-left: 20px;
  1008. border: none;
  1009. color: #858686;
  1010. /* 字体颜色 */
  1011. margin-top: 10px;
  1012. background-color: #ecf0f3;
  1013. outline: none;
  1014. border-radius: 5px;
  1015. /* 圆角 */
  1016. box-shadow: inset 5px 5px 5px #cbced1, inset -5px -5px 5px #ffffff;
  1017. /* 内阴影 */
  1018. }
  1019. #settingsUIContainer textarea {
  1020. width: 100%;
  1021. height: 150px;
  1022. padding-left: 20px;
  1023. padding-top: 10px;
  1024. border: none;
  1025. color: #858686;
  1026. /* 字体颜色 */
  1027. margin-top: 10px;
  1028. background-color: #ecf0f3;
  1029. outline: none;
  1030. border-radius: 5px;
  1031. /* 圆角 */
  1032. box-shadow: inset 5px 5px 5px #cbced1, inset -5px -5px 5px #ffffff;
  1033. /* 内阴影 */
  1034. }
  1035. /* 复选框输入框样式 */
  1036. #settingsUIContainer input[type="checkbox"] {
  1037. position: absolute;
  1038. /* 绝对定位 */
  1039. opacity: 0;
  1040. /* 不可见 */
  1041. cursor: pointer;
  1042. /* 鼠标指针样式为手型 */
  1043. }
  1044.  
  1045. /* 自定义复选框样式 */
  1046. #settingsUIContainer .bgsh-setting-checkbox-label .bgsh-setting-checkbox-custom {
  1047. position: absolute;
  1048. /* 绝对定位 */
  1049. top: 0;
  1050. /* 顶部位置为0 */
  1051. left: 0px;
  1052. /* 左边位置为0像素 */
  1053. height: 20px;
  1054. /* 高度为20像素 */
  1055. width: 20px;
  1056. /* 宽度为20像素 */
  1057. background-color: #ecf0f3;
  1058. /* 背景颜色 */
  1059. border-radius: 5px;
  1060. /* 圆角 */
  1061. border: none;
  1062. /* 无边框 */
  1063. box-shadow: inset 3px 3px 3px #cbced1, inset -3px -3px 3px #ffff;
  1064. /* 内阴影效果 */
  1065. }
  1066.  
  1067. /* 复选框选中状态样式 */
  1068. #settingsUIContainer .bgsh-setting-checkbox-label input:checked ~ .bgsh-setting-checkbox-custom {
  1069. background-color: #ecf0f3;
  1070. /* 背景颜色 */
  1071. border-radius: 5px;
  1072. /* 圆角 */
  1073. -webkit-transform: rotate(0deg) scale(1);
  1074. /* 旋转和缩放 */
  1075. -ms-transform: rotate(0deg) scale(1);
  1076. /* 旋转和缩放 */
  1077. transform: rotate(0deg) scale(1);
  1078. /* 旋转和缩放 */
  1079. opacity: 1;
  1080. /* 不透明 */
  1081. border: none;
  1082. /* 无边框 */
  1083. box-shadow: -4px -4px 4px #feffff, 4px 4px 4px #161b1d2f;
  1084. /* 阴影效果 */
  1085. }
  1086.  
  1087. /* 自定义复选框的标志样式 */
  1088. #settingsUIContainer .bgsh-setting-checkbox-label .bgsh-setting-checkbox-custom::after {
  1089. position: absolute;
  1090. /* 绝对定位 */
  1091. content: "";
  1092. /* 内容为空,用于伪元素 */
  1093. left: 10px;
  1094. /* 左侧位置为10像素 */
  1095. top: 10px;
  1096. /* 顶部位置为10像素 */
  1097. height: 0px;
  1098. /* 高度为0像素 */
  1099. width: 0px;
  1100. /* 宽度为0像素 */
  1101. border-radius: 5px;
  1102. /* 圆角 */
  1103. border: solid #635f5f;
  1104. /* 边框样式和颜色 */
  1105. border-width: 0 3px 3px 0;
  1106. /* 边框宽度设置 */
  1107. -webkit-transform: rotate(0deg) scale(0);
  1108. /* 旋转和缩放 */
  1109. -ms-transform: rotate(0deg) scale(0);
  1110. /* 旋转和缩放 */
  1111. transform: rotate(0deg) scale(0);
  1112. /* 旋转和缩放 */
  1113. opacity: 1;
  1114. /* 不透明 */
  1115. transition: all 0.3s ease-out;
  1116. /* 过渡效果设置 */
  1117. }
  1118.  
  1119. /* 复选框选中状态下的标志样式 */
  1120. #settingsUIContainer .bgsh-setting-checkbox-label input:checked ~ .bgsh-setting-checkbox-custom::after {
  1121. -webkit-transform: rotate(45deg) scale(1);
  1122. /* 旋转和缩放 */
  1123. -ms-transform: rotate(45deg) scale(1);
  1124. /* 旋转和缩放 */
  1125. transform: rotate(45deg) scale(1);
  1126. /* 旋转和缩放 */
  1127. opacity: 1;
  1128. /* 不透明 */
  1129. left: 7px;
  1130. /* 左侧位置为7像素 */
  1131. top: 3px;
  1132. /* 顶部位置为3像素 */
  1133. width: 4px;
  1134. /* 宽度为4像素 */
  1135. height: 8px;
  1136. /* 高度为8像素 */
  1137. border: solid #635f5f;
  1138. /* 边框样式和颜色 */
  1139. border-width: 0 2px 2px 0;
  1140. /* 边框宽度设置 */
  1141. background-color: transparent;
  1142. /* 背景颜色透明 */
  1143. border-radius: 0;
  1144. /* 圆角设置为0 */
  1145. }
  1146.  
  1147. /* 按钮样式 */
  1148. #settingsUIContainer button {
  1149. width: 50px;
  1150. /* 宽度 */
  1151. margin-top: 20px;
  1152. /* 顶部外边距设置为20像素 */
  1153. height: 38px;
  1154. /* 高度为38像素 */
  1155. border: none;
  1156. /* 无边框 */
  1157. outline: none;
  1158. /* 移除焦点边框 */
  1159. border-radius: 20px;
  1160. /* 圆角设置为20像素 */
  1161. background-color: #727171;
  1162. /* 背景颜色 */
  1163. font-size: 13px;
  1164. /* 字体大小 */
  1165. font-weight: 500;
  1166. /* 字体粗细 */
  1167. color: #ffffff;
  1168. /* 字体颜色 */
  1169. cursor: pointer;
  1170. /* 鼠标指针样式为手型 */
  1171. box-shadow: -5px -5px 8px #d8e2e6, 5px 5px 10px #2c313378;
  1172. /* 阴影效果 */
  1173. transition: 0.8s;
  1174. /* 过渡效果设置 */
  1175. }
  1176.  
  1177. /* 按钮悬停状态样式 */
  1178. #settingsUIContainer button:hover {
  1179. background-color: #535658;
  1180. /* 背景颜色 */
  1181. box-shadow: inset 5px 5px 10px #05050578, inset -5px -5px 10px #9e9c9c;
  1182. /* 内阴影效果 */
  1183. }
  1184.  
  1185. /* 隐藏 <fieldset> 的边框 */
  1186. #settingsUIContainer fieldset {
  1187. border: none;
  1188. /* 移除边框 */
  1189. }
  1190.  
  1191. /* 自定义单选框样式 */
  1192. #settingsUIContainer input[type="radio"] {
  1193. background-color: #ecf0f3;
  1194. /* 背景颜色 */
  1195. border-radius: 5px;
  1196. /* 圆角 */
  1197. border: none;
  1198. /* 无边框 */
  1199. box-shadow: inset 3px 3px 3px #cbced1, inset -3px -3px 3px #ffff;
  1200. /* 内阴影效果 */
  1201. }
  1202. .bgsh-setting-first,
  1203. .bgsh-setting-second {
  1204. width: 50%; /* 设定为50%宽度 */
  1205. }
  1206.  
  1207. /* 为了让 .bgsh-setting-first 和 .bgsh-setting-second 水平排列,我们需要一个外层的容器 */
  1208. .bgsh-setting-box-container {
  1209. display: flex; /* 设置为flex容器,使其子元素水平排列 */
  1210. gap: 20px; /* 设置子元素之间的间隔,你可以根据需要调整 */
  1211. }
  1212.  
  1213. .bgsh-setting-button {
  1214. width: 100%; /* 占据100%的宽度 */
  1215. text-align: center; /* 按钮居中显示 */
  1216. gap: 20px; /* 设置子元素之间的间隔,你可以根据需要调整 */
  1217.  
  1218. }
  1219.  
  1220. `;
  1221.  
  1222. const styleElement = document.createElement("style");
  1223. styleElement.innerHTML = style;
  1224. document.head.appendChild(styleElement);
  1225. }
  1226.  
  1227. // #endregion
  1228.  
  1229. // #region 剪贴板操作
  1230.  
  1231. /**
  1232. * 将指定文本复制到剪贴板。
  1233. * @param {string} text - 需要复制的文本。
  1234. * @param {function} onSuccess - 复制成功时的回调函数。
  1235. * @param {function} onError - 复制失败时的回调函数。
  1236. */
  1237. async function copyToClipboard(text, onSuccess, onError) {
  1238. try {
  1239. await navigator.clipboard.writeText(text);
  1240. if (onSuccess) {
  1241. onSuccess();
  1242. }
  1243. } catch (err) {
  1244. if (onError) {
  1245. onError(err);
  1246. }
  1247. console.error("无法将文本复制到剪贴板", err);
  1248. }
  1249. }
  1250.  
  1251. // #endregion
  1252.  
  1253. // #region URL处理
  1254.  
  1255. /**
  1256. * 从给定的URL中解析查询参数。
  1257. * @param {string} url - 需要解析的URL。
  1258. * @returns {object} 返回一个包含查询参数的对象。
  1259. */
  1260. function getQueryParams(url) {
  1261. const queryParams = {};
  1262.  
  1263. // 检查 URL 是否包含传统的查询字符串
  1264. if (url.includes("?")) {
  1265. // 处理标准查询字符串
  1266. const queryPattern = /[?&]([^=&]+)=([^&]*)/g;
  1267. let match;
  1268. while ((match = queryPattern.exec(url)) !== null) {
  1269. queryParams[match[1]] = decodeURIComponent(match[2]);
  1270. }
  1271. } else {
  1272. // 处理特殊的 URL 路径模式,如 forum-154-1.html
  1273. const pathPattern = /forum-(\d+)-(\d+)\.html$/;
  1274. const pathMatch = pathPattern.exec(url);
  1275. if (pathMatch && pathMatch.length === 3) {
  1276. // 假设第一个数字是 fid,第二个数字是 page
  1277. queryParams.fid = pathMatch[1];
  1278. queryParams.page = pathMatch[2];
  1279. }
  1280. }
  1281.  
  1282. return queryParams;
  1283. }
  1284.  
  1285. /**
  1286. * 从给定的URL中解析tid。
  1287. * @param {string} url - 需要解析的URL。
  1288. * @returns {object} 返回一个包含查询参数的对象。
  1289. */
  1290. function extractTid(url) {
  1291. let tid = null;
  1292.  
  1293. // 检查是否是类似 /thread-XXXX-1-1.html 的格式
  1294. const threadMatch = url.match(/thread-(\d+)-\d+-\d+\.html/);
  1295. if (threadMatch && threadMatch.length > 1) {
  1296. tid = threadMatch[1];
  1297. } else {
  1298. // 检查是否是类似 /forum.php?mod=viewthread&tid=XXXX&extra=... 的格式
  1299. const queryMatch = url.match(/tid=(\d+)/);
  1300. if (queryMatch && queryMatch.length > 1) {
  1301. tid = queryMatch[1];
  1302. }
  1303. }
  1304.  
  1305. return tid;
  1306. }
  1307.  
  1308. // #endregion
  1309.  
  1310. // #region DOM操作
  1311.  
  1312. /**
  1313. * 获取指定名称的单选按钮的选中值。
  1314. * @param {string} name - 单选按钮的名称。
  1315. * @returns {number|null} 返回选中单选按钮的值,如果没有选中,则返回null。
  1316. */
  1317. function getCheckedRadioValue(name) {
  1318. const radios = document.getElementsByName(name);
  1319. for (let i = 0; i < radios.length; i++) {
  1320. if (radios[i].checked) {
  1321. return parseInt(radios[i].value);
  1322. }
  1323. }
  1324. return null;
  1325. }
  1326.  
  1327. /**
  1328. * 解析给定内容为DOM。
  1329. *
  1330. * @param {string} content - 要解析的内容。
  1331. * @param {string} type - 解析内容的类型,默认为"text/html"。
  1332. * @returns {Document} - 返回解析后的文档。
  1333. */
  1334. function parseContent(content, type = "text/html") {
  1335. return new DOMParser().parseFromString(content, type);
  1336. }
  1337.  
  1338. /**
  1339. * 从给定的DOM文档中提取值。
  1340. *
  1341. * @param {Document} doc - 要从中提取值的DOM文档。
  1342. * @param {string} selector - 用于定位元素的CSS选择器。
  1343. * @param {string} attr - 要提取的属性,默认为"value"。
  1344. * @returns {string|null} - 返回提取的值或null。
  1345. */
  1346. function extractValueFromDOM(doc, selector, attr = "value") {
  1347. const elem = doc.querySelector(selector);
  1348. if (!elem) return null;
  1349. return elem.getAttribute(attr);
  1350. }
  1351.  
  1352. /**
  1353. * 显示随机分布的水印文本"保国爱你"在全屏上。
  1354. * 水印将在2秒后自动消失。
  1355. */
  1356. function showWatermarkMessage() {
  1357. var settings = getSettings();
  1358. if (!settings.isShowWatermarkMessage) return;
  1359. const watermarkWrapper = document.createElement("div");
  1360. watermarkWrapper.className = "bgsh-watermark-wrapper";
  1361.  
  1362. const positions = [];
  1363. const maxAttempts = 10; // 增加到20次尝试
  1364.  
  1365. for (let i = 0; i < 20; i++) {
  1366. const watermarkText = document.createElement("div");
  1367. watermarkText.className = "bgsh-watermark-text";
  1368.  
  1369. // 吻的SVG
  1370. const kissIcon = `
  1371. <svg class="icon" viewBox="0 0 1489 1024" xmlns="http://www.w3.org/2000/svg">
  1372. <path
  1373. d="M1445.997803 542.822364c-28.845516 31.637018-113.986313 125.61757-171.677346 201.918612-70.252789 93.050052-107.007559 171.677345-165.163841 215.41087A249.374138 249.374138 0 0 1 935.153019 1023.891131a303.343168 303.343168 0 0 1-160.976589-46.525025 139.575077 139.575077 0 0 0-46.525026-6.513504 121.430317 121.430317 0 0 0-46.525026 5.117753 298.690666 298.690666 0 0 1-160.511339 46.525026 253.096141 253.096141 0 0 1-174.003597-63.274035C291.246662 915.022571 254.491891 837.791028 186.100103 744.740976 126.54807 667.044183 40.942023 573.063631 12.096507 541.426614c-6.048253-6.513504-12.096507-7.909254-12.096507-13.027008s12.096507-13.027007 12.096507-13.027007a487.11702 487.11702 0 0 0 85.606047-6.513503c21.401512-6.513504 211.688868-133.992074 211.688868-133.992075l150.741083-119.104066a143.76233 143.76233 0 0 1 68.391788-15.818509c41.872523 0 200.522861 100.028806 200.522862 100.028806S887.697493 241.340197 930.500517 241.340197a147.949582 147.949582 0 0 1 68.857038 15.353259l149.810583 119.569316s189.822105 127.013321 211.688868 133.992074a482.464518 482.464518 0 0 0 85.140797 6.513504s12.561757 7.909254 12.561757 13.027007-6.048253 6.513504-12.561757 13.027007zM1483.217823 136.658889a110.264311 110.264311 0 0 1-9.305005 21.401512 121.895568 121.895568 0 0 1-11.166006 15.818509L1315.72773 326.015744l-147.484331-150.741084a100.494056 100.494056 0 0 1-12.561757-17.67951 96.772054 96.772054 0 0 1-8.839755-17.679509 157.254587 157.254587 0 0 1-6.048254-41.872524 93.050052 93.050052 0 0 1 100.959306-93.050051 110.264311 110.264311 0 0 1 73.044291 46.525026A110.264311 110.264311 0 0 1 1387.84152 0.340563 93.050052 93.050052 0 0 1 1488.800827 95.716866a154.928336 154.928336 0 0 1-5.583004 40.942023z"
  1374. fill="#FD140B" p-id="15006"></path>
  1375. <path
  1376. d="M729.047155 553.52312a739.28266 739.28266 0 0 0-87.001799 0 1777.255987 1777.255987 0 0 0-226.576875 58.621533c0 7.444004 13.492257 17.67951 113.055812 26.984515a1599.530388 1599.530388 0 0 0 200.522862 4.187252 1460.885811 1460.885811 0 0 0 201.453362-2.791501c99.563555-9.770255 113.521063-19.540511 113.521063-26.984515a1759.576477 1759.576477 0 0 0-227.042126-59.086783c-26.054014-2.791502-87.932299-0.930501-87.932299-0.930501z"
  1377. fill="#F2C330" p-id="15007"></path>
  1378. </svg>`;
  1379. watermarkText.innerHTML = `${kissIcon}${settings.logoText}${kissIcon}`;
  1380.  
  1381. let attempts = 0;
  1382. let overlap = false;
  1383.  
  1384. do {
  1385. overlap = false;
  1386.  
  1387. const x = Math.random() * window.innerWidth * 0.8;
  1388. const y = Math.random() * window.innerHeight * 0.8;
  1389.  
  1390. // 检查新位置是否与现有位置重叠
  1391. for (let pos of positions) {
  1392. const dx = x - pos.x;
  1393. const dy = y - pos.y;
  1394.  
  1395. const distance = Math.sqrt(dx * dx + dy * dy);
  1396. if (distance < 400) {
  1397. // 减少到100px
  1398. overlap = true;
  1399. break;
  1400. }
  1401. }
  1402.  
  1403. if (!overlap) {
  1404. watermarkText.style.left = `${x}px`;
  1405. watermarkText.style.top = `${y}px`;
  1406. positions.push({ x, y });
  1407. }
  1408.  
  1409. attempts++;
  1410. } while (overlap && attempts < maxAttempts);
  1411.  
  1412. if (attempts < maxAttempts) {
  1413. watermarkWrapper.appendChild(watermarkText);
  1414. }
  1415. }
  1416.  
  1417. document.body.appendChild(watermarkWrapper);
  1418. setTimeout(() => {
  1419. watermarkWrapper.remove();
  1420. }, 500);
  1421. }
  1422.  
  1423. // #endregion
  1424.  
  1425. // #region 用户信息获取
  1426.  
  1427. /**
  1428. * 从页面中获取当前登录用户的 userid。
  1429. * @returns {string|null} 返回用户ID,如果未找到则返回null。
  1430. */
  1431. function getUserId() {
  1432. const userLink = document.querySelector(".vwmy a");
  1433. if (userLink) {
  1434. const match = userLink.href.match(/uid=(\d+)/);
  1435. if (match) {
  1436. return match[1];
  1437. }
  1438. }
  1439. return null;
  1440. }
  1441.  
  1442. // #endregion
  1443.  
  1444. // #region 帖子信息获取
  1445.  
  1446. /**
  1447. * 从给定的元素中获取其父级table的帖子楼层Pid。
  1448. * @param {HTMLElement} element - 要查询的HTML元素。
  1449. * @returns {string|null} 返回楼层的Pid,如果未找到则返回null。
  1450. */
  1451. function getTableIdFromElement(element) {
  1452. if (element) {
  1453. let parentTable = element.closest("table");
  1454. if (parentTable && parentTable.id.startsWith("pid")) {
  1455. return parentTable.id.replace("pid", "");
  1456. }
  1457. }
  1458. return null;
  1459. }
  1460.  
  1461. // #endregion
  1462.  
  1463. // #region 会话验证
  1464.  
  1465. /**
  1466. * 从页面中获取formhash值。
  1467. * @returns {string|null} 返回formhash值,如果未找到则返回null。
  1468. */
  1469. function getFormHash() {
  1470. const element = document.querySelector('input[name="formhash"]');
  1471. if (element) {
  1472. return element.value;
  1473. } else {
  1474. return null;
  1475. }
  1476. }
  1477.  
  1478. // #endregion
  1479.  
  1480. // #region 帖子列表样式设置
  1481.  
  1482. /**
  1483. * 设置帖子标题的样式。
  1484. *
  1485. * 使用自定义字体、加粗和字体大小为标题增加高亮。
  1486. */
  1487. function stylePosts(settings) {
  1488. const style = document.createElement("style");
  1489. style.id = "customTitleStyle"; // 为样式元素添加ID,方便后续操作
  1490. style.textContent = `
  1491. .s.xst {
  1492. font-size: ${settings.titleStyleSize}px;
  1493. font-weight: ${settings.titleStyleWeight};
  1494. font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei New', 'STHeiti Light', sans-serif;
  1495. }
  1496. `;
  1497. document.head.appendChild(style);
  1498.  
  1499. // 获取页面上所有alt="heatlevel"的<img>元素
  1500. var images = document.querySelectorAll('img[alt="heatlevel"]');
  1501. images.forEach((image) => {
  1502. // 寻找同级的符合条件的<a>标签
  1503. var parent = image.parentNode;
  1504. var link = parent.querySelector("a.s.xst");
  1505. var uniqueId = "baoguoheatleveldisplay"; // 设置一个唯一的ID
  1506.  
  1507. if (link) {
  1508. // 在 link 的父元素中查找 id 为 "baoguobuyinfouniqueSpanId" 的元素
  1509. const existingSpan = link.parentNode.querySelector("#" + uniqueId);
  1510.  
  1511. // 如果不存在这样的 span 元素,则创建并插入一个新的
  1512. if (!existingSpan) {
  1513. var span = document.createElement("span");
  1514. span.textContent = ` [${image.getAttribute("title")}]`; // 使用图片的title属性值
  1515. // 设置样式
  1516. span.style.color = "red";
  1517. span.style.fontWeight = "bold";
  1518. span.style.fontSize = `${settings.titleStyleSize}px`;
  1519. span.id = uniqueId;
  1520.  
  1521. // 将<span>元素插入到<a>标签后面
  1522. link.parentNode.insertBefore(span, link.nextSibling);
  1523. }
  1524. }
  1525. });
  1526. }
  1527.  
  1528. /**
  1529. * 移除先前设置的帖子标题样式。
  1530. */
  1531. function undoStylePosts() {
  1532. const styleElement = document.getElementById("customTitleStyle");
  1533. if (styleElement) {
  1534. styleElement.remove();
  1535. }
  1536. }
  1537.  
  1538. // #endregion
  1539.  
  1540. // #region 页码操作
  1541.  
  1542. /**
  1543. * 从页面的一个位置复制页码到另一个位置。
  1544. */
  1545. function addPageNumbers() {
  1546. const sourceElement = document.querySelector(".pgs.cl.mbm");
  1547. const targetElement = document.querySelector(".slst.mtw");
  1548.  
  1549. if (!sourceElement) {
  1550. console.error("源元素(使用选择器 '.pgs.cl.mbm')未找到!");
  1551. return;
  1552. }
  1553.  
  1554. if (!targetElement) {
  1555. console.error("目标元素(使用选择器 '.slst.mtw')未找到!");
  1556. return;
  1557. }
  1558.  
  1559. const parentElement = targetElement.parentElement;
  1560.  
  1561. if (!parentElement) {
  1562. console.error("目标元素的父元素不可用!");
  1563. return;
  1564. }
  1565.  
  1566. const clonedElement = sourceElement.cloneNode(true);
  1567. parentElement.insertBefore(clonedElement, targetElement);
  1568. }
  1569.  
  1570. // #endregion
  1571.  
  1572. // #region UI组件创建
  1573.  
  1574. /**
  1575. * 创建一个汇率显示窗口。
  1576. */
  1577. function createFloatingWindow() {
  1578. if (document.getElementById("currencyConverter")) {
  1579. return;
  1580. }
  1581. const floatingDiv = document.createElement("div");
  1582. floatingDiv.style.position = "fixed";
  1583. floatingDiv.style.top = "50%";
  1584. floatingDiv.style.left = "50%";
  1585. floatingDiv.style.transform = "translate(-50%, -50%)";
  1586. floatingDiv.style.backgroundColor = "#f9f9f9";
  1587. floatingDiv.style.border = "1px solid #ddd";
  1588. floatingDiv.style.boxShadow = "0 4px 8px rgba(0,0,0,0.05)";
  1589. floatingDiv.style.padding = "20px";
  1590. floatingDiv.style.borderRadius = "8px";
  1591. floatingDiv.style.zIndex = "1000";
  1592. floatingDiv.setAttribute("id", "currencyConverter");
  1593. floatingDiv.setAttribute("draggable", "true");
  1594. floatingDiv.innerHTML = `<div style="font-family: Arial, sans-serif; color: #333; text-align: center; margin-bottom: 15px; font-size: 18px; font-weight: bold;">保国带你逛算汇率</div><div><label>金钱:</label><input type="number"id="moneyInput"value="280"style="margin-bottom: 10px; border: 1px solid #ccc; padding: 2px;"/><br/><label>人民币:</label><input type="number"id="rmbInput"value="100"style="margin-bottom: 10px; border: 1px solid #ccc; padding: 2px;"/><br/><button id="convertButton"style="margin-right: 5px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; padding: 5px 10px; cursor: pointer;">计算汇率</button><button id="closeButton"style="background-color: #f44336; color: white; border: none; border-radius: 4px; padding: 5px 10px; cursor: pointer;">关闭</button><div id="conversionResult"style="margin-top: 10px;"></div></div>`;
  1595. document.body.appendChild(floatingDiv);
  1596. enableDrag(floatingDiv);
  1597. document
  1598. .getElementById("convertButton")
  1599. .addEventListener("click", convertCurrency);
  1600. document.getElementById("closeButton").addEventListener("click", () => {
  1601. document.getElementById("currencyConverter").remove();
  1602. });
  1603. }
  1604.  
  1605. /**
  1606. * 启用拖动
  1607. * @param {string} elmnt - 组件。
  1608. */
  1609. function enableDrag(elmnt) {
  1610. var pos1 = 0,
  1611. pos2 = 0,
  1612. pos3 = 0,
  1613. pos4 = 0;
  1614. if (document.getElementById(elmnt.id + "header")) {
  1615. document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
  1616. } else {
  1617. elmnt.onmousedown = dragMouseDown;
  1618. }
  1619. function dragMouseDown(e) {
  1620. e = e || window.event;
  1621. if (e.target.tagName.toUpperCase() === "INPUT") {
  1622. return;
  1623. }
  1624. e.preventDefault();
  1625. pos3 = e.clientX;
  1626. pos4 = e.clientY;
  1627. document.onmouseup = closeDragElement;
  1628. document.onmousemove = elementDrag;
  1629. }
  1630. function elementDrag(e) {
  1631. e = e || window.event;
  1632. e.preventDefault();
  1633. pos1 = pos3 - e.clientX;
  1634. pos2 = pos4 - e.clientY;
  1635. pos3 = e.clientX;
  1636. pos4 = e.clientY;
  1637. elmnt.style.top = elmnt.offsetTop - pos2 + "px";
  1638. elmnt.style.left = elmnt.offsetLeft - pos1 + "px";
  1639. }
  1640. function closeDragElement() {
  1641. document.onmouseup = null;
  1642. document.onmousemove = null;
  1643. }
  1644. }
  1645.  
  1646. /**
  1647. * 计算汇率
  1648. */
  1649. function convertCurrency() {
  1650. const moneyInput = document.getElementById("moneyInput").value;
  1651. const rmbInput = document.getElementById("rmbInput").value;
  1652. if (!moneyInput || !rmbInput || moneyInput <= 0 || rmbInput <= 0) {
  1653. document.getElementById("conversionResult").innerHTML =
  1654. "请输入有效的金钱和人民币值";
  1655. return;
  1656. }
  1657.  
  1658. const baseRate = rmbInput / (moneyInput * 1.2);
  1659. const normalUserCost = ((200 * rmbInput) / (moneyInput * 1.2)).toFixed(4);
  1660. const eliteUserCost = ((180 * rmbInput) / (moneyInput * 1.2)).toFixed(4);
  1661. document.getElementById("conversionResult").innerHTML = `1金钱=${(
  1662. 1 * baseRate
  1663. ).toFixed(4)}元<br/>1元=${(1 / baseRate).toFixed(
  1664. 4
  1665. )}金钱<br/>普通用户兑换邀请码需要:${normalUserCost}元<br/>精英用户兑换邀请码需要:${eliteUserCost}元`;
  1666. }
  1667.  
  1668. /**
  1669. * 创建一个多选框组。
  1670. * @param {string} id - 组件的ID。
  1671. * @param {string} title - 多选框组的标题。
  1672. * @param {Array} options - 多选框选项数组,每个选项包含"value"和"label"属性。
  1673. * @returns {HTMLElement} 返回多选框组的HTML元素。
  1674. */
  1675. function createCheckboxGroup(id, title, options) {
  1676. const groupDiv = document.createElement("div");
  1677. groupDiv.className = "bgsh-forget";
  1678. groupDiv.id = id;
  1679.  
  1680. let innerHTML = `<strong>${title}</strong><br>`;
  1681.  
  1682. // 添加一个'全选'复选框
  1683. const selectAllId = `bgsh-${id}-select-all`;
  1684. innerHTML += `
  1685. <label class="bgsh-checkbox-label">
  1686. <input type="checkbox" id="${selectAllId}" class="select-all">
  1687. <span class="bgsh-checkbox-custom"></span>
  1688. <span class="bgsh-label-text">全选</span>
  1689. </label>
  1690. `;
  1691.  
  1692. options.forEach((option) => {
  1693. const checkboxId = `bgsh-${id}-${option.value}`;
  1694. innerHTML += `
  1695. <label class="bgsh-checkbox-label">
  1696. <input type="checkbox" id="${checkboxId}" value="${option.value}">
  1697. <span class="bgsh-checkbox-custom"></span>
  1698. <span class="bgsh-label-text">${option.label}</span>
  1699. </label>
  1700. `;
  1701. });
  1702.  
  1703. groupDiv.innerHTML = innerHTML;
  1704.  
  1705. // 添加事件监听
  1706. const selectAllCheckbox = groupDiv.querySelector(".select-all");
  1707. const otherCheckboxes = Array.from(
  1708. groupDiv.querySelectorAll('input[type="checkbox"]')
  1709. ).filter((cb) => cb !== selectAllCheckbox);
  1710.  
  1711. function checkIndeterminateStatus() {
  1712. const checkedCheckboxes = otherCheckboxes.filter(
  1713. (cb) => cb.checked
  1714. ).length;
  1715.  
  1716. selectAllCheckbox.checked = checkedCheckboxes === otherCheckboxes.length;
  1717. selectAllCheckbox.indeterminate =
  1718. checkedCheckboxes > 0 && checkedCheckboxes < otherCheckboxes.length;
  1719. }
  1720.  
  1721. // 初始化全选框状态
  1722. setTimeout(() => {
  1723. checkIndeterminateStatus();
  1724. }, 500);
  1725. // 为 '全选' 复选框添加事件监听器
  1726. selectAllCheckbox.addEventListener("change", () => {
  1727. otherCheckboxes.forEach((checkbox) => {
  1728. checkbox.checked = selectAllCheckbox.checked;
  1729. });
  1730.  
  1731. // 在全选/取消全选后更新状态
  1732. checkIndeterminateStatus();
  1733. });
  1734.  
  1735. // 为其他复选框添加事件监听器
  1736. otherCheckboxes.forEach((checkbox) => {
  1737. checkbox.addEventListener("change", checkIndeterminateStatus);
  1738. });
  1739.  
  1740. return groupDiv;
  1741. }
  1742.  
  1743. /**
  1744. * 创建一个按钮。
  1745. * @param {string} id - 按钮的ID。
  1746. * @param {string} text - 按钮上的文本。
  1747. * @param {function} clickFunction - 按钮点击时的回调函数。
  1748. * @returns {HTMLElement} 返回创建的按钮元素。
  1749. */
  1750. const createButton = (
  1751. id,
  1752. text,
  1753. clickFunction,
  1754. className = "bgsh-customBtn",
  1755. bgColor = "#0396FF"
  1756. ) => {
  1757. const button = document.createElement("button");
  1758. button.id = id;
  1759. button.innerText = text;
  1760. button.className = className;
  1761. button.style.backgroundColor = bgColor; // 设置背景颜色
  1762. button.addEventListener("click", clickFunction);
  1763. return button;
  1764. };
  1765.  
  1766. /**
  1767. * 创建一个固定位置的按钮容器。
  1768. * @returns {HTMLElement} 返回创建的按钮容器元素。
  1769. */
  1770. function createButtonContainer() {
  1771. const container = document.createElement("div");
  1772. Object.assign(container.style, {
  1773. display: "flex",
  1774. flexDirection: "column",
  1775. alignItems: "center",
  1776. position: "fixed",
  1777. top: "50%",
  1778. right: "1vh",
  1779. zIndex: "1000",
  1780. transform: "translateY(-50%)",
  1781. });
  1782.  
  1783. return container;
  1784. }
  1785.  
  1786. function createMenuButton(settings) {
  1787. const menuButton = document.createElement("button");
  1788. // 根据容器的可见性设置按钮的文本
  1789. menuButton.textContent = settings.menuButtonIsVisible ? "隐藏" : "显示";
  1790. // 根据容器的可见性设置按钮的背景色
  1791. const buttonColor = settings.menuButtonIsVisible ? "#4682B4" : "#FF6347";
  1792.  
  1793. Object.assign(menuButton.style, {
  1794. position: "fixed",
  1795. top: "calc(50% - 60px)", // 将按钮放在容器上方
  1796. right: "1vh",
  1797. zIndex: "1001", // 确保按钮在容器之上
  1798. cursor: "pointer",
  1799. fontSize: "15px",
  1800. padding: "15px 15px",
  1801. borderRadius: "50%", // 圆形按钮
  1802. backgroundColor: buttonColor, // 根据状态设置背景色
  1803. color: "white",
  1804. border: "none",
  1805. });
  1806.  
  1807. return menuButton;
  1808. }
  1809. function toggleContainer(menuButton, container) {
  1810. const settings = getSettings();
  1811. let isVisible = settings.menuButtonIsVisible; // 初始状态设置为可见
  1812. menuButton.addEventListener("click", () => {
  1813. if (isVisible) {
  1814. container.style.display = "none"; // 隐藏容器
  1815. menuButton.textContent = "显示"; // 菜单按钮图标
  1816. menuButton.style.backgroundColor = "#FF6347"; // 设置背景色为红色
  1817.  
  1818. isVisible = false;
  1819. } else {
  1820. container.style.display = "flex"; // 显示容器
  1821. menuButton.textContent = "隐藏"; // 菜单按钮图标
  1822. menuButton.style.backgroundColor = "#4682B4"; // 设置背景色为蓝色
  1823.  
  1824. isVisible = true;
  1825. }
  1826. // 更新和存储新的可见性状态
  1827. GM_setValue("menuButtonIsVisible", isVisible);
  1828. const newsettings = getSettings();
  1829. setMenuButtonPosition(menuButton, container, newsettings);
  1830. });
  1831. }
  1832.  
  1833. /**
  1834. * 创建一个日期选择框并返回
  1835. * @param {string} id - 输入元素的ID
  1836. * @param {string} defaultValue - 默认日期值
  1837. * @returns {HTMLElement} 日期选择框
  1838. */
  1839. function createDateInput(
  1840. id,
  1841. defaultValue = new Date().toISOString().split("T")[0],
  1842. className = "bgsh-dateInput"
  1843. ) {
  1844. const input = document.createElement("input");
  1845. input.type = "date";
  1846. input.id = id;
  1847. input.value = defaultValue;
  1848. input.className = className;
  1849.  
  1850. return input;
  1851. }
  1852. // #endregion
  1853.  
  1854. // #region 更新操作
  1855.  
  1856. /**
  1857. * 检查脚本是否有新版本可用。
  1858. * 从提供的URL中获取最新版本号,并与当前版本进行比较。
  1859. * 如果发现新版本,则显示更新对话框。
  1860. */
  1861. async function checkForUpdates() {
  1862. // 获取当前脚本版本
  1863. const currentVersion = GM.info.script.version;
  1864. const updateURL =
  1865. "https://sleazyfork.org/zh-CN/scripts/494839-保国逛色花/code";
  1866.  
  1867. try {
  1868. // 请求最新版本的脚本内容
  1869. let response = await fetch(updateURL);
  1870. let data = await response.text();
  1871.  
  1872. // 从脚本内容中匹配版本号
  1873. const matchVersion = data.match(/@version\s+([\d.]+)/);
  1874.  
  1875. // 如果匹配到新版本号且新版本号大于当前版本号,显示更新对话框
  1876. if (
  1877. matchVersion &&
  1878. matchVersion[1] &&
  1879. parseFloat(matchVersion[1]) > parseFloat(currentVersion)
  1880. ) {
  1881. showUpdateDialog();
  1882. }
  1883.  
  1884. // 记录最后一次检查更新的时间
  1885. GM_setValue("lastCheckedUpdate", Date.now());
  1886. } catch (error) {
  1887. console.error("检查更新时出错:", error);
  1888. }
  1889. }
  1890.  
  1891. /**
  1892. * 显示脚本新版本的更新对话框。
  1893. * 提供一个链接供用户点击以更新脚本。
  1894. */
  1895. function showUpdateDialog() {
  1896. // 更新对话框的HTML内容
  1897. const dialogHTML = `
  1898. <div style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); z-index: 9999; display: flex; justify-content: center; align-items: center;">
  1899. <div style="background: #fff; padding: 20px; border-radius: 5px;">
  1900. <p>有新版本的保国逛色花脚本可用!</p>
  1901. <a href="https://sleazyfork.org/zh-CN/scripts/494839-保国逛色花" target="_blank">点击这里更新</a>
  1902. <button style="margin-top: 10px;" onclick="this.closest('.updateDialog').remove();">关闭</button>
  1903. </div>
  1904. </div>`;
  1905.  
  1906. // 插入到页面中
  1907. const tempDiv = document.createElement("div");
  1908. tempDiv.className = "updateDialog";
  1909. tempDiv.innerHTML = dialogHTML;
  1910. document.body.appendChild(tempDiv);
  1911. }
  1912.  
  1913. // #endregion
  1914.  
  1915. // #region 用户签到功能
  1916.  
  1917. /**
  1918. * 为给定的用户执行签到操作。
  1919. *
  1920. * @param {string} userid 用户ID
  1921. * @returns {boolean} 签到成功返回 true,否则返回 false
  1922. */
  1923. async function sign(userid) {
  1924. const signURL = `${baseURL}/plugin.php?id=dd_sign&ac=sign&infloat=yes&handlekey=pc_click_ddsign&inajax=1&ajaxtarget=fwin_content_pc_click_ddsign`;
  1925. const params = await getSignParameters(signURL);
  1926.  
  1927. if (!params || !params.formhash || !params.signhash) {
  1928. console.error("Failed to retrieve sign parameters.");
  1929. return false;
  1930. }
  1931.  
  1932. const { formhash, signtoken, signhash } = params;
  1933. const secanswer = await getValidationResult();
  1934.  
  1935. let responseText = await postSignData({
  1936. baseURL,
  1937. formhash,
  1938. signtoken,
  1939. secanswer,
  1940. signhash,
  1941. });
  1942. return updateSignButton(responseText, userid);
  1943. }
  1944.  
  1945. /**
  1946. * 从指定的 URL 获取签到所需的参数。
  1947. *
  1948. * @param {string} url 目标URL
  1949. * @returns {Object|null} 包含签到参数的对象或null
  1950. */
  1951. async function getSignParameters(url) {
  1952. const { responseText, contentType } = await fetchWithContentType(url);
  1953. return handleResponseContent(responseText, contentType);
  1954. }
  1955.  
  1956. async function getValidationResult() {
  1957. const secqaaURL = `/misc.php?mod=secqaa&action=update&idhash=qSAxcb0`;
  1958. const { responseText, contentType } = await fetchWithContentType(secqaaURL);
  1959. return extractValidationText(responseText, contentType);
  1960. }
  1961.  
  1962. async function postSignData({
  1963. baseURL,
  1964. formhash,
  1965. signtoken,
  1966. secanswer,
  1967. signhash,
  1968. }) {
  1969. const postURL = `${baseURL}/plugin.php?id=dd_sign&ac=sign&signsubmit=yes&handlekey=pc_click_ddsign&signhash=${signhash}&inajax=1`;
  1970. const data = new URLSearchParams({
  1971. formhash,
  1972. signtoken,
  1973. secanswer,
  1974. secqaahash: "qSAxcb0",
  1975. });
  1976. const response = await fetch(postURL, {
  1977. method: "post",
  1978. headers: {
  1979. "Content-Type": "application/x-www-form-urlencoded",
  1980. },
  1981. body: data,
  1982. });
  1983. return response.text();
  1984. }
  1985.  
  1986. async function fetchWithContentType(url) {
  1987. const response = await fetch(url);
  1988. const contentType = response.headers.get("Content-Type");
  1989. const responseText = await response.text();
  1990. return { responseText, contentType };
  1991. }
  1992.  
  1993. function handleResponseContent(responseText, contentType) {
  1994. if (contentType.includes("text/xml")) {
  1995. return handleXMLContent(responseText);
  1996. } else if (contentType.includes("text/html")) {
  1997. return extractSignParametersFromHTML(responseText);
  1998. } else {
  1999. throw new Error("Unsupported content type");
  2000. }
  2001. }
  2002.  
  2003. /**
  2004. * 处理XML内容并提取所需的签到参数。
  2005. *
  2006. * @param {string} responseText - 从请求中返回的XML内容。
  2007. * @returns {object|null} - 返回提取的签到参数或null。
  2008. */
  2009. function handleXMLContent(responseText) {
  2010. const settings = getSettings();
  2011. let xml = parseContent(responseText, "text/xml");
  2012. let content = xml.getElementsByTagName("root")[0].textContent;
  2013. let doc = parseContent(content);
  2014. const alertErrorElement = doc.querySelector(".alert_error");
  2015. if (alertErrorElement) {
  2016. let scripts = alertErrorElement.querySelectorAll("script");
  2017. scripts.forEach((script) => {
  2018. script.remove();
  2019. });
  2020. if (settings.qiandaoTip) {
  2021. showTooltip(alertErrorElement.textContent.trim());
  2022. }
  2023. return;
  2024. } else {
  2025. return extractSignParametersFromHTML(content);
  2026. }
  2027. }
  2028.  
  2029. /**
  2030. * 从HTML内容中提取签到参数。
  2031. *
  2032. * @param {string} responseText - 从请求中返回的HTML内容。
  2033. * @returns {object} - 返回提取的签到参数。
  2034. */
  2035. function extractSignParametersFromHTML(responseText) {
  2036. const doc = parseContent(responseText);
  2037. const formhash = extractValueFromDOM(doc, 'input[name="formhash"]');
  2038. const signtoken = extractValueFromDOM(doc, 'input[name="signtoken"]');
  2039. const signhash = extractValueFromDOM(
  2040. doc,
  2041. 'form[name="login"]',
  2042. "id"
  2043. ).replace("signform_", "");
  2044. return { formhash, signtoken, signhash };
  2045. }
  2046.  
  2047. /**
  2048. * 从验证结果文本中提取计算表达式并计算结果。
  2049. *
  2050. * @param {string} resultText 验证结果文本
  2051. * @param {string} contentType 内容类型
  2052. * @returns {number} 计算的结果
  2053. */
  2054. function extractValidationText(resultText, contentType) {
  2055. const text = resultText
  2056. .replace("sectplcode[2] + '", "前")
  2057. .replace("' + sectplcode[3]", "后");
  2058. const matchedText = text.match(/前([\w\W]+)后/)[1];
  2059. return computeExpression(matchedText.replace("= ?", ""));
  2060. }
  2061.  
  2062. /**
  2063. * 计算给定的数学表达式。
  2064. *
  2065. * @param {string} expr 数学表达式
  2066. * @returns {number} 计算的结果
  2067. */
  2068. const computeExpression = (expr) => {
  2069. const [left, operator, right] = expr.split(/([+\-*/])/);
  2070. const a = parseFloat(left.trim());
  2071. const b = parseFloat(right.trim());
  2072. switch (operator) {
  2073. case "+":
  2074. return a + b;
  2075. case "-":
  2076. return a - b;
  2077. case "*":
  2078. return a * b;
  2079. case "/":
  2080. return a / b;
  2081. default:
  2082. throw new Error("Unsupported operator");
  2083. }
  2084. };
  2085.  
  2086. /**
  2087. * 根据签到响应内容更新签到按钮的状态,并设置最后签到日期。
  2088. *
  2089. * @param {string} responseText 签到响应内容
  2090. * @param {string} userid 用户ID
  2091. * @returns {boolean} 签到成功返回 true,否则返回 false
  2092. */
  2093. function updateSignButton(responseText, userid) {
  2094. const settings = getSettings();
  2095. const today = new Date().toLocaleDateString();
  2096. if (
  2097. responseText.includes("已经签到过") ||
  2098. responseText.includes("重复签到")
  2099. ) {
  2100. if (settings.qiandaoTip) {
  2101. showTooltip("已经签到过啦,请明天再来!");
  2102. }
  2103. GM_setValue(`lastSignDate_${userid}`, today);
  2104. return true;
  2105. } else if (responseText.includes("签到成功")) {
  2106. if (settings.qiandaoTip) {
  2107. showTooltip("签到成功,金钱+2,明天记得来哦。");
  2108. }
  2109. GM_setValue(`lastSignDate_${userid}`, today);
  2110. return true;
  2111. } else if (responseText.includes("请至少发表或回复一个帖子后再来签到")) {
  2112. if (settings.qiandaoTip) {
  2113. if (settings.qiandaoTip) {
  2114. showTooltip("请至少发表或回复一个帖子后再来签到!");
  2115. }
  2116. }
  2117. return false;
  2118. } else {
  2119. if (settings.qiandaoTip) {
  2120. showTooltip("抱歉,签到出现了未知错误!");
  2121. }
  2122. return false;
  2123. }
  2124. }
  2125.  
  2126. // #endregion
  2127.  
  2128. // #region 收藏帖子操作
  2129.  
  2130. /**
  2131. * 收藏当前查看的帖子。
  2132. * 通过构造特定URL实现收藏功能,同时给用户提供收藏成功或失败的提示。
  2133. * @async
  2134. * @function
  2135. */
  2136. async function star() {
  2137. showWatermarkMessage();
  2138. // 从当前页面URL中获取帖子的tid
  2139. const tid = extractTid(window.location.href);
  2140. // 获取formhash,用于验证请求
  2141. const formHash = document.querySelector('input[name="formhash"]').value;
  2142.  
  2143. // 构造收藏URL
  2144. const starUrl = `/home.php?mod=spacecp&ac=favorite&type=thread&id=${tid}&formhash=${formHash}&infloat=yes&handlekey=k_favorite&inajax=1&ajaxtarget=fwin_content_k_favorite`;
  2145.  
  2146. // 发送收藏请求
  2147. const text = await fetch(starUrl).then((r) => r.text());
  2148.  
  2149. // 根据响应内容提供相应的提示
  2150. if (text.includes("抱歉,您已收藏,请勿重复收藏")) {
  2151. return showTooltip("抱歉,您已收藏,请勿重复收藏");
  2152. }
  2153.  
  2154. if (text.includes("信息收藏成功")) {
  2155. return showTooltip("信息收藏成功");
  2156. }
  2157.  
  2158. // 如果既没有成功消息也没有重复收藏消息,视为出错并在控制台记录
  2159. showTooltip("信息收藏出现问题!!!");
  2160. console.error(text);
  2161. }
  2162.  
  2163. // #endregion
  2164.  
  2165. // #region 帖子评分
  2166.  
  2167. /**
  2168. * 获取指定帖子的评分信息。
  2169. * @param {number} pid - 帖子ID。
  2170. * @param {number} tid - 主题ID。
  2171. * @param {number} timestamp - 当前时间戳。
  2172. * @returns {Object} 评分信息。
  2173. * @async
  2174. */
  2175. async function getRateInfo(pid, tid, timestamp) {
  2176. const infoDefaults = {
  2177. state: false,
  2178. max: 0,
  2179. left: 0,
  2180. formHash: "",
  2181. referer: "",
  2182. handleKey: "",
  2183. error: "",
  2184. };
  2185.  
  2186. try {
  2187. // 构建评分信息请求的URL
  2188. const url = `/forum.php?mod=misc&action=rate&tid=${tid}&pid=${pid}&infloat=yes&handlekey=rate&t=${timestamp}&inajax=1&ajaxtarget=fwin_content_rate`;
  2189. const response = await fetch(url);
  2190. if (!response.ok) throw new Error("Failed to fetch rate info");
  2191.  
  2192. // 解析服务器返回的XML数据
  2193. const text = await response.text();
  2194. const xml = new DOMParser().parseFromString(text, "text/xml");
  2195. const htmlContent = xml.querySelector("root").textContent;
  2196. const doc = new DOMParser().parseFromString(htmlContent, "text/html");
  2197.  
  2198. // 检查是否存在错误
  2199. if (htmlContent.includes("alert_error")) {
  2200. const alertErrorElement = doc.querySelector(".alert_error");
  2201. const scriptElements = alertErrorElement.querySelectorAll("script");
  2202. scriptElements.forEach((script) => script.remove());
  2203.  
  2204. const errorMessage = alertErrorElement.textContent.trim();
  2205. return { ...infoDefaults, error: errorMessage };
  2206. }
  2207.  
  2208. // 提取评分信息
  2209. const maxElement = doc.querySelector("#scoreoption8 li");
  2210. if (!maxElement) {
  2211. return { ...infoDefaults, error: "评分不足啦!" };
  2212. }
  2213.  
  2214. const max = parseInt(maxElement.textContent.replace("+", ""), 10);
  2215. const left = parseInt(
  2216. doc.querySelector(".dt.mbm td:last-child").textContent,
  2217. 10
  2218. );
  2219. const formHash = doc.querySelector('input[name="formhash"]').value;
  2220. const referer = doc.querySelector('input[name="referer"]').value;
  2221. const handleKey = doc.querySelector('input[name="handlekey"]').value;
  2222.  
  2223. return {
  2224. state: true,
  2225. max: Math.min(max, left),
  2226. left,
  2227. formHash,
  2228. referer,
  2229. handleKey,
  2230. error: "",
  2231. };
  2232. } catch (error) {
  2233. showTooltip(error);
  2234. return infoDefaults;
  2235. }
  2236. }
  2237.  
  2238. /**
  2239. * 对指定的帖子进行评分。
  2240. * @param {number} pid - 帖子ID。
  2241. * @async
  2242. */
  2243. async function grade(pid) {
  2244. showWatermarkMessage();
  2245. const tid = extractTid(window.location.href);
  2246. const timestamp = new Date().getTime();
  2247. const rateInfo = await getRateInfo(pid, tid, timestamp);
  2248. if (!rateInfo.state) {
  2249. showTooltip(rateInfo.error);
  2250. return;
  2251. }
  2252. var settings = getSettings();
  2253. var maxGradeThread = settings.maxGradeThread;
  2254. rateInfo.max =
  2255. parseInt(rateInfo.max) < parseInt(maxGradeThread)
  2256. ? rateInfo.max
  2257. : maxGradeThread;
  2258. // 构建评分请求的URL和数据
  2259. const rateUrl =
  2260. "/forum.php?mod=misc&action=rate&ratesubmit=yes&infloat=yes&inajax=1";
  2261. const data = new URLSearchParams();
  2262. data.append("formhash", rateInfo.formHash);
  2263. data.append("tid", tid);
  2264. data.append("pid", pid);
  2265. data.append("referer", rateInfo.referer);
  2266. data.append("handlekey", rateInfo.handleKey);
  2267. data.append("score8", `+${rateInfo.max}`);
  2268. data.append("reason", settings.logoText);
  2269. data.append("sendreasonpm", "on");
  2270.  
  2271. // 发送评分请求
  2272. const request = new Request(rateUrl, {
  2273. method: "post",
  2274. headers: {
  2275. "Content-Type": "application/x-www-form-urlencoded",
  2276. },
  2277. body: data,
  2278. });
  2279.  
  2280. try {
  2281. const responseText = await fetch(request).then((r) => r.text());
  2282.  
  2283. // 根据响应内容提供评分成功或失败的提示
  2284. if (responseText.includes("感谢您的参与,现在将转入评分前页面")) {
  2285. showTooltip(`+${rateInfo.max} 评分成功,并通知了楼主!`);
  2286. } else {
  2287. showTooltip("抱歉,评分失败!");
  2288. console.error(responseText);
  2289. }
  2290. } catch (error) {
  2291. showTooltip("评分请求失败!");
  2292. console.error(error);
  2293. }
  2294. }
  2295.  
  2296. // #endregion
  2297.  
  2298. // #region 获取购买记录
  2299.  
  2300. /**
  2301. * 获取指定帖子的购买记录。
  2302. * @param {number} tid - 主题ID。
  2303. * @returns {Object} 购买记录
  2304. * @async
  2305. */
  2306. async function getViewpayments(tid) {
  2307. const infoDefaults = {
  2308. state: false,
  2309. dataRowCount: 0,
  2310. error: "",
  2311. };
  2312.  
  2313. try {
  2314. // 构建评分信息请求的URL
  2315. const url = `/forum.php?mod=misc&action=viewpayments&tid=${tid}&infloat=yes&handlekey=pay&inajax=1&ajaxtarget=fwin_content_pay`;
  2316. const response = await fetch(url);
  2317. if (!response.ok) throw new Error("Failed to fetch Viewpayments info");
  2318. // 解析服务器返回的XML数据
  2319. const text = await response.text();
  2320. const xml = new DOMParser().parseFromString(text, "text/xml");
  2321. const htmlContent = xml.querySelector("root").textContent;
  2322. const doc = new DOMParser().parseFromString(htmlContent, "text/html");
  2323.  
  2324. // 检查是否存在错误
  2325. if (htmlContent.includes("alert_error")) {
  2326. const alertErrorElement = doc.querySelector(".alert_error");
  2327. const scriptElements = alertErrorElement.querySelectorAll("script");
  2328. scriptElements.forEach((script) => script.remove());
  2329.  
  2330. const errorMessage = alertErrorElement.textContent.trim();
  2331. return { ...infoDefaults, error: errorMessage };
  2332. }
  2333. if (htmlContent.includes("目前没有用户购买此主题")) {
  2334. return {
  2335. state: true,
  2336. dataRowCount: 0,
  2337. error: "",
  2338. };
  2339. }
  2340.  
  2341. // 提取购买信息
  2342. var table = doc.querySelector("table.list"); // 选择class为list的table
  2343.  
  2344. if (!table) {
  2345. return {
  2346. state: true,
  2347. dataRowCount: 0,
  2348. error: "",
  2349. };
  2350. }
  2351. var rows = table.querySelectorAll("tr"); // 选中所有的行<tr>
  2352. var dataRowCount = rows.length - 1; // 减去表头的一行
  2353. return {
  2354. state: true,
  2355. dataRowCount: dataRowCount,
  2356. error: "",
  2357. };
  2358. } catch (error) {
  2359. showTooltip(error);
  2360. return infoDefaults;
  2361. }
  2362. }
  2363.  
  2364. // #endregion
  2365.  
  2366. // #region 帖子置顶
  2367.  
  2368. /**
  2369. * 获取指定帖子的置顶信息。
  2370. * @param {number} fid - 板块ID。
  2371. * @param {number} tid - 主题ID。
  2372. * @param {number} pid - 楼层ID。
  2373. * @returns {Object} 置顶信息。
  2374. * @async
  2375. */
  2376. async function getTopicadmin(fid, tid, pid) {
  2377. const infoDefaults = {
  2378. state: false,
  2379. action: "",
  2380. formhash: "",
  2381. page: "",
  2382. handlekey: "",
  2383. error: "",
  2384. };
  2385. try {
  2386. const formhash = getFormHash();
  2387.  
  2388. // 构建评分信息请求的URL
  2389. const url = `/forum.php?mod=topicadmin&action=stickreply&fid=${fid}&tid=${tid}&handlekey=mods&infloat=yes&nopost=yes&inajax=1`;
  2390. const data = new URLSearchParams();
  2391. data.append("formhash", formhash);
  2392. data.append("optgroup", "");
  2393. data.append("operation", "");
  2394. data.append("listextra", "");
  2395. data.append("page", 1);
  2396. data.append("topiclist[]", pid);
  2397.  
  2398. const request = new Request(url, {
  2399. method: "post",
  2400. headers: {
  2401. "Content-Type": "application/x-www-form-urlencoded",
  2402. },
  2403. body: data,
  2404. });
  2405.  
  2406. const text = await fetch(request).then((r) => r.text());
  2407.  
  2408. const xml = new DOMParser().parseFromString(text, "text/xml");
  2409. const htmlContent = xml.querySelector("root").textContent;
  2410. const doc = new DOMParser().parseFromString(htmlContent, "text/html");
  2411.  
  2412. // 检查是否存在错误
  2413. if (htmlContent.includes("alert_error")) {
  2414. const alertErrorElement = doc.querySelector(".alert_error");
  2415. const scriptElements = alertErrorElement.querySelectorAll("script");
  2416. scriptElements.forEach((script) => script.remove());
  2417.  
  2418. const errorMessage = alertErrorElement.textContent.trim();
  2419. return { ...infoDefaults, error: errorMessage };
  2420. }
  2421.  
  2422. // 提取评分信息
  2423. const element = doc.querySelector("#topicadminform");
  2424. if (!element) {
  2425. return { ...infoDefaults, error: "提取置顶信息失败拉!" };
  2426. }
  2427. // 获取元素的action属性值
  2428. const action =
  2429. element.getAttribute("action").replace(/amp;/g, "") + "&inajax=1";
  2430. const newformhash = element.querySelector('input[name="formhash"]').value;
  2431. const page = element.querySelector('input[name="page"]').value;
  2432. const handlekey = element.querySelector('input[name="handlekey"]').value;
  2433.  
  2434. return {
  2435. state: true,
  2436. action,
  2437. formhash: newformhash,
  2438. page,
  2439. handlekey,
  2440. error: "",
  2441. };
  2442. } catch (error) {
  2443. showTooltip(error);
  2444. return infoDefaults;
  2445. }
  2446. }
  2447.  
  2448. /**
  2449. * 对指定的帖子进行置顶。
  2450. * @param {number} pid - 帖子ID。
  2451. * @async
  2452. */
  2453. async function topicadmin(pid, stickreply) {
  2454. showWatermarkMessage();
  2455. const tid = extractTid(window.location.href);
  2456. let fid = getFidFromElement();
  2457.  
  2458. if (!fid) {
  2459. showTooltip("获取板块ID失败!");
  2460. return;
  2461. }
  2462. const topicadminInfo = await getTopicadmin(fid, tid, pid);
  2463. if (!topicadminInfo.state) {
  2464. showTooltip(topicadminInfo.error);
  2465. return;
  2466. }
  2467. const settings = getSettings();
  2468. // 构建置顶请求的URL和数据
  2469. const topicadminUrl = `/${topicadminInfo.action}`;
  2470. const data = new URLSearchParams();
  2471. data.append("formhash", topicadminInfo.formhash);
  2472. data.append("fid", fid);
  2473. data.append("tid", tid);
  2474. data.append("topiclist[]", pid);
  2475. data.append("page", topicadminInfo.page);
  2476. data.append("handlekey", topicadminInfo.handlekey);
  2477. data.append("stickreply", stickreply);
  2478. data.append("reason", settings.logoText);
  2479. data.append("sendreasonpm", "on");
  2480.  
  2481. // 发送置顶请求
  2482. const request = new Request(topicadminUrl, {
  2483. method: "post",
  2484. headers: {
  2485. "Content-Type": "application/x-www-form-urlencoded",
  2486. },
  2487. body: data,
  2488. });
  2489.  
  2490. try {
  2491. const responseText = await fetch(request).then((r) => r.text());
  2492.  
  2493. // 根据响应内容提供置顶成功或失败的提示
  2494. if (responseText.includes("操作成功 ")) {
  2495. showTooltip(
  2496. stickreply == "1"
  2497. ? ` 置顶成功,并通知了楼主!`
  2498. : ` 取消置顶成功,并通知了楼主!`
  2499. );
  2500. } else {
  2501. showTooltip("抱歉,置顶失败!");
  2502. console.error(responseText);
  2503. }
  2504. } catch (error) {
  2505. showTooltip("置顶请求失败!");
  2506. console.error(error);
  2507. }
  2508. }
  2509.  
  2510. /**
  2511. * 从指定的元素中提取fid值
  2512. *
  2513. * @param {string} elementId - 要查找的元素的ID。
  2514. * @returns {string|null} 返回fid值,如果找不到则返回null。
  2515. */
  2516. function getFidFromElement() {
  2517. // 通过ID查找页面上的元素
  2518. let element = document.querySelector("#newspecial");
  2519. // 如果元素不存在,返回null
  2520. if (!element) return null;
  2521.  
  2522. // 获取元素的onclick属性值
  2523. let hrefValue = element.getAttribute("onclick");
  2524.  
  2525. // 如果onclick属性不存在,返回null
  2526. if (!hrefValue) return null;
  2527.  
  2528. // 使用正则表达式匹配fid的值
  2529. let match = /fid=(\d+)/.exec(hrefValue);
  2530.  
  2531. // 如果匹配成功,返回fid的值,否则返回null
  2532. return match ? match[1] : null;
  2533. }
  2534.  
  2535. // #endregion
  2536.  
  2537. // #region 一键评分与收藏
  2538.  
  2539. /**
  2540. * 对首帖进行评分并收藏该帖子。
  2541. * 1. 从页面中选择首帖元素。
  2542. * 2. 从该元素获取帖子ID。
  2543. * 3. 对帖子进行评分。
  2544. * 4. 收藏该帖子。
  2545. */
  2546. function gradeAndStar() {
  2547. // 获取首帖元素
  2548. let firstPobClElement = document.querySelector(".po.hin");
  2549. // 从首帖元素中提取帖子ID
  2550. let pid = getTableIdFromElement(firstPobClElement);
  2551.  
  2552. // 对首帖进行评分
  2553. grade(pid);
  2554. // 收藏首帖
  2555. star();
  2556. }
  2557.  
  2558. // #endregion
  2559.  
  2560. // #region 勋章操作
  2561.  
  2562. /**
  2563. * 判断是否应用设置
  2564. * @param {number} setting - 设置值
  2565. * @param {boolean} targetMatch - 目标匹配标志
  2566. * @return {boolean} - 是否应用设置
  2567. */
  2568. function shouldApplySetting(setting, targetMatch) {
  2569. return setting === 1 || (setting === 2 && targetMatch);
  2570. }
  2571.  
  2572. /**
  2573. * 隐藏勋章
  2574. * @param {HTMLImageElement} img - 勋章图片
  2575. * @param {boolean} targetMatch - 目标匹配标志
  2576. * @param {number} setting - 设置值
  2577. */
  2578. function hideMedal(img, targetMatch, setting) {
  2579. if (shouldApplySetting(setting, targetMatch)) {
  2580. img.style.display = "none";
  2581. } else {
  2582. img.style.display = "";
  2583. }
  2584. }
  2585.  
  2586. /**
  2587. * 调整勋章大小
  2588. * @param {HTMLImageElement} img - 勋章图片
  2589. * @param {boolean} targetMatch - 目标匹配标志
  2590. * @param {number} setting - 设置值
  2591. * @param {string} size - 新的图片大小
  2592. */
  2593. function resizeMedal(img, targetMatch, setting, size) {
  2594. if (shouldApplySetting(setting, targetMatch)) {
  2595. img.style.width = size;
  2596. } else {
  2597. img.style.width = "auto";
  2598. }
  2599. }
  2600.  
  2601. /**
  2602. * 替换勋章
  2603. * @param {HTMLImageElement} img - 勋章图片
  2604. * @param {boolean} targetMatch - 目标匹配标志
  2605. * @param {number} setting - 设置值
  2606. * @param {string} newUrl - 新的图片URL
  2607. */
  2608. function replaceMedal(img, targetMatch, setting, newUrl) {
  2609. if (shouldApplySetting(setting, targetMatch)) {
  2610. img.src = newUrl;
  2611. img.style.width = "50px";
  2612. }
  2613. }
  2614.  
  2615. /**
  2616. * 主要的勋章操作函数
  2617. * @param {object} settings - 设置对象
  2618. */
  2619. function manipulateMedals(settings) {
  2620. const excludeNumbers = [
  2621. 17, 29, 31, 32, 33, 34, 35, 36, 37, 38, 110, 111, 112, 113, 114, 116, 117,
  2622. ];
  2623. const targetMedalNumbers = Array.from({ length: 122 }, (_, i) => i + 14)
  2624. .filter((num) => !excludeNumbers.includes(num))
  2625. .map((num) => `medal${num}`);
  2626.  
  2627. document.querySelectorAll(".md_ctrl img").forEach((img) => {
  2628. const imgSrc = img.src;
  2629. const targetMatch = targetMedalNumbers.some((target) =>
  2630. imgSrc.includes(target)
  2631. );
  2632.  
  2633. hideMedal(img, targetMatch, settings.blockMedals);
  2634. resizeMedal(img, targetMatch, settings.resizeMedals, settings.imageSize);
  2635. replaceMedal(img, targetMatch, settings.replaceMedals, settings.imageUrl);
  2636. });
  2637. }
  2638.  
  2639. // #endregion
  2640.  
  2641. // #region 用户内容屏蔽
  2642.  
  2643. /**
  2644. * 根据设置屏蔽指定用户的内容
  2645. * @param {object} settings - 设置对象,包含被屏蔽的用户列表和显示消息选项
  2646. */
  2647. function blockContentByUsers(settings) {
  2648. const { blockedUsers, displayBlockedTips } = settings;
  2649. blockedUsers.forEach((userID) => {
  2650. const actions = [
  2651. //屏蔽帖子列表页
  2652. createBlockAction(
  2653. `//table//tr[1]/td[2]//cite/a[text()="${userID}"]/ancestor::tbody[1]`,
  2654. `<tr>
  2655. <td class='icn'>
  2656. <img src='static/image/common/folder_common.gif' />
  2657. </td>
  2658. <th class='common'>
  2659. <b>已屏蔽主题 <font color=grey></th>
  2660. <td class='by'>
  2661. <cite><font color=grey>${userID}</font></cite>
  2662. </td>
  2663. <td class='num'></td>
  2664. <td class='by'></td>
  2665. </tr>`
  2666. ),
  2667. //屏蔽搜索列表页
  2668.  
  2669. createBlockAction(
  2670. `//ul/li[p[3]/span[2]/a[text()='${userID}']]`,
  2671. `
  2672. <li class="pbw" >
  2673. <p>
  2674. <span>
  2675. 已屏蔽"${userID}"
  2676. </span>
  2677. </p>
  2678. </li>
  2679. `
  2680. ),
  2681. // createBlockAction('//table/tbody[tr[1]/td[1]//a[text()="' + userID + '"]]', "<p><center>已屏蔽 <font color=grey>" + userID + "</font></center></p>"),
  2682. // createBlockAction('//blockquote[font/a/font[contains(text(),"' + userID + '")]]', "<p>已屏蔽引用 <font color=grey>" + userID + "</font>的言论</p>"),
  2683. // createBlockAction('//table/tbody[tr[1]/th[1]//a[contains(text(),"' + userID + '")]]', ""),
  2684. ];
  2685.  
  2686. actions.forEach(applyBlockAction(displayBlockedTips));
  2687. });
  2688. }
  2689.  
  2690. /**
  2691. * 根据设置的关键词屏蔽帖子标题
  2692. * @param {object} settings - 设置对象,包含被屏蔽的用户列表和显示消息选项
  2693. */
  2694. function blockContentByTitle(settings) {
  2695. const { excludePostOptions, displayBlockedTips } = settings;
  2696. excludePostOptions.forEach((keyword) => {
  2697. const actions = [
  2698. //屏蔽帖子列表页
  2699. // /table/tbody[12]/tr/th/a[2]
  2700. createBlockAction(
  2701. `//table/tbody/tr/th/a[2][contains(text(),'${keyword}')]/ancestor::tbody[1]`,
  2702. `<tr>
  2703. <td class='icn'>
  2704. <img src='static/image/common/folder_common.gif' />
  2705. </td>
  2706. <th class='common'>
  2707. <b>已屏蔽主题关键词:${keyword} <font color=grey></th>
  2708. <td class='by'>
  2709. <cite><font color=grey></font></cite>
  2710. </td>
  2711. <td class='num'></td>
  2712. <td class='by'></td>
  2713. </tr>`
  2714. ),
  2715. ];
  2716.  
  2717. actions.forEach(applyBlockAction(displayBlockedTips));
  2718. });
  2719. }
  2720.  
  2721. /**
  2722. * 创建一个屏蔽动作
  2723. * @param {string} xpath - XPath查询字符串,用于查找要屏蔽的元素
  2724. * @param {string} message - 要显示的消息,当内容被屏蔽时
  2725. * @return {object} - 包含XPath查询和消息的对象
  2726. */
  2727. function createBlockAction(xpath, message) {
  2728. return { xpath, message };
  2729. }
  2730.  
  2731. /**
  2732. * 应用屏蔽动作
  2733. * @param {boolean} displayBlockedTips - 是否显示屏蔽消息
  2734. * @return {function} - 一个函数,该函数接受一个屏蔽动作并应用它
  2735. */
  2736. function applyBlockAction(displayBlockedTips) {
  2737. return function (action) {
  2738. const elements = document.evaluate(
  2739. action.xpath,
  2740. document,
  2741. null,
  2742. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  2743. null
  2744. );
  2745. for (let i = 0; i < elements.snapshotLength; i++) {
  2746. if (displayBlockedTips) {
  2747. elements.snapshotItem(i).innerHTML = action.message;
  2748. } else {
  2749. elements.snapshotItem(i).style.display = "none";
  2750. }
  2751. }
  2752. };
  2753. }
  2754.  
  2755. // #endregion
  2756.  
  2757. // #region 划词搜索功能
  2758.  
  2759. /**
  2760. * 响应用户的文本选择,用于显示搜索选项。
  2761. * @param {Event} e - 事件对象
  2762. */
  2763. function selectSearch(e) {
  2764. const LEFT_MOUSE_BUTTON = 0;
  2765. const MIN_TEXT_LENGTH = 2;
  2766. const forbiddenTags = ["INPUT", "TEXTAREA"];
  2767.  
  2768. // 确保是左键点击
  2769. if (e.button !== LEFT_MOUSE_BUTTON) return;
  2770.  
  2771. // 如果活动元素是输入框或文本区域,则不处理
  2772. const activeElementTag = document.activeElement.tagName.toUpperCase();
  2773. if (forbiddenTags.includes(activeElementTag)) return;
  2774.  
  2775. const selectedText = window.getSelection().toString().trim();
  2776.  
  2777. // 移除已存在的搜索菜单,如果选中的文本过短
  2778. if (selectedText.length < MIN_TEXT_LENGTH) {
  2779. removeSearchMenu();
  2780. return;
  2781. }
  2782.  
  2783. // 如果没有现有的搜索菜单,创建并显示一个
  2784. if (!document.querySelector(".bgsh-sav-menu")) {
  2785. const searchPopup = createSearchPopup(selectedText);
  2786. displaySearchPopup(e.pageX, e.pageY, searchPopup);
  2787. }
  2788. }
  2789.  
  2790. /**
  2791. * 移除已存在的搜索菜单
  2792. */
  2793. function removeSearchMenu() {
  2794. const searchMenu = document.querySelector(".bgsh-sav-menu");
  2795. if (searchMenu) searchMenu.remove();
  2796. }
  2797.  
  2798. /**
  2799. * 在页面上的指定位置显示搜索菜单
  2800. * @param {number} x - 菜单的x坐标
  2801. * @param {number} y - 菜单的y坐标
  2802. * @param {Element} element - 要显示的元素
  2803. */
  2804. function displaySearchPopup(x, y, element) {
  2805. const rect = element.getBoundingClientRect();
  2806. Object.assign(element.style, {
  2807. left: `${x - rect.width / 2}px`,
  2808. top: `${y}px`,
  2809. position: "absolute",
  2810. });
  2811. document.body.appendChild(element);
  2812. }
  2813.  
  2814. /**
  2815. * 根据所选文本创建搜索菜单元素
  2816. * @param {string} selectedText - 所选的文本内容
  2817. * @return {Element} - 创建的按钮元素
  2818. */
  2819. function createSearchPopup(selectedText) {
  2820. const button = document.createElement("button");
  2821. button.classList.add("bgsh-sav-menu", "bgsh-searchBtn");
  2822. button.setAttribute("type", "button");
  2823.  
  2824. const innerDiv = document.createElement("div");
  2825. innerDiv.classList.add("savlink", "savsehuatang");
  2826. innerDiv.setAttribute("data-avid", selectedText);
  2827. innerDiv.textContent = `搜索: ${selectedText}`;
  2828. button.appendChild(innerDiv);
  2829.  
  2830. button.addEventListener("click", handleSearchPopupClick);
  2831. return button;
  2832. }
  2833.  
  2834. /**
  2835. * 处理搜索弹窗点击事件
  2836. * @param {Event} e - 事件对象
  2837. */
  2838. function handleSearchPopupClick(e) {
  2839. const target = e.target;
  2840. if (target.classList.contains("savsehuatang")) {
  2841. target.classList.remove("savsehuatang");
  2842. searchSehuatang(target.dataset.avid);
  2843. }
  2844. removeSearchMenu();
  2845. }
  2846.  
  2847. /**
  2848. * 在Sehuatang中执行搜索
  2849. * @param {string} query - 搜索查询词
  2850. */
  2851. function searchSehuatang(query) {
  2852. const formhash = getFormHash();
  2853. const openSearch = () => window.open(`${baseURL}/search.php`, "_blank");
  2854.  
  2855. if (!formhash) {
  2856. copyToClipboard(query).then(openSearch);
  2857. return;
  2858. }
  2859.  
  2860. const formDataString = `formhash=${encodeURIComponent(
  2861. formhash
  2862. )}&srchtxt=${encodeURIComponent(query)}&searchsubmit=yes`;
  2863.  
  2864. GM_xmlhttpRequest({
  2865. method: "POST",
  2866. url: `${baseURL}/search.php?mod=forum`,
  2867. data: formDataString, // 转换为字符串形式发送
  2868. redirect: "manual",
  2869. headers: {
  2870. "Content-Type": "application/x-www-form-urlencoded",
  2871. Origin: baseURL,
  2872. Referer: baseURL,
  2873. },
  2874. onload: function (response) {
  2875. console.log(response);
  2876. if (response.status === 301 || response.status === 302) {
  2877. var headers = response.responseHeaders.split("\n");
  2878. var locationHeader = headers.find((header) =>
  2879. header.toLowerCase().startsWith("location:")
  2880. );
  2881. if (locationHeader) {
  2882. var location = locationHeader.split(":")[1].trim();
  2883. window.open(`${baseURL}/${location}`, "_blank");
  2884. }
  2885. } else {
  2886. if (response.finalUrl.includes("searchmd5")) {
  2887. showTooltip(
  2888. "目前因论坛限制划词搜索只支持Tampermonkey BETA,请下载BETA版并移除本版本后再进行使用本功能"
  2889. );
  2890. return;
  2891. }
  2892. var htmlString = response.responseText;
  2893. // 将 HTML 字符串解析为一个 DOM 节点
  2894. var parser = new DOMParser();
  2895. var doc = parser.parseFromString(htmlString, "text/html");
  2896.  
  2897. // 获取 id="messagetext"
  2898. var messagetextElement = doc.getElementById("messagetext");
  2899. if (messagetextElement) {
  2900. var firstPElement = messagetextElement.querySelector("p"); // 使用 querySelector 来获取第一个 <p> 标签
  2901. if (firstPElement) {
  2902. showTooltip(firstPElement.textContent);
  2903. return;
  2904. }
  2905. }
  2906. }
  2907. },
  2908. onerror: function (error) {
  2909. console.error("GM_xmlhttpRequest error:", error);
  2910. },
  2911. });
  2912. }
  2913.  
  2914. // #endregion
  2915.  
  2916. // #region 无缝翻页
  2917.  
  2918. /**
  2919. * 初始化无限滚动功能
  2920. * 根据用户的滚动行为来加载下一页的内容。
  2921. *
  2922. * @param {string} pageName 页面名称,用于确定要加载哪种内容
  2923. */
  2924. function initInfiniteScroll(pageName) {
  2925. let isLoading = false;
  2926. let noMoreData = false;
  2927. const settings = getSettings();
  2928.  
  2929. // 根据传入的页面名称决定内容选择器
  2930. let contentSelector;
  2931. switch (pageName) {
  2932. case "isSearchPage":
  2933. case "isForumDisplayPage":
  2934. contentSelector = "#threadlist";
  2935. break;
  2936. case "isPostPage":
  2937. contentSelector = "#postlist";
  2938. break;
  2939. case "isSpacePage":
  2940. contentSelector = "#delform";
  2941. break;
  2942. case "isMySpacePage":
  2943. contentSelector = "#threadlist";
  2944. break;
  2945. case "isShowdarkroomPage":
  2946. contentSelector = "#darkroomtable";
  2947. break;
  2948. case "isMyfavoritePage":
  2949. contentSelector = "#favorite_ul";
  2950. break;
  2951. default:
  2952. contentSelector = "#threadlist"; // 默认选择器
  2953. }
  2954.  
  2955. if (!settings.autoPagination) {
  2956. return;
  2957. }
  2958.  
  2959. /**
  2960. * 加载下一个页面的内容。
  2961. * 获取当前页面中的“下一页”链接,然后抓取该链接的内容,
  2962. * 并将新内容添加到当前页面。
  2963. */
  2964. async function loadNextPage() {
  2965. const nextPageLink = document.querySelector(".nxt");
  2966. if (!nextPageLink || noMoreData) {
  2967. if (!noMoreData) {
  2968. showTooltip("已经是全部数据了");
  2969. noMoreData = true;
  2970. }
  2971. return;
  2972. }
  2973.  
  2974. isLoading = true;
  2975. const url = nextPageLink.getAttribute("href");
  2976.  
  2977. const response = await fetch(url);
  2978. const text = await response.text();
  2979.  
  2980. const div = document.createElement("div");
  2981. div.innerHTML = text;
  2982.  
  2983. const newNextPageLink = div.querySelector(".nxt");
  2984. newNextPageLink
  2985. ? nextPageLink.setAttribute(
  2986. "href",
  2987. newNextPageLink.getAttribute("href")
  2988. )
  2989. : (noMoreData = true);
  2990.  
  2991. appendNewContent(div.querySelector(contentSelector));
  2992.  
  2993. updatePagination(div.querySelector(".pg"));
  2994.  
  2995. const newSettings = getSettings();
  2996. await processPageContentBasedOnSettings(pageName, newSettings);
  2997. blockContentByUsers(settings);
  2998. isLoading = false;
  2999. checkAndLoadIfContentNotEnough();
  3000. }
  3001.  
  3002. /**
  3003. * 将新页面中的内容添加到当前页面。
  3004. * @param {Element} newContent 新的内容元素
  3005. */
  3006. function appendNewContent(newContent) {
  3007. const currentContent = document.querySelector(contentSelector);
  3008. newContent.childNodes.forEach((child) =>
  3009. currentContent.appendChild(child.cloneNode(true))
  3010. );
  3011. }
  3012.  
  3013. /**
  3014. * 更新页面上的分页元素(页码)为新页面中的分页元素。
  3015. * @param {Element} newPgElement 新的分页元素
  3016. */
  3017. function updatePagination(newPgElement) {
  3018. const currentPageElements = document.querySelectorAll(".pg");
  3019. currentPageElements.forEach(
  3020. (pg) => (pg.innerHTML = newPgElement.innerHTML)
  3021. );
  3022. }
  3023.  
  3024. /**
  3025. * 根据页面名称和设置处理页面内容。
  3026. * @param {string} pageName 页面名称
  3027. * @param {Object} settings 用户设置
  3028. */
  3029. async function processPageContentBasedOnSettings(pageName, settings) {
  3030. if (pageName == "isSearchPage") {
  3031. filterElementsBasedOnSettings(settings);
  3032. displayAdvanThreadImages(settings);
  3033. } else if (pageName == "isForumDisplayPage") {
  3034. if (settings.enableTitleStyle) {
  3035. stylePosts(settings);
  3036. }
  3037. removeAD2();
  3038. const currentURL = window.location.href;
  3039. const queryParams = getQueryParams(currentURL);
  3040. const fid = queryParams.fid;
  3041. if (fid == 143 || fid == "143") {
  3042. blockingResolvedAction(settings);
  3043. isOnlyShowMoneyAction(settings);
  3044. }
  3045. if (fid == 166 || fid == "166" || fid == 97 || fid == "97") {
  3046. await displayThreadBuyInfo(settings);
  3047. }
  3048. blockContentByTitle(settings);
  3049. displayThreadImages(settings);
  3050. } else if (pageName == "isPostPage") {
  3051. replacePMonPost();
  3052. appendTitleFromHotImage();
  3053. appendBuyNumber();
  3054. showAvatarEvent();
  3055. const userid = getUserId();
  3056. if (userid) {
  3057. // addQuickGradeToPostButton();//已失效和谐
  3058. addQuickActionToPostButton();
  3059. }
  3060. removeAD3();
  3061. manipulateMedals(settings); // 修改用户勋章显示
  3062. } else if (pageName == "isMySpacePage" || pageName == "isSpacePage") {
  3063. displayThreadBuyInfoOther(settings);
  3064. }
  3065. }
  3066.  
  3067. /**
  3068. * 检查页面内容是否已经填满视窗,如果没有,则加载下一页内容。
  3069. */
  3070. function checkAndLoadIfContentNotEnough() {
  3071. if (document.body.offsetHeight <= window.innerHeight && !isLoading) {
  3072. loadNextPage();
  3073. }
  3074. }
  3075.  
  3076. window.addEventListener("scroll", () => {
  3077. if (
  3078. window.innerHeight + window.scrollY >=
  3079. document.body.offsetHeight - 500 &&
  3080. !isLoading
  3081. ) {
  3082. loadNextPage();
  3083. }
  3084. });
  3085.  
  3086. checkAndLoadIfContentNotEnough();
  3087. }
  3088.  
  3089. /**
  3090. * 根据提供的设置过滤页面上的元素
  3091. * @param {Object} settings 用户设置
  3092. */
  3093. function filterElementsBasedOnSettings(settings) {
  3094. const pbwElements = document.querySelectorAll(".pbw");
  3095.  
  3096. pbwElements.forEach((pbw) => {
  3097. let shouldDisplay = shouldElementBeDisplayed(pbw, settings);
  3098. pbw.style.display = shouldDisplay ? "block" : "none";
  3099. });
  3100. }
  3101.  
  3102. /**
  3103. * 确定给定的元素是否应该根据提供的设置显示在页面上
  3104. * @param {Element} element 待检查的元素
  3105. * @param {Object} settings 用户设置
  3106. * @returns {boolean} 根据设置是否应显示元素
  3107. */
  3108. function shouldElementBeDisplayed(element, settings) {
  3109. if (settings.TIDGroup && settings.TIDGroup.length) {
  3110. const aElement = element.querySelector(".xi1");
  3111. if (!aElement || !doesTIDGroupMatch(aElement, settings.TIDGroup)) {
  3112. return false;
  3113. }
  3114. }
  3115.  
  3116. if (settings.excludeGroup && settings.excludeGroup.length) {
  3117. const pElement = element.querySelector("p:nth-of-type(2)");
  3118. const xs3Element = element.querySelector(".xs3");
  3119.  
  3120. if (
  3121. isExcludedByKeyword(pElement, settings.excludeGroup) ||
  3122. isExcludedByKeyword(xs3Element, settings.excludeGroup)
  3123. ) {
  3124. return false;
  3125. }
  3126. }
  3127.  
  3128. return true;
  3129. }
  3130.  
  3131. /**
  3132. * 检查给定的元素链接是否与提供的TIDGroup中的任何ID匹配
  3133. * @param {Element} aElement 待检查的链接元素
  3134. * @param {Array} TIDGroup TID组
  3135. * @returns {boolean} 是否与TID组匹配
  3136. */
  3137. function doesTIDGroupMatch(aElement, TIDGroup) {
  3138. const href = aElement.getAttribute("href");
  3139.  
  3140. // 判断是否匹配 fid=${tid} 或 forum=${tid} 的格式
  3141. return TIDGroup.some(
  3142. (tid) => href.includes(`fid=${tid}`) || href.includes(`forum-${tid}`)
  3143. );
  3144. }
  3145.  
  3146. /**
  3147. * 检查给定的元素内容是否包含提供的排除关键字列表中的任何关键字
  3148. * @param {Element} element 待检查的元素
  3149. * @param {Array} excludeGroup 排除关键字组
  3150. * @returns {boolean} 是否包含关键字
  3151. */
  3152. function isExcludedByKeyword(element, excludeGroup) {
  3153. if (!element) return false;
  3154. const text = element.textContent.toLowerCase();
  3155. return excludeGroup.some((keyword) => text.includes(keyword.toLowerCase()));
  3156. }
  3157.  
  3158. // #endregion
  3159.  
  3160. // #region 帖子列表页执行的方法
  3161.  
  3162. /**
  3163. * 创建“快速发帖”按钮,用于快速本板块发帖
  3164. * @return {HTMLElement} 按钮元素
  3165. */
  3166. function createFastPostButton() {
  3167. return createButton("fastPostButton", "快速发帖", function () {
  3168. let fid = getFidFromElement();
  3169. showWindow("newthread", `forum.php?mod=post&action=newthread&fid=${fid}`);
  3170. });
  3171. }
  3172.  
  3173. /**
  3174. * 添加日期范围选择器和“打开”按钮到页面
  3175. * @param {HTMLElement|string} targetElementOrId - 参考元素或其ID (将在此元素之后插入日期选择器和按钮)
  3176. */
  3177. function addDateRangeSelectorAndButton(targetElementOrId) {
  3178. const refElement =
  3179. typeof targetElementOrId === "string"
  3180. ? document.getElementById(targetElementOrId)
  3181. : targetElementOrId;
  3182.  
  3183. if (!refElement) return;
  3184.  
  3185. // 创建日期选择框
  3186. const startDateInput = createDateInput("startDateSelector");
  3187. const endDateInput = createDateInput("endDateSelector");
  3188.  
  3189. // 创建并绑定点击事件到“打开”按钮
  3190. const openButton = createButton(
  3191. "openAllUrlButton",
  3192. "批量打开帖子",
  3193. () => filterAndOpenThreadsByDate(),
  3194. "bgsh-openAllUrlBtn",
  3195. "#f6211c"
  3196. );
  3197.  
  3198. // 插入元素到页面中
  3199. refElement.after(openButton);
  3200. refElement.after(endDateInput);
  3201. refElement.after(document.createTextNode("到"));
  3202. refElement.after(startDateInput);
  3203. }
  3204.  
  3205. /**
  3206. * 过滤并在新窗口中打开选定日期范围内的帖子链接。
  3207. */
  3208. function filterAndOpenThreadsByDate() {
  3209. // 获取用户指定的开始和结束日期
  3210. const startDateValue = document.getElementById("startDateSelector").value;
  3211. const endDateValue = document.getElementById("endDateSelector").value;
  3212.  
  3213. // 转换日期字符串为 Date 对象
  3214. const startDate = new Date(startDateValue);
  3215. const endDate = new Date(endDateValue);
  3216.  
  3217. // 选择页面上的所有帖子
  3218. const posts = document.querySelectorAll("#threadlisttableid tbody tr");
  3219.  
  3220. posts.forEach((post) => {
  3221. const spanSpanElement = post.querySelector("td.by em span span");
  3222. const spanElement = post.querySelector("td.by em span");
  3223.  
  3224. let postDateStr = "";
  3225. if (spanSpanElement) {
  3226. // 如果存在td.by em span span,则获取其title属性作为日期字符串
  3227. postDateStr = spanSpanElement.getAttribute("title");
  3228. } else if (spanElement) {
  3229. // 否则,如果存在td.by em span,则获取其文本内容作为日期字符串
  3230. postDateStr = spanElement.textContent;
  3231. }
  3232.  
  3233. if (postDateStr) {
  3234. const postDate = new Date(postDateStr);
  3235.  
  3236. // 检查帖子的日期是否在用户指定的日期范围内
  3237. if (postDate >= startDate && postDate <= endDate) {
  3238. // 尝试从帖子中获取链接元素
  3239. const linkElement = post.querySelector(".s.xst");
  3240. if (linkElement) {
  3241. // 在新窗口中打开帖子链接
  3242. window.open(linkElement.href, "_blank");
  3243. }
  3244. }
  3245. } else {
  3246. console.warn("未找到日期信息");
  3247. }
  3248. });
  3249. }
  3250.  
  3251. /**
  3252. * 创建时间排序按钮
  3253. * @param {Object} settings - 用户的设置
  3254. * @param {Element} buttonContainer - 按钮容器元素
  3255. */
  3256. function createTimeSortButton(settings, buttonContainer) {
  3257. const currentURL = window.location.href;
  3258. const queryParams = getQueryParams(currentURL);
  3259. const fid = queryParams.fid;
  3260. const hasOrderBy = queryParams.orderby === "dateline";
  3261. const isFidInOrder = settings.orderFids.includes(fid);
  3262.  
  3263. const setText = (isOrder) => {
  3264. return isOrder ? "当前列表\n时间排序" : "当前列表\n默认排序";
  3265. };
  3266.  
  3267. const initialButtonText = setText(isFidInOrder);
  3268.  
  3269. const timeSortButton = createButton(
  3270. "timeSortButton",
  3271. initialButtonText,
  3272. function () {
  3273. if (isFidInOrder) {
  3274. timeSortButton.innerText = setText(false);
  3275. if (hasOrderBy) {
  3276. const newURL = `${baseURL}/forum.php?mod=forumdisplay&fid=${fid}`;
  3277. window.location.href = newURL;
  3278. }
  3279. settings.orderFids = settings.orderFids.filter(
  3280. (existingFid) => existingFid !== fid
  3281. );
  3282. } else {
  3283. timeSortButton.innerText = setText(true);
  3284. if (!hasOrderBy) {
  3285. const newURL = `${baseURL}/forum.php?mod=forumdisplay&fid=${fid}&filter=author&orderby=dateline`;
  3286. window.location.href = newURL;
  3287. }
  3288. settings.orderFids.push(fid);
  3289. }
  3290. GM_setValue("orderFids", JSON.stringify(settings.orderFids));
  3291. }
  3292. );
  3293.  
  3294. buttonContainer.appendChild(timeSortButton);
  3295. }
  3296.  
  3297. /**
  3298. * 处理帖子列表页面的初始状态,可能会重定向
  3299. * @param {Object} settings - 用户的设置
  3300. */
  3301. function handleInitialPageState(settings) {
  3302. const currentURL = window.location.href;
  3303. const queryParams = getQueryParams(currentURL);
  3304. const fid = queryParams.fid;
  3305. const hasOrderBy = queryParams.orderby === "dateline";
  3306.  
  3307. // 检查当前fid是否存在于orderFids中
  3308. const isFidInOrder = settings.orderFids.includes(fid);
  3309.  
  3310. if (isFidInOrder && !hasOrderBy) {
  3311. // 如果上次是时间排序,但现在URL没有orderby=dateline,则需要重定向
  3312. const newURL = `${baseURL}/forum.php?mod=forumdisplay&fid=${fid}&filter=author&orderby=dateline`;
  3313. window.location.href = newURL;
  3314. } else if (!isFidInOrder && hasOrderBy) {
  3315. // 如果上次是默认排序,但现在URL有orderby=dateline,则需要重定向
  3316. const newURL = `${baseURL}/forum.php?mod=forumdisplay&fid=${fid}`;
  3317. window.location.href = newURL;
  3318. }
  3319. }
  3320.  
  3321. /**
  3322. * 插入帖子内的前三张图片到帖子标题下方
  3323. */
  3324.  
  3325. async function displayThreadImages(settings) {
  3326. if (!settings.displayThreadImages) {
  3327. return;
  3328. }
  3329. const postLinks = document.querySelectorAll(".s.xst");
  3330.  
  3331. for (let link of postLinks) {
  3332. let threadURL = link.href;
  3333.  
  3334. try {
  3335. let response = await fetch(threadURL);
  3336. let pageContent = await response.text();
  3337. let parser = new DOMParser();
  3338. let doc = parser.parseFromString(pageContent, "text/html");
  3339. let imgElements = doc.querySelectorAll("img.zoom");
  3340.  
  3341. // 过滤图片
  3342. imgElements = Array.from(imgElements)
  3343. .filter((img) => {
  3344. let fileValue = img.getAttribute("file");
  3345. return (
  3346. fileValue &&
  3347. !fileValue.includes("static") &&
  3348. !fileValue.includes("hrline")
  3349. );
  3350. })
  3351. .slice(0, 3);
  3352.  
  3353. if (!imgElements.length) continue;
  3354. const tbodyRef = link.closest("tbody");
  3355. // Check if the tbody with the specific ID already exists. If it does, we skip this iteration.
  3356. if (
  3357. tbodyRef.nextElementSibling &&
  3358. tbodyRef.nextElementSibling.id === "imagePreviewTbody"
  3359. ) {
  3360. continue;
  3361. }
  3362.  
  3363. // 创建新的图片容器
  3364. const newTbody = document.createElement("tbody");
  3365. newTbody.id = "imagePreviewTbody"; // Assigning the unique ID to the tbody
  3366. const newTr = document.createElement("tr");
  3367. const newTd = document.createElement("td");
  3368. const imgContainer = document.createElement("div");
  3369. imgContainer.style.display = "flex";
  3370.  
  3371. imgElements.forEach((imgEl) => {
  3372. let img = document.createElement("img");
  3373. img.src = imgEl.getAttribute("file");
  3374. img.style.width = "300px";
  3375. img.style.height = "auto";
  3376. img.style.maxWidth = "300px";
  3377. img.style.maxHeight = "300px";
  3378. img.style.marginRight = "10px";
  3379. imgContainer.appendChild(img);
  3380. });
  3381.  
  3382. newTd.appendChild(imgContainer);
  3383. newTr.appendChild(newTd);
  3384. newTbody.appendChild(newTr);
  3385.  
  3386. link.closest("tbody").after(newTbody);
  3387. } catch (e) {
  3388. console.error("Error fetching or processing:", e);
  3389. }
  3390. }
  3391. }
  3392.  
  3393. /**
  3394. * 插入购买记录到帖子标题下方
  3395. */
  3396.  
  3397. async function displayThreadBuyInfo(settings) {
  3398. if (!settings.displayThreadBuyInfo) {
  3399. return;
  3400. }
  3401. var links = document.querySelectorAll("a.s.xst"); // 选择所有class为"s xst"的<a>元素
  3402. links.forEach(async function (link) {
  3403. var href = link.href;
  3404. var tid = extractTid(href); // 从URL中获取tid参数
  3405.  
  3406. if (tid) {
  3407. var buyInfo = await getViewpayments(tid); // 用于获取购买信息
  3408. if (buyInfo.state) {
  3409. var dataRowCount = buyInfo.dataRowCount;
  3410. if (link) {
  3411. // 在 link 的父元素中查找 id 为 "baoguobuyinfouniqueSpanId" 的元素
  3412. const existingSpan = link.parentNode.querySelector(
  3413. "#baoguobuyinfouniqueSpanId"
  3414. );
  3415.  
  3416. // 如果不存在这样的 span 元素,则创建并插入一个新的
  3417. if (!existingSpan) {
  3418. const span = document.createElement("span");
  3419. span.id = "baoguobuyinfouniqueSpanId"; // 设置 span 的 ID
  3420. span.style.cssText =
  3421. "font-size: larger; font-weight: bold; color: red;"; // 设置样式
  3422. span.textContent = ` [购买${dataRowCount}次]`;
  3423. if (settings.enableTitleStyle) {
  3424. span.style.fontSize = `${settings.titleStyleSize}px`;
  3425. }
  3426.  
  3427. // 将 <span> 插入到 <a> 后面
  3428. link.parentNode.insertBefore(span, link.nextSibling);
  3429. }
  3430. }
  3431. }
  3432. }
  3433. });
  3434. }
  3435. /**
  3436. * 其他页面插入购买记录到帖子标题下方
  3437. */
  3438.  
  3439. async function displayThreadBuyInfoOther(settings) {
  3440. if (!settings.displayThreadBuyInfo) {
  3441. return;
  3442. }
  3443.  
  3444. // 获取所有<th>标签
  3445. var thElements = document.querySelectorAll("th");
  3446.  
  3447. thElements.forEach(async (th) => {
  3448. // 在当前<th>标签中查找第一个<a>元素
  3449. var aElement = th.querySelector("a");
  3450.  
  3451. // 如果存在<a>元素
  3452. if (aElement) {
  3453. // 获取当前<th>标签的下一个兄弟元素,应为<td>
  3454. var nextTd = th.nextElementSibling;
  3455.  
  3456. // 确保这个兄弟元素是<td>并且包含<a>元素
  3457. if (nextTd && nextTd.tagName === "TD") {
  3458. var tdLink = nextTd.querySelector("a");
  3459.  
  3460. // 如果<td>中有<a>元素
  3461. if (tdLink) {
  3462. // 检查这个<a>的href属性是否包含特定的fid
  3463. if (/fid=166|fid=97|forum-166|forum-97/.test(tdLink.href)) {
  3464. // 执行特定操作,比如打印信息
  3465. var href = aElement.href;
  3466. var tid = extractTid(href); // 从URL中获取tid参数
  3467.  
  3468. if (tid) {
  3469. var buyInfo = await getViewpayments(tid); // 用于获取购买信息
  3470. if (buyInfo.state) {
  3471. var dataRowCount = buyInfo.dataRowCount;
  3472.  
  3473. // 在 link 的父元素中查找 id 为 "baoguobuyinfouniqueSpanId" 的元素
  3474. const existingSpan = aElement.parentNode.querySelector(
  3475. "#baoguobuyinfouniqueSpanId"
  3476. );
  3477.  
  3478. // 如果不存在这样的 span 元素,则创建并插入一个新的
  3479. if (!existingSpan) {
  3480. const span = document.createElement("span");
  3481. span.id = "baoguobuyinfouniqueSpanId"; // 设置 span 的 ID
  3482. span.style.cssText =
  3483. "font-size: larger; font-weight: bold; color: red;"; // 设置样式
  3484. span.textContent = ` [购买${dataRowCount}次]`;
  3485.  
  3486. // 将 <span> 插入到 <a> 后面
  3487. aElement.parentNode.insertBefore(
  3488. span,
  3489. aElement.nextSibling
  3490. );
  3491. }
  3492. }
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. });
  3499. }
  3500.  
  3501. /**
  3502. * 插入帖子内的前三张图片到帖子标题下方
  3503. */
  3504.  
  3505. async function displayAdvanThreadImages(settings) {
  3506. if (!settings.displayThreadImages) {
  3507. return;
  3508. }
  3509. const h3Elements = document.querySelectorAll("h3.xs3");
  3510.  
  3511. for (let h3Element of h3Elements) {
  3512. const aElement = h3Element.querySelector("a");
  3513. if (aElement) {
  3514. let url = aElement.href;
  3515. try {
  3516. let response = await fetch(url);
  3517. let pageContent = await response.text();
  3518. let parser = new DOMParser();
  3519. let doc = parser.parseFromString(pageContent, "text/html");
  3520. let imgElements = doc.querySelectorAll("img.zoom");
  3521.  
  3522. // 过滤图片
  3523. imgElements = Array.from(imgElements)
  3524. .filter((img) => {
  3525. let fileValue = img.getAttribute("file");
  3526. return (
  3527. fileValue &&
  3528. !fileValue.includes("static") &&
  3529. !fileValue.includes("hrline")
  3530. );
  3531. })
  3532. .slice(0, 3);
  3533.  
  3534. if (!imgElements.length) continue;
  3535. const closestLi = h3Element.closest("li");
  3536. if (closestLi.querySelector("tbody, #imagePreviewTbody")) {
  3537. continue;
  3538. }
  3539.  
  3540. // 创建新的图片容器
  3541. const newTbody = document.createElement("tbody");
  3542. newTbody.id = "imagePreviewTbody"; // Assigning the unique ID to the tbody
  3543. const newTr = document.createElement("tr");
  3544. const newTd = document.createElement("td");
  3545. const imgContainer = document.createElement("div");
  3546. imgContainer.style.display = "flex";
  3547.  
  3548. imgElements.forEach((imgEl) => {
  3549. let img = document.createElement("img");
  3550. img.src = imgEl.getAttribute("file");
  3551. img.style.width = "300px";
  3552. img.style.height = "auto";
  3553. img.style.maxWidth = "300px";
  3554. img.style.maxHeight = "300px";
  3555. img.style.marginRight = "10px";
  3556. imgContainer.appendChild(img);
  3557. });
  3558.  
  3559. newTd.appendChild(imgContainer);
  3560. newTr.appendChild(newTd);
  3561. newTbody.appendChild(newTr);
  3562.  
  3563. // h3Element.closest("li").after(newTbody);
  3564. if (closestLi) {
  3565. closestLi.appendChild(newTbody);
  3566. }
  3567. } catch (e) {
  3568. console.error("Error fetching or processing:", e);
  3569. }
  3570. }
  3571. }
  3572. }
  3573.  
  3574. /**
  3575. * 处理帖子列表页面,设置页面状态、样式、内容屏蔽、时间排序和无限滚动
  3576. * @param {Object} settings - 用户的设置
  3577. * @param {Element} buttonContainer - 按钮容器元素
  3578. */
  3579. async function handleForumDisplayPage(settings, buttonContainer) {
  3580. handleInitialPageState(settings);
  3581. if (settings.enableTitleStyle) {
  3582. stylePosts(settings);
  3583. }
  3584. removeAD2();
  3585.  
  3586. removeFastPost();
  3587. createTimeSortButton(settings, buttonContainer);
  3588. blockContentByTitle(settings);
  3589. displayThreadImages(settings);
  3590. const currentURL = window.location.href;
  3591. const queryParams = getQueryParams(currentURL);
  3592. const fid = queryParams.fid;
  3593. if (fid == 143 || fid == "143") {
  3594. blockingResolvedAction(settings);
  3595. isOnlyShowMoneyAction(settings);
  3596. const blockingResolvedText =
  3597. settings.blockingResolved == true ? "显示解决" : "屏蔽解决";
  3598. const blockingResolvedButton = createButton(
  3599. "blockingResolvedBtn",
  3600. blockingResolvedText,
  3601. function () {
  3602. if (blockingResolvedButton.innerText === "显示解决") {
  3603. blockingResolvedButton.innerText = "屏蔽解决";
  3604. GM_setValue("blockingResolved", false);
  3605. location.reload();
  3606. } else {
  3607. blockingResolvedButton.innerText = "显示解决";
  3608. GM_setValue("blockingResolved", true);
  3609. location.reload();
  3610. }
  3611. }
  3612. );
  3613. buttonContainer.appendChild(blockingResolvedButton);
  3614.  
  3615. const isOnlyShowMoneyText =
  3616. settings.isOnlyShowMoney == true ? "显示全部" : "只看现金";
  3617. const isOnlyShowMoneyButton = createButton(
  3618. "isOnlyShowMoneyBtn",
  3619. isOnlyShowMoneyText,
  3620. function () {
  3621. if (isOnlyShowMoneyButton.innerText === "显示全部") {
  3622. isOnlyShowMoneyButton.innerText = "只看现金";
  3623. GM_setValue("isOnlyShowMoney", false);
  3624. location.reload();
  3625. } else {
  3626. isOnlyShowMoneyButton.innerText = "显示全部";
  3627. GM_setValue("isOnlyShowMoney", true);
  3628. location.reload();
  3629. }
  3630. }
  3631. );
  3632. buttonContainer.appendChild(isOnlyShowMoneyButton);
  3633. }
  3634. if (fid == 166 || fid == "166" || fid == 97 || fid == "97") {
  3635. await displayThreadBuyInfo(settings);
  3636. }
  3637.  
  3638. const userid = getUserId();
  3639. if (userid && settings.showFastPost) {
  3640. buttonContainer.appendChild(createFastPostButton());
  3641. }
  3642. const targetElement = document.querySelector(".xs1.xw0.i");
  3643. addDateRangeSelectorAndButton(targetElement);
  3644. initInfiniteScroll("isForumDisplayPage");
  3645. }
  3646.  
  3647. /**
  3648. * 移除帖子列表页广告
  3649. */
  3650. async function removeAD2() {
  3651. document.querySelectorAll(".show-text2").forEach((element) => {
  3652. element.remove();
  3653. });
  3654. }
  3655.  
  3656. /**
  3657. * 移除列表底部的快速发帖
  3658. */
  3659. function removeFastPost() {
  3660. document.querySelectorAll("#f_pst").forEach((element) => {
  3661. element.remove();
  3662. });
  3663. }
  3664.  
  3665. /**
  3666. * 移除帖子列表页已解决的帖子
  3667. */
  3668. async function blockingResolvedAction(settings) {
  3669. if (settings.blockingResolved) {
  3670. const currentURL = window.location.href;
  3671. const queryParams = getQueryParams(currentURL);
  3672. const fid = queryParams.fid;
  3673.  
  3674. // 获取页面上所有的 tbody 元素
  3675. const tbodies = document.querySelectorAll("tbody");
  3676.  
  3677. // 遍历每个 tbody 元素
  3678. tbodies.forEach((tbody) => {
  3679. // 检查 tbody 的文本内容是否包含指定的字符串
  3680. if (tbody.textContent.includes("[已解决]")) {
  3681. // 如果包含,移除这个 tbody 元素
  3682. tbody.remove();
  3683. }
  3684. });
  3685. }
  3686. }
  3687.  
  3688. /**
  3689. * 帖子列表页只显示E卡
  3690. */
  3691. async function isOnlyShowMoneyAction(settings) {
  3692. if (!settings.isOnlyShowMoney) {
  3693. return; // 如果设置不启用,直接返回
  3694. }
  3695.  
  3696. const tbodies = document.querySelectorAll("tbody");
  3697. const keywords = ["E卡", "e卡", "话费"]; // 关键词列表
  3698. const excludedSelectors = ["#scbar_txt", "#scbar_btn", "#scbar_type"]; // 不应被移除的元素的选择器
  3699.  
  3700. tbodies.forEach((tbody) => {
  3701. // 检查tbody是否包含排除的选择器中的任何一个元素
  3702. const isExcluded = excludedSelectors.some((selector) =>
  3703. tbody.querySelector(selector)
  3704. );
  3705. if (isExcluded) {
  3706. return; // 如果包含排除元素,则不移除此tbody
  3707. }
  3708.  
  3709. // 检查是否包含任何关键词
  3710. const containsKeyword = keywords.some((keyword) =>
  3711. tbody.textContent.includes(keyword)
  3712. );
  3713. if (!containsKeyword) {
  3714. tbody.remove(); // 如果不包含关键词且没有排除标识,则移除
  3715. }
  3716. });
  3717. }
  3718.  
  3719. // #endregion
  3720.  
  3721. // #region 搜索页执行的方法
  3722.  
  3723. /**
  3724. * 处理搜索页面,包括增加高级搜索、添加页码、基于设置过滤元素和初始化无限滚动
  3725. * @param {Object} settings - 用户的设置
  3726. */
  3727. function handleSearchPage(settings) {
  3728. replaceImageSrc();
  3729. addAdvancedSearch(settings);
  3730. addPageNumbers();
  3731. filterElementsBasedOnSettings(settings);
  3732. initInfiniteScroll("isSearchPage");
  3733. displayAdvanThreadImages(settings);
  3734. }
  3735.  
  3736. // #endregion
  3737.  
  3738. // #region 帖子内容页执行方法
  3739.  
  3740. /**
  3741. * 创建“复制内容”按钮,用于快速复制本帖内容
  3742. * @return {HTMLElement} 按钮元素
  3743. */
  3744. function createFastCopyButton() {
  3745. return createButton("fastCopyButton", "复制帖子", function () {
  3746. var content = document.querySelector(".t_f");
  3747. var secondContent = document.querySelectorAll(".t_f")[1];
  3748. var resultHtml = "";
  3749. if (content) {
  3750. resultHtml += processContent(content);
  3751. }
  3752. if (secondContent && secondContent.querySelectorAll("img").length > 3) {
  3753. resultHtml += processContent(secondContent);
  3754. }
  3755. if (resultHtml !== "") {
  3756. copyToClipboard(resultHtml);
  3757. copyToClipboard(
  3758. resultHtml,
  3759. () => showTooltip("内容已复制!"),
  3760. (err) => showTooltip("复制失败: ", err)
  3761. );
  3762. } else {
  3763. showTooltip("复制失败: 没有找到相应内容");
  3764. }
  3765. });
  3766. }
  3767.  
  3768. /**
  3769. * 处理指定的内容
  3770. * @param {string} content html文本
  3771. * @return {cleanedHtml} 处理好的内容
  3772. */
  3773.  
  3774. function processContent(content) {
  3775. var html = content.innerHTML;
  3776. var cleanedHtml = removeElementsByClass(
  3777. html,
  3778. ["pstatus", "tip_4"],
  3779. [
  3780. "font",
  3781. "div",
  3782. "ignore_js_op",
  3783. "br",
  3784. "ol",
  3785. "li",
  3786. "strong",
  3787. "a",
  3788. "i",
  3789. "table",
  3790. "tbody",
  3791. "tr",
  3792. "td",
  3793. "blockquote",
  3794. ],
  3795. ["em"]
  3796. );
  3797. cleanedHtml = removeNbspAndNewlines(cleanedHtml);
  3798. cleanedHtml = removeElementsByIdPrefix(cleanedHtml, "attach_");
  3799.  
  3800. return cleanedHtml;
  3801. }
  3802.  
  3803. /**
  3804. * 移除不需要的内容
  3805. * @param {string} htmlString html文本
  3806. * @return {stringWithoutNbsp} 链接
  3807. */
  3808.  
  3809. function removeNbspAndNewlines(htmlString) {
  3810. var stringWithoutNbsp = htmlString.replace(/&nbsp;/g, "");
  3811. stringWithoutNbsp = stringWithoutNbsp.replace(/&amp;/g, "");
  3812. stringWithoutNbsp = stringWithoutNbsp.replace(/\n+/g, "\n");
  3813. stringWithoutNbsp = stringWithoutNbsp.replace(/\\baoguo/g, "\n");
  3814. return stringWithoutNbsp;
  3815. }
  3816.  
  3817. /**
  3818. * 处理指定的内容
  3819. * @param {string} htmlString html文本
  3820. * @param {string} classList class列表
  3821. * @param {string} tagsToRemove tags
  3822. * @param {string} tagsToAllRemove tags
  3823. * @return {doc.body.innerHTML} 处理好的内容
  3824. */
  3825.  
  3826. function removeElementsByClass(
  3827. htmlString,
  3828. classList,
  3829. tagsToRemove,
  3830. tagsToAllRemove
  3831. ) {
  3832. var parser = new DOMParser();
  3833. var doc = parser.parseFromString(htmlString, "text/html");
  3834. classList.forEach(function (className) {
  3835. var elements = doc.querySelectorAll("." + className);
  3836. elements.forEach(function (element) {
  3837. element.parentNode.removeChild(element);
  3838. });
  3839. });
  3840. tagsToRemove.forEach(function (tagName) {
  3841. var elements = doc.querySelectorAll(tagName);
  3842. elements.forEach(function (element) {
  3843. while (element.firstChild) {
  3844. element.parentNode.insertBefore(element.firstChild, element);
  3845. }
  3846. element.parentNode.removeChild(element);
  3847. });
  3848. });
  3849. tagsToAllRemove.forEach(function (tagName) {
  3850. var elements = doc.querySelectorAll(tagName);
  3851.  
  3852. elements.forEach(function (element) {
  3853. element.parentNode.removeChild(element);
  3854. });
  3855. });
  3856. var imgElements = doc.querySelectorAll("img");
  3857. imgElements.forEach(function (img) {
  3858. var fileAttr = img.getAttribute("file");
  3859. if (fileAttr) {
  3860. var fileText =
  3861. (fileAttr.includes("static/image") ? "" : fileAttr) + "\\baoguo";
  3862. var textNode = document.createTextNode(fileText);
  3863. img.parentNode.replaceChild(textNode, img);
  3864. } else {
  3865. var srcAttr = img.getAttribute("src");
  3866. if (srcAttr) {
  3867. var srcText =
  3868. (srcAttr.includes("static/image") ? "" : srcAttr) + "\\baoguo";
  3869. var textNode1 = document.createTextNode(srcText);
  3870. img.parentNode.replaceChild(textNode1, img);
  3871. }
  3872. }
  3873. });
  3874. return doc.body.innerHTML;
  3875. }
  3876.  
  3877. /**
  3878. * 移除包含指定的内容的元素
  3879. * @param {string} htmlString html文本
  3880. * @param {string} idPrefix 指定内容
  3881. * @return {doc.body.innerHTML} 处理好的内容
  3882. */
  3883. function removeElementsByIdPrefix(html, idPrefix) {
  3884. // 使用 DOMParser 解析 HTML 字符串
  3885. const parser = new DOMParser();
  3886. const doc = parser.parseFromString(html, "text/html");
  3887.  
  3888. // 选择所有 id 属性包含特定前缀的元素
  3889. const elements = doc.querySelectorAll(`[id^="${idPrefix}"]`);
  3890.  
  3891. // 移除这些元素
  3892. elements.forEach((element) => {
  3893. element.remove();
  3894. });
  3895.  
  3896. // 将处理后的 DOM 转回为 HTML 字符串
  3897. return doc.body.innerHTML;
  3898. }
  3899.  
  3900. /**
  3901. * 创建“快速回复”按钮,用于快速回复本帖内容
  3902. * @return {HTMLElement} 按钮元素
  3903. */
  3904. function createFastReplyButton() {
  3905. return createButton("fastReplyButton", "快速回复", function () {
  3906. let fid = getFidFromElement();
  3907. const tid = extractTid(window.location.href);
  3908. showWindow(
  3909. "reply",
  3910. `forum.php?mod=post&action=reply&fid=${fid}&tid=${tid}`
  3911. );
  3912. });
  3913. }
  3914.  
  3915. /**
  3916. * 创建“快速私信”按钮,用于快速私信
  3917. * @return {HTMLElement} 按钮元素
  3918. */
  3919. function createFastPMButton(pid, touid) {
  3920. return createButton(
  3921. "fastPMButton",
  3922. "快速私信",
  3923. function () {
  3924. let fid = getFidFromElement();
  3925. const tid = extractTid(window.location.href);
  3926. showWindow(
  3927. "sendpm",
  3928. `home.php?mod=spacecp&ac=pm&op=showmsg&handlekey=showmsg_${touid}&touid=${touid}&pmid=0&daterange=2&pid=${pid}&tid=${tid}`
  3929. );
  3930. },
  3931. "bgsh-fastPMButtonBtn",
  3932. "#7f8c8d"
  3933. );
  3934. }
  3935.  
  3936. /**
  3937. * 创建“查看评分”按钮,用于快速查看本帖评分
  3938. * @return {HTMLElement} 按钮元素
  3939. */
  3940. function createViewRatingsButton(pid) {
  3941. return createButton("viewRatingsButton", "查看评分", function () {
  3942. let fid = getFidFromElement();
  3943. const tid = extractTid(window.location.href);
  3944. showWindow(
  3945. "viewratings",
  3946. `forum.php?mod=misc&action=viewratings&tid=${tid}&pid=${pid}`
  3947. );
  3948. });
  3949. }
  3950.  
  3951. /**
  3952. * 创建“购买记录”按钮,用于快速查看本帖购买记录
  3953. * @return {HTMLElement} 按钮元素
  3954. */
  3955. function createPayLogButton(pid) {
  3956. return createButton("payLogButton", "购买记录", function () {
  3957. let fid = getFidFromElement();
  3958. const tid = extractTid(window.location.href);
  3959. showWindow(
  3960. "pay",
  3961. `forum.php?mod=misc&action=viewpayments&tid=${tid}&pid=${pid}`
  3962. );
  3963. });
  3964. }
  3965.  
  3966. /**
  3967. * 创建“下载附件”按钮,用于快速下载附件
  3968. * @return {HTMLElement} 按钮元素
  3969. */
  3970. function createDownButton() {
  3971. return createButton("downButton", "下载附件", function () {
  3972. // 检查是否已存在模态框
  3973. if (document.getElementById("customModal")) {
  3974. return;
  3975. }
  3976.  
  3977. const spans = document.querySelectorAll('span[id*="attach_"]');
  3978. const lockedDivs = Array.from(
  3979. document.querySelectorAll("div.locked")
  3980. ).filter((div) => div.textContent.includes("购买"));
  3981. const dls = Array.from(document.querySelectorAll("dl.tattl")).filter(
  3982. (dl) => dl.querySelector("p.attnm")
  3983. );
  3984.  
  3985. const elements = [...spans, ...dls, ...lockedDivs];
  3986.  
  3987. if (elements.length === 0) {
  3988. showTooltip("没有找到任何附件。");
  3989. return;
  3990. }
  3991.  
  3992. const result = elements.map((el) => el.outerHTML).join("<br>");
  3993.  
  3994. // 创建模态框
  3995. const modal = document.createElement("div");
  3996. modal.id = "customModal";
  3997. modal.style.position = "fixed";
  3998. modal.style.left = "50%";
  3999. modal.style.top = "50%";
  4000. modal.style.transform = "translate(-50%, -50%)";
  4001. modal.style.backgroundColor = "#FFF";
  4002. modal.style.padding = "20px";
  4003. modal.style.border = "1px solid #DDD";
  4004. modal.style.boxShadow = "0px 0px 10px rgba(0,0,0,0.5)";
  4005. modal.style.borderRadius = "8px";
  4006. modal.style.width = "80%";
  4007. modal.style.maxWidth = "600px";
  4008. modal.style.height = "auto";
  4009. modal.style.maxHeight = "80vh";
  4010. modal.style.overflowY = "auto";
  4011. modal.style.zIndex = "100";
  4012.  
  4013. // 添加内容和关闭按钮
  4014. modal.innerHTML = `<div style="margin-bottom: 20px;">${result}</div><button id="closeModal" style="padding: 5px 10px; background-color: #F44336; color: white; border: none; border-radius: 5px; cursor: pointer;">关闭</button>`;
  4015.  
  4016. document.body.appendChild(modal);
  4017.  
  4018. // 关闭按钮事件
  4019. document.getElementById("closeModal").addEventListener("click", () => {
  4020. modal.remove();
  4021. });
  4022. });
  4023. }
  4024.  
  4025. /**
  4026. * 创建“复制代码”按钮,用于复制页面内所有代码块的内容
  4027. * @return {HTMLElement} 按钮元素
  4028. */
  4029. function createCopyCodeButton() {
  4030. return createButton("copyCodeButton", "复制代码", function () {
  4031. let allBlockCodes = document.querySelectorAll(".blockcode");
  4032. let allTexts = [];
  4033. allBlockCodes.forEach((blockCode) => {
  4034. let liElements = blockCode.querySelectorAll("li");
  4035. liElements.forEach((li) => {
  4036. allTexts.push(li.textContent);
  4037. });
  4038. });
  4039. let combinedText = allTexts.join("\n");
  4040. copyToClipboard(
  4041. combinedText,
  4042. () => showTooltip("代码已复制!"),
  4043. (err) => showTooltip("复制失败: ", err)
  4044. );
  4045. });
  4046. }
  4047.  
  4048. /**
  4049. * 创建“快速评分”按钮,用于页面内对主帖的内容快速评分
  4050. * @return {HTMLElement} 按钮元素
  4051. */
  4052. function createQuickGradeButton(pid) {
  4053. return createButton("quickGradeButton", "快速评分", () => grade(pid));
  4054. }
  4055.  
  4056. /**
  4057. * 创建“快速收藏”按钮,用于页面内对回复的内容快速收藏
  4058. * @return {HTMLElement} 按钮元素
  4059. */
  4060. function createQuickStarButton() {
  4061. return createButton("quickStarButton", "快速收藏", star);
  4062. }
  4063.  
  4064. /**
  4065. * 创建“一键二连”按钮,用于页面内对回复的内容快速评分和收藏
  4066. * @return {HTMLElement} 按钮元素
  4067. */
  4068. function createOneClickDoubleButton() {
  4069. return createButton("oneClickDoubleButton", "一键二连", gradeAndStar);
  4070. }
  4071.  
  4072. /**
  4073. * 创建“快速置顶”按钮,用于页面内对回复的内容快速置顶
  4074. * @return {HTMLElement} 按钮元素
  4075. */
  4076. function createQuickTopicadminToPostButton(post, stickreply) {
  4077. var text = stickreply === "1" ? "快速置顶" : "取消置顶";
  4078. return createButton(
  4079. "quickTopicadminToPost",
  4080. text,
  4081. () => {
  4082. let pid = getTableIdFromElement(post);
  4083. if (pid) {
  4084. topicadmin(pid, stickreply);
  4085. } else {
  4086. showTooltip("未找到置顶元素");
  4087. }
  4088. },
  4089. "bgsh-quickTopicadminToPostBtn",
  4090. "#002661"
  4091. );
  4092. }
  4093. /**
  4094. * 创建“快速编辑回复”按钮,用于页面内对回复的内容快速编辑
  4095. * @return {HTMLElement} 按钮元素
  4096. */
  4097. function createQuickReplyEditToPostButton(post) {
  4098. var text = "编辑回复";
  4099. return createButton(
  4100. "quickReplyEditToPost",
  4101. text,
  4102. () => {
  4103. let pid = getTableIdFromElement(post);
  4104. if (pid) {
  4105. let fid = getFidFromElement();
  4106. const tid = extractTid(window.location.href);
  4107. window.location.href = `forum.php?mod=post&action=edit&fid=${fid}&tid=${tid}&pid=${pid}`;
  4108. } else {
  4109. showTooltip("未找到回复元素");
  4110. }
  4111. },
  4112. "bgsh-quickReplyEditToPostBtn",
  4113. "#c42626"
  4114. );
  4115. }
  4116.  
  4117. /**
  4118. * 创建“快速回复”按钮,用于页面内对回复的内容快速置顶
  4119. * @return {HTMLElement} 按钮元素
  4120. */
  4121. function createQuickReplyToPostButton(post) {
  4122. var text = "快速回复";
  4123. return createButton(
  4124. "quickReplyToPost",
  4125. text,
  4126. () => {
  4127. let pid = getTableIdFromElement(post);
  4128. if (pid) {
  4129. let fid = getFidFromElement();
  4130. const tid = extractTid(window.location.href);
  4131. showWindow(
  4132. "reply",
  4133. `forum.php?mod=post&action=reply&fid=${fid}&tid=${tid}&repquote=${pid}`
  4134. );
  4135. } else {
  4136. showTooltip("未找到回复元素");
  4137. }
  4138. },
  4139. "bgsh-quickReplyToPostBtn",
  4140. "#c42626"
  4141. );
  4142. }
  4143. /**
  4144. * 创建“最佳答案”按钮,用于页面内对回复的内容最佳
  4145. * @return {HTMLElement} 按钮元素
  4146. */
  4147. function createSetAnswerToPostButton(post) {
  4148. var text = "最佳答案";
  4149. return createButton(
  4150. "setAnswerToPost",
  4151. text,
  4152. () => {
  4153. let pid = getTableIdFromElement(post);
  4154. if (pid) {
  4155. // let fid = getFidFromElement();
  4156. // const tid = extractTid(window.location.href);
  4157. // showWindow("reply", `forum.php?mod=post&action=reply&fid=${fid}&tid=${tid}&repquote=${pid}`);
  4158. setanswer(pid, "");
  4159. } else {
  4160. showTooltip("未找到最佳答案");
  4161. }
  4162. },
  4163. "bgsh-setAnswerToPostBtn",
  4164. "#4c9ae1"
  4165. );
  4166. }
  4167.  
  4168. /**
  4169. * 创建“广告举报”按钮,用于页面内对回复的内容广告举报
  4170. * @return {HTMLElement} 按钮元素
  4171. */
  4172. function createQuickReportadToPostButton(post) {
  4173. var text = "广告举报";
  4174. return createButton(
  4175. "quickReportadToPost",
  4176. text,
  4177. () => {
  4178. let pid = getTableIdFromElement(post);
  4179. if (pid) {
  4180. const tid = extractTid(window.location.href);
  4181. showWindow(
  4182. "reportad",
  4183. `plugin.php?id=pc_reportad&tid=${tid}&pid=${pid}`
  4184. );
  4185. } else {
  4186. showTooltip("未找到举报元素");
  4187. }
  4188. },
  4189. "bgsh-quickReportadToPostBtn",
  4190. "#333333"
  4191. );
  4192. }
  4193.  
  4194. /**
  4195. * 创建“快速举报”按钮,用于页面内对回复的内容快速举报
  4196. * @return {HTMLElement} 按钮元素
  4197. */
  4198. function createQuickMiscReportToPostButton(post) {
  4199. var text = "快速举报";
  4200. return createButton(
  4201. "quickMiscReport",
  4202. text,
  4203. () => {
  4204. let pid = getTableIdFromElement(post);
  4205. if (pid) {
  4206. let fid = getFidFromElement();
  4207. const tid = extractTid(window.location.href);
  4208. showWindow(
  4209. `miscreport${pid}`,
  4210. `misc.php?mod=report&rtype=post&rid=${pid}&tid=${tid}&fid=${fid}`
  4211. );
  4212. } else {
  4213. showTooltip("未找到回复元素");
  4214. }
  4215. },
  4216. "bgsh-QuickMiscReportBtn",
  4217. "#333333"
  4218. );
  4219. }
  4220.  
  4221. /**
  4222. * 添加对回复进行操作的按钮,用于页面内对回复的内容快速置顶/回复等等
  4223. * @return {HTMLElement} 按钮元素
  4224. */
  4225. function addQuickActionToPostButton() {
  4226. const postContainers = document.querySelectorAll(".po.hin");
  4227.  
  4228. postContainers.forEach((postContainer) => {
  4229. // 检查该元素之后是否已经有一个quickTopicadminToPost
  4230. const existingButton = postContainer.parentNode.querySelector(
  4231. "#quickTopicadminToPost"
  4232. );
  4233. if (existingButton) {
  4234. // 如果已存在按钮,则直接返回
  4235. return;
  4236. }
  4237.  
  4238. // 寻找 element 的父级 tbody
  4239. let parentTbody = postContainer.closest("tbody");
  4240. var stickreply =
  4241. parentTbody &&
  4242. parentTbody.querySelector('img[src="static/image/common/settop.png"]')
  4243. ? "0"
  4244. : "1";
  4245. const quickTopicadminToPostButton = createQuickTopicadminToPostButton(
  4246. postContainer,
  4247. stickreply
  4248. );
  4249. const replyToPostButton = createQuickReplyToPostButton(postContainer);
  4250. const quickMiscReportToPostButton =
  4251. createQuickMiscReportToPostButton(postContainer);
  4252. const quickReportadToPostButton =
  4253. createQuickReportadToPostButton(postContainer);
  4254. const setAnswerToPostButton = createSetAnswerToPostButton(postContainer);
  4255.  
  4256. postContainer.appendChild(replyToPostButton);
  4257. postContainer.appendChild(quickTopicadminToPostButton);
  4258. postContainer.appendChild(quickMiscReportToPostButton);
  4259. postContainer.appendChild(quickReportadToPostButton);
  4260. const found = postContainer.querySelector(`.editp`);
  4261. // 如果找到了具有指定类的元素,弹出窗口
  4262. if (found) {
  4263. const quickReplyEditToPostButton =
  4264. createQuickReplyEditToPostButton(postContainer);
  4265. postContainer.appendChild(quickReplyEditToPostButton);
  4266. }
  4267. if (postContainer && postContainer.innerHTML.includes("setanswer(")) {
  4268. postContainer.appendChild(setAnswerToPostButton);
  4269. }
  4270. });
  4271. }
  4272.  
  4273. /**
  4274. * 用于页面内对头像的屏蔽与显示
  4275. * @return {HTMLElement} 按钮元素
  4276. */
  4277. function showAvatarEvent() {
  4278. const avatars = document.querySelectorAll(".avatar");
  4279. const isPostPage = () =>
  4280. /forum\.php\?mod=viewthread|\/thread-\d+-\d+-\d+\.html/.test(
  4281. window.location.href
  4282. );
  4283. if (!isPostPage()) {
  4284. return;
  4285. }
  4286. var settings = getSettings();
  4287. // 遍历所有头像元素
  4288. avatars.forEach((avatar) => {
  4289. // 如果复选框被选中,显示头像;否则,隐藏头像
  4290. if (settings.showAvatar) {
  4291. avatar.style.display = "block";
  4292. } else {
  4293. avatar.style.display = "none";
  4294. }
  4295. });
  4296. }
  4297.  
  4298. /**
  4299. * 在帖子内容页中添加和执行各种功能
  4300. * @param {Object} settings - 用户的设置
  4301. * @param {HTMLElement} buttonContainer - 按钮容器
  4302. */
  4303. function handlePostPage(settings, buttonContainer) {
  4304. const toggleImages = (action) => {
  4305. const images = document.querySelectorAll("img.zoom");
  4306. images.forEach(
  4307. (img) => (img.style.display = action === "hide" ? "none" : "")
  4308. );
  4309. };
  4310.  
  4311. toggleImages(settings.showImageButton);
  4312.  
  4313. const initialButtonText =
  4314. settings.showImageButton === "show" ? "隐藏图片" : "显示图片";
  4315.  
  4316. const toggleButton = createButton(
  4317. "toggleImageDisplay",
  4318. initialButtonText,
  4319. function () {
  4320. if (toggleButton.innerText === "显示图片") {
  4321. toggleImages("show");
  4322. toggleButton.innerText = "隐藏图片";
  4323. GM_setValue("showImageButton", "show");
  4324. } else {
  4325. toggleImages("hide");
  4326. toggleButton.innerText = "显示图片";
  4327. GM_setValue("showImageButton", "hide");
  4328. }
  4329. }
  4330. );
  4331. buttonContainer.appendChild(toggleButton);
  4332. if (settings.showDown) {
  4333. buttonContainer.appendChild(createDownButton());
  4334. }
  4335.  
  4336. let codeBlocks = document.querySelectorAll(".blockcode");
  4337. if (codeBlocks.length > 0 && settings.showCopyCode) {
  4338. buttonContainer.appendChild(createCopyCodeButton());
  4339. }
  4340. let firstPobClElement = document.querySelector(".po.hin");
  4341. let pid = getTableIdFromElement(firstPobClElement);
  4342.  
  4343. const userid = getUserId();
  4344. if (userid) {
  4345. if (settings.showFastPost) {
  4346. buttonContainer.appendChild(createFastPostButton());
  4347. }
  4348. if (settings.showFastReply) {
  4349. buttonContainer.appendChild(createFastReplyButton());
  4350. }
  4351. if (settings.showQuickGrade) {
  4352. buttonContainer.appendChild(createQuickGradeButton(pid));
  4353. }
  4354. if (settings.showQuickStar) {
  4355. buttonContainer.appendChild(createQuickStarButton());
  4356. }
  4357. if (settings.showClickDouble) {
  4358. buttonContainer.appendChild(createOneClickDoubleButton());
  4359. }
  4360.  
  4361. // addQuickGradeToPostButton();//已失效和谐
  4362. addQuickActionToPostButton();
  4363. }
  4364. if (settings.showViewRatings) {
  4365. buttonContainer.appendChild(createViewRatingsButton(pid));
  4366. }
  4367. if (settings.showPayLog) {
  4368. buttonContainer.appendChild(createPayLogButton(pid));
  4369. }
  4370. if (settings.showFastCopy) {
  4371. buttonContainer.appendChild(createFastCopyButton());
  4372. }
  4373.  
  4374. if (settings.defaultSwipeToSearch) {
  4375. document.addEventListener("mouseup", selectSearch);
  4376. }
  4377. initInfiniteScroll("isPostPage");
  4378. showAvatarEvent();
  4379. removeAD3();
  4380. replacePMonPost();
  4381. removeFastReply();
  4382. appendTitleFromHotImage();
  4383. appendBuyNumber();
  4384. }
  4385.  
  4386. /**
  4387. * 移除帖子内容页广告
  4388. */
  4389. async function removeAD3() {
  4390. document.querySelectorAll('[class*="show-text"]').forEach((element) => {
  4391. element.remove();
  4392. });
  4393. document.querySelectorAll('[id*="mgc_post"]').forEach((element) => {
  4394. element.remove();
  4395. });
  4396. document.querySelectorAll("#p_btn").forEach((element) => {
  4397. element.remove();
  4398. });
  4399. document.querySelectorAll(".pob.cl").forEach((element) => {
  4400. element.remove();
  4401. });
  4402. }
  4403.  
  4404. /**
  4405. * 移除帖子底部的快速回帖
  4406. */
  4407. function removeFastReply() {
  4408. document.querySelectorAll("#f_pst").forEach((element) => {
  4409. element.remove();
  4410. });
  4411. }
  4412. /**
  4413. * 替换帖子内容页私信
  4414. */
  4415. async function replacePMonPost() {
  4416. let firstPobClElement = document.querySelector(".po.hin");
  4417. let pid = getTableIdFromElement(firstPobClElement);
  4418. document.querySelectorAll('[class*="pm2"]').forEach((element) => {
  4419. // 获取element内部的<a>标签
  4420. const anchor = element.querySelector("a");
  4421. if (anchor) {
  4422. // 解析<a>标签的href属性以获取touid
  4423. const href = anchor.getAttribute("href");
  4424. const urlParams = new URLSearchParams(href);
  4425. const touid = urlParams.get("touid");
  4426.  
  4427. // 确保touid存在
  4428. if (touid) {
  4429. // 创建新的按钮,假设createFastPMButton接受touid作为参数
  4430. const newButton = createFastPMButton(pid, touid);
  4431.  
  4432. // 插入按钮
  4433. if (element.nextSibling) {
  4434. element.parentNode.insertBefore(newButton, element.nextSibling);
  4435. } else {
  4436. element.parentNode.appendChild(newButton);
  4437. }
  4438. }
  4439. }
  4440.  
  4441. // 移除原始元素
  4442. element.remove();
  4443. });
  4444. }
  4445. /**
  4446. * 帖子内容页显示热度
  4447. */
  4448. function appendTitleFromHotImage() {
  4449. const regex = /static\/image\/common\/hot_\d+\.gif/;
  4450. const images = Array.from(document.querySelectorAll("img")).filter((img) =>
  4451. regex.test(img.src)
  4452. );
  4453.  
  4454. // 如果有多张图片,遍历所有符合条件的图片
  4455. images.forEach((image) => {
  4456. const titleContent = image.title; // 提取图片的title内容
  4457.  
  4458. // 获取页面上所有'id="thread_subject"'的元素
  4459. const threadSubjectSpans = document.querySelectorAll("#thread_subject");
  4460. // 遍历所有找到的span元素
  4461. threadSubjectSpans.forEach((threadSubjectSpan) => {
  4462. const uniqueId = `hotTitle-appendTitleFromHotImage`; // 生成基于图片中数字的唯一ID
  4463.  
  4464. if (!threadSubjectSpan.parentNode.querySelector(`#${uniqueId}`)) {
  4465. const newSpan = document.createElement("span"); // 创建新的span元素
  4466. newSpan.id = uniqueId; // 设置新span的ID
  4467. newSpan.textContent = ` [${titleContent}]`; // 设置新span的内容
  4468. newSpan.style.color = `red`;
  4469. threadSubjectSpan.parentNode.insertBefore(
  4470. newSpan,
  4471. threadSubjectSpan.nextSibling
  4472. ); // 在每个'thread_subject'后面插入新的span
  4473. }
  4474. });
  4475. });
  4476. }
  4477.  
  4478. /**
  4479. * 帖子内容页显示购买数量
  4480. */
  4481. async function appendBuyNumber() {
  4482. const divPt = document.getElementById("pt"); // 获取id为'pt'的div
  4483. if (!divPt) {
  4484. return; // 如果没有找到这个div,直接返回
  4485. }
  4486.  
  4487. // 定义需要查找的forum ID
  4488. const forumTexts = ["fid=166", "fid=97", "forum-166", "forum-97"];
  4489. let found = false; // 用于标记是否找到匹配的文本
  4490.  
  4491. // 检查div的文本内容中是否包含任一指定的forum ID
  4492. const textContent = divPt.innerHTML; // 获取div的全部文本内容
  4493. forumTexts.forEach((text) => {
  4494. if (textContent.includes(text)) {
  4495. found = true;
  4496. }
  4497. });
  4498.  
  4499. // 根据结果执行操作
  4500. if (found) {
  4501. var href = window.location.href; // 获取当前页面的URL
  4502. var tid = extractTid(href); // 从URL中获取tid参数
  4503. console.log("当前页面的tid:", tid);
  4504. if (tid) {
  4505. var buyInfo = await getViewpayments(tid); // 用于获取购买信息
  4506. if (buyInfo.state) {
  4507. var dataRowCount = buyInfo.dataRowCount;
  4508.  
  4509. // 获取页面上所有'id="thread_subject"'的元素
  4510. const threadSubjectSpans =
  4511. document.querySelectorAll("#thread_subject");
  4512. // 遍历所有找到的span元素
  4513. threadSubjectSpans.forEach((threadSubjectSpan) => {
  4514. const uniqueId = `buynum-appendBuyNumber`; // 生成基于图片中数字的唯一ID
  4515.  
  4516. if (!threadSubjectSpan.parentNode.querySelector(`#${uniqueId}`)) {
  4517. const newSpan = document.createElement("span"); // 创建新的span元素
  4518. newSpan.id = uniqueId; // 设置新span的ID
  4519. newSpan.textContent = ` [购买${dataRowCount}次]`; // 设置新span的内容
  4520. newSpan.style.color = `red`;
  4521. threadSubjectSpan.parentNode.insertBefore(
  4522. newSpan,
  4523. threadSubjectSpan.nextSibling
  4524. ); // 在每个'thread_subject'后面插入新的span
  4525. }
  4526. });
  4527. }
  4528. }
  4529. }
  4530. }
  4531.  
  4532. // #endregion
  4533.  
  4534. // #region 网站全局功能
  4535.  
  4536. /**
  4537. * 综合区快速发帖
  4538. */
  4539. function PostContent() {
  4540. if (!window.location.href.includes("forum.php?mod=post&action=newthread")) {
  4541. return;
  4542. }
  4543. const link = document.createElement("a");
  4544. link.href =
  4545. "/forum.php?mod=redirect&goto=findpost&ptid=1708826&pid=16039784";
  4546. link.textContent = "发帖须知";
  4547. link.target = "_blank";
  4548. const organizeButton = document.createElement("li");
  4549. organizeButton.className = "a";
  4550. organizeButton.innerHTML =
  4551. '<button id="organizeBtn" type="button">整理</button>';
  4552.  
  4553. const shareButton = document.createElement("li");
  4554. shareButton.className = "a";
  4555. shareButton.innerHTML = '<button id="shareBtn" type="button">自转</button>';
  4556. const ulElement = document.querySelector(".tb.cl.mbw");
  4557. if (ulElement) {
  4558. ulElement.appendChild(link);
  4559. ulElement.appendChild(organizeButton);
  4560. ulElement.appendChild(shareButton);
  4561. } else {
  4562. console.warn("未找到指定的ul元素");
  4563. return;
  4564. }
  4565. var ttttype = "";
  4566. const modalContent = `<div id="organizeModal"style="display:none; position:fixed; z-index:1000; left:50%; top:50%; transform:translate(-50%, -50%); background-color:white; padding:20px; border-radius:10px;"><div><strong>【资源名称】:</strong><input type="text"id="resourceName"/></div><div><strong>【资源类型】:</strong><label><input type="radio"name="resourceType"value="影片"/>影片</label><label><input type="radio"name="resourceType"value="视频"checked/>视频</label><label><input type="radio"name="resourceType"value="动漫"/>动漫</label><label><input type="radio"name="resourceType"value="套图"/>套图</label><label><input type="radio"name="resourceType"value="游戏"/>游戏</label></div><div><strong>【是否有码】:</strong><label><input type="radio"name="censorship"value="有码"/>有码</label><label><input type="radio"name="censorship"value="无码"checked/>无码</label></div><div><strong>【是否水印】:</strong><label><input type="radio"name="watermark"value="有水印"/>有水印</label><label><input type="radio"name="watermark"value="无水印"checked/>无水印</label></div><div><strong>【字幕】:</strong><label><input type="radio"name="subtitle"value="中文字幕"/>中文字幕</label><label><input type="radio"name="subtitle"value="日文字幕"/>日文字幕</label><label><input type="radio"name="subtitle"value="英文字幕"/>英文字幕</label><label><input type="radio"name="subtitle"value="无字幕"checked/>无字幕</label></div><div><strong>【资源大小】:</strong><input type="text"id="resourceSize"placeholder="大小"/><label><input type="radio"name="sizeUnit"value="M"checked/>M</label><label><input type="radio"name="sizeUnit"value="G"/>G</label><label><input type="radio"name="sizeUnit"value="T"/>T</label><br><div><strong>【下载类型】:</strong><label><input type="radio"name="downType"value="115ED2K"checked/>115ED2K</label><label><input type="radio"name="downType"value="BT/磁链"/>BT/磁链</label><label><input type="radio"name="downType"value="ED2K"/>ED2K</label><label><input type="radio"name="downType"value="夸克网盘"/>夸克网盘</label><label><input type="radio"name="downType"value="百度网盘"/>百度网盘</label><label><input type="radio"name="downType"value="PikPak网盘"/>PikPak网盘</label><label><input type="radio"name="downType"value="其它网盘"/>其它网盘</label></div>视频数量:<input type="text"id="videoCount"placeholder="视频数量"/><br>图片数量:<input type="text"id="imageCount"placeholder="图片数量"/><br>配额数量:<input type="text"id="quota"placeholder="配额数量"/></div><div><strong>【资源预览】:</strong></div><div><strong>【资源链接】:</strong><input type="text"id="resourceLink"/></div><button id="insetBtn"type="button">插入</button></div>`;
  4567. document.body.insertAdjacentHTML("beforeend", modalContent);
  4568. document
  4569. .getElementById("organizeBtn")
  4570. .addEventListener("click", function () {
  4571. showModal("整理");
  4572. });
  4573. document.getElementById("shareBtn").addEventListener("click", function () {
  4574. showModal("自转");
  4575. });
  4576. function showModal(param) {
  4577. console.log(param);
  4578. ttttype = param;
  4579. document.getElementById("organizeModal").style.display = "block";
  4580. }
  4581. document.getElementById("insetBtn").addEventListener("click", function () {
  4582. const resourceName = document.getElementById("resourceName").value;
  4583. const resourceType = document.querySelector(
  4584. 'input[name="resourceType"]:checked'
  4585. )?.value;
  4586. const censorship = document.querySelector(
  4587. 'input[name="censorship"]:checked'
  4588. )?.value;
  4589. const watermark = document.querySelector(
  4590. 'input[name="watermark"]:checked'
  4591. )?.value;
  4592. const subtitle = document.querySelector(
  4593. 'input[name="subtitle"]:checked'
  4594. )?.value;
  4595. const resourceLink = document.getElementById("resourceLink").value;
  4596. const downType = document.querySelector(
  4597. 'input[name="downType"]:checked'
  4598. )?.value;
  4599. const resourceSize = document.getElementById("resourceSize").value;
  4600. const sizeUnit = document.querySelector(
  4601. 'input[name="sizeUnit"]:checked'
  4602. ).value;
  4603. const videoCount = document.getElementById("videoCount").value;
  4604. const imageCount = document.getElementById("imageCount").value;
  4605. const quota = document.getElementById("quota").value;
  4606. let resourceSizeStr = resourceSize ? `${resourceSize}${sizeUnit}` : "";
  4607. let videoCountStr = videoCount ? `${videoCount}V` : "";
  4608. let imageCountStr = imageCount ? `${imageCount}P` : "";
  4609. let quotaStr = quota ? `${quota}配额` : "";
  4610. const content = `
  4611. 【资源名称】:${resourceName}<br>
  4612. 【资源类型】:${resourceType}<br>
  4613. 【是否有码】:${censorship} @ ${watermark} @ ${subtitle}<br>
  4614. 【资源大小】:${resourceSizeStr}/${videoCountStr}/${imageCountStr}/${quotaStr}<br>
  4615. 【资源预览】:<br>
  4616. 【资源链接】:<div class="blockcode"><blockquote>${resourceLink}</blockquote></div><br>
  4617. `;
  4618. const iframe = document.querySelector(".area iframe");
  4619. if (iframe && iframe.contentDocument) {
  4620. const body = iframe.contentDocument.body;
  4621. if (body && body.isContentEditable) {
  4622. body.innerHTML = content;
  4623. } else {
  4624. console.warn("在iframe中未找到可编辑的body元素");
  4625. }
  4626. } else {
  4627. console.warn("未找到class为area的div中的iframe");
  4628. }
  4629. const title = `【${ttttype}】【${downType}】${resourceName}【${resourceSizeStr}/${videoCountStr}/${imageCountStr}/${quotaStr}】
  4630. `;
  4631. const subjectInput = document.getElementById("subject");
  4632. if (subjectInput) {
  4633. subjectInput.value = title;
  4634. } else {
  4635. console.warn("未找到ID为'subject'的input元素");
  4636. }
  4637. var selectElement = document.getElementById("typeid");
  4638. if (selectElement) {
  4639. selectElement.setAttribute("selecti", "8");
  4640. } else {
  4641. console.warn("未找到ID为'typeid'的select元素");
  4642. }
  4643. var aElement = document.querySelector(".ftid a#typeid_ctrl");
  4644. if (aElement) {
  4645. aElement.textContent = "情色分享";
  4646. aElement.setAttribute("initialized", "true");
  4647. } else {
  4648. console.warn("未找到对应的a元素");
  4649. }
  4650. document.getElementById("organizeModal").style.display = "none";
  4651. });
  4652. }
  4653.  
  4654. /**
  4655. * 创建挑选女友的按钮
  4656. * @param {Element} buttonContainer - 按钮容器元素
  4657. */
  4658. function createGirlFriendButton(buttonContainer) {
  4659. var girlFriendButton = createButton("girlFriendButton", "挑选女友", () =>
  4660. createPopup()
  4661. );
  4662. buttonContainer.appendChild(girlFriendButton);
  4663. }
  4664.  
  4665. /**
  4666. * 创建广告的按钮
  4667. * @param {Element} buttonContainer - 按钮容器元素
  4668. */
  4669. function createADButton(buttonContainer) {
  4670. var ADButton = createButton("ADButton", "购买邀请码", () =>
  4671. togglePopup("https://ad1.caomeistore.com/")
  4672. );
  4673. buttonContainer.appendChild(ADButton);
  4674. }
  4675. /**
  4676. * 创建广告2的按钮
  4677. * @param {Element} buttonContainer - 按钮容器元素
  4678. */
  4679. function createAD2Button(buttonContainer) {
  4680. var AD2Button = createButton("AD2Button", "机场推荐", () =>
  4681. togglePopup("https://sbairport.com")
  4682. );
  4683. buttonContainer.appendChild(AD2Button);
  4684. }
  4685.  
  4686. /**
  4687. * 挑选女友的style。
  4688. */
  4689.  
  4690. function addGirlFriendStyles() {
  4691. var style = document.createElement("style");
  4692. style.id = "popupStyle_baoguo";
  4693. style.innerHTML = `
  4694. .app_baoguo{width:500px;height:500px;overflow:hidden;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background-color:#fff8f8;border:1px solid #000;box-shadow:0 4px 8px rgba(0,0,0,0.1);z-index:10000}.word-content_baoguo,.cloudword_baoguo,.title_baoguo,.btn-content_baoguo{position:relative;max-width:100%;max-height:100%;overflow:hidden}.word-content_baoguo{position:absolute;left:50%;top:50%;width:100%;z-index:2;transform:translate(-50%,-50%)}.title_baoguo{display:flex;justify-content:center;font-size:40px;font-weight:bold;color:red}.cloudword_baoguo{position:absolute;width:100%;height:100%;z-index:1}.btn-content_baoguo{margin:50px 0;display:flex;justify-content:center}.btn_baoguo{width:140px;height:50px;font-size:16px;background-color:#007BFF;color:white;border:none;border-radius:5px;box-shadow:0 2px 4px rgba(0,0,0,0.2);cursor:pointer;transition:background-color 0.3s,box-shadow 0.3s}@keyframes complexMoveFade_baoguo{0%{opacity:0;transform:scale(0.5) translate(0,0);font-weight:normal}25%{opacity:0.5;transform:scale(0.8) translate(-10px,10px)}50%{opacity:1;transform:scale(1.1) translate(10px,-10px);font-weight:bold}75%{opacity:0.5;transform:scale(0.8) translate(-10px,10px)}100%{opacity:0;transform:scale(0.5) translate(0,0);font-weight:normal}}.text-popup_baoguo{animation:complexMoveFade_baoguo 1s forwards}.text-popup_baoguo{font-size:30px} @media (max-width:600px){.app_baoguo{width:300px;height:500px}}`;
  4695. document.head.appendChild(style);
  4696. }
  4697.  
  4698. /**
  4699. * 挑选女友的script。
  4700. */
  4701. function addGirlFriendScript() {
  4702. var script = document.createElement("script");
  4703. script.id = "popupScript_baoguo";
  4704. script.textContent = `var displayTextElement=document.getElementById("displayText_baoguo");var toggleButton_baoguo=document.getElementById("toggleButton_baoguo");var cloudwordElement=document.getElementById("cloudword_baoguo");var options=["大泽惠","美咲沙耶","石川铃华","早见琉璃","羽田未来","小泉梨菜","二宫沙树","星野明","椎名由奈","青木玲","星艾莉丝","鮎川奈绪","秋川露依","内山遥","香澄果穗","麻田有希","友崎玲","春菜花","神咲诗织","姬咲莉莉亚","AYA","佐藤美沙","天海翼","西田美沙","心有花","相户爱","平井绫","速水百花","小峰由衣","管野静香","香山圣","叶月奈穗","川嶋夏树","长泽筑实","樱井梨花","伊藤青叶","伊东遥","杏树纱奈","七咲枫花","爱川香织","黑泽英里奈","星野飞鸟","原明奈","辻沙耶香","原田明绘","北川绘美","小林爱弓","大泽美加","吉冈美奈","铃木里美","北条麻妃","神谷姬","神河美音","筱惠美","大浦安娜","三浦亚沙妃","ASUKA","泽木树里","周防雪子","波多野结衣","冬月枫","大冢咲","天宫真奈美","原千寻","叶志穗","濑奈凉","相泽唯衣","广濑由奈","小坂惠","翼裕香","叶山润子","绫濑美音","朝日奈明","青空小夏","麻仓忧","木村那美","村上里沙","田中亚弥","泷泽萝拉","花鸟丽","小向美奈子","天衣美津","JULIA","早坂瞳","樱井莉亚","横山美雪","相田纱耶香","青山雪菜","大岛理子","松本麻里奈","纱仓真菜","渡濑晶","若菜光","日向真昼","平泽里菜子","绫波优","小峰日向","羽田爱","水城奈绪","红音萤","新村爱","伊泽千夏","加护范子","长泽梓","乙音奈奈","白咲舞","希美真由","黑木麻衣","爱音真寻","松野由井","和叶美玲","麻美由真","日野雫","爱泽莲","早川濑里奈","铃木茶织","阿立未来","筱原凉","雨宫琴音","初美理音","一条爱美","青木莉子","高原智美","朝河兰","桃子美优","坂田美影","樱心美","范田纱纱","中岛京子","种村美咲","草莓牛奶","天海丽","相崎琴音","神谷美雪","高树圣良","北岛玲","原小雪","朝比奈琉依","水元优奈","松生彩","小日向优","若宫莉那","上原瑞穗","若林树里","爱川美里菜","芹泽直美","唯川纯","黑川绮罗","大桥未久","星崎杏里","幸田李梨","星乃星爱","藤本莉娜","姬野爱","铃香音色","@YOU","青木琳","糸矢芽衣","若叶久留美","妃乃光","新垣圣那","北原多香子","遥惠美","栗林里莉","古都光","水菜丽","岬里沙","爱原翼","加藤莉娜","吉泽明步","濑名步","岛田阳子","夏目奈奈","堀口奈津美","折笠弥生","翔田千里","木下柚花","春咲和津实","卯月麻衣","希志爱野","弘前亮子","松下怜","早乙女露依","赤西凉","桐生樱","晶爱丽","舞咲美娜","北原夏美","明日花绮罗","茉莉花","小林初花","辰巳唯","安西琉菜","月野姬","藤原瞳","叶山丽子","恋小夜","安达有里","橘日向","紫彩乃","星崎未来","麻生岬","滨崎里绪","佐藤江梨花","村上丽奈","蓝山南","青山由衣","木内美保","水朝美树","藤泽美羽","高濑七海","樱田樱","香坂百合","大槻响","大泽佳那","麻川丽","樱木凛","堀咲莉亚","樱朱音","绘色千佳","音羽奏","成濑心美","长谷川理穗","安倍夏树","飞鸟伊央","真白希实","立花美凉","叶不二子","宫川怜","泷泽优奈","立花里子","浅田琪琪","早乙女优","森美咲","原更纱","爱内梨花","野宫凛子","西野翔","爱海一夏","朝香凉","小泉彩","山口玲子","爱田由","明佐奈","爱原理彩","小泉优香","及川奈央","福山沙耶香","前嶋美步","竹内爱","真田春香","美知广子","橘未稀","藤井雪莉","田畑百子","吉崎直绪","爱叶渚","直嶋爱","菅野亚梨沙","秋元美由","莲井志帆","铃木杏里","妃悠爱","小樱沙树","桐岛葵","美优千奈","并木优","藤井彩","南沙也香","前田香织","藤崎里绪","观月雏乃","青山沙希","浅乃晴美","仁科沙也加","石原莉奈","杉浦美由","小森美树","长谷川美红","前田优希","原纱央莉","羽月希","濑户由衣","朝田芭娜娜","石黑京香","麻生希"];var timer=null;var btnText="点击我";toggleButton_baoguo.addEventListener("click",function(){if(btnText==="点击我"||btnText==="再来一次"){startRandomSelection()}else{stopRandomSelection()}});function startRandomSelection(){if(timer)return;timer=setInterval(updateRandomOption,50);btnText="选择";toggleButton_baoguo.textContent=btnText}function stopRandomSelection(){clearInterval(timer);timer=null;btnText="再来一次";toggleButton_baoguo.textContent=btnText;displayTextElement.textContent="今天冲"+displayTextElement.textContent;var floatingTexts=cloudwordElement.querySelectorAll(".text-popup_baoguo");floatingTexts.forEach(function(textElement){textElement.remove()})}function updateRandomOption(){var randomIndex=getRandomNumber(0,options.length-1);displayTextElement.textContent=options[randomIndex]+"!";createFloatingText()}function getRandomNumber(min,max){return Math.floor(Math.random()*(max-min+1))+min}function createFloatingText(){var textElement=document.createElement("span");textElement.className="text-popup_baoguo";textElement.textContent=options[getRandomNumber(0,options.length-1)];var maxWidth=cloudwordElement.clientWidth;var maxHeight=cloudwordElement.clientHeight;textElement.style.left=getRandomNumber(0,maxWidth-20)+"px";textElement.style.top=getRandomNumber(0,maxHeight-20)+"px";textElement.style.position="absolute";textElement.addEventListener("animationend",function(){textElement.remove()});cloudwordElement.appendChild(textElement)}`;
  4705. document.body.appendChild(script);
  4706. }
  4707.  
  4708. /**
  4709. * 挑选女友的弹出窗体。
  4710. */
  4711. function createPopup() {
  4712. var popup = document.createElement("div");
  4713. popup.className = "app_baoguo";
  4714. popup.innerHTML = `<div class="word-content_baoguo"><div class="title_baoguo"><span id="displayText_baoguo">今天冲哪个?</span></div><div class="btn-content_baoguo"><button class="btn_baoguo"id="toggleButton_baoguo">点击我</button></div></div><div class="cloudword_baoguo"id="cloudword_baoguo"></div>`;
  4715. var closeButton = document.createElement("button");
  4716. closeButton.textContent = "X";
  4717. closeButton.style.position = "absolute";
  4718. closeButton.style.top = "5px";
  4719. closeButton.style.right = "5px";
  4720. closeButton.style.zIndex = "100001";
  4721. closeButton.style.padding = "5px 10px";
  4722. closeButton.style.border = "none";
  4723. closeButton.style.borderRadius = "50%";
  4724. closeButton.style.backgroundColor = "#ff4545";
  4725. closeButton.style.color = "white";
  4726. closeButton.style.fontSize = "16px";
  4727. closeButton.style.cursor = "pointer";
  4728. closeButton.style.boxShadow = "0 2px 4px rgba(0, 0, 0, 0.2)";
  4729. closeButton.style.transition = "background-color 0.2s, box-shadow 0.2s";
  4730. closeButton.addEventListener("click", function () {
  4731. stopRandomSelection();
  4732. var popup = document.querySelector(".app_baoguo");
  4733. if (popup) {
  4734. popup.remove();
  4735. }
  4736. var styleElement = document.getElementById("popupStyle_baoguo");
  4737. var scriptElement = document.getElementById("popupScript_baoguo");
  4738. if (styleElement) {
  4739. styleElement.remove();
  4740. }
  4741. if (scriptElement) {
  4742. scriptElement.remove();
  4743. }
  4744. });
  4745. popup.appendChild(closeButton);
  4746. document.body.appendChild(popup);
  4747. addGirlFriendStyles();
  4748. addGirlFriendScript();
  4749. }
  4750. /**
  4751. * 广告的弹出窗体。
  4752. */
  4753.  
  4754. function togglePopup(url) {
  4755. let popup = document.getElementById("myPopupIframe");
  4756. let iframe;
  4757.  
  4758. // 检查弹出窗口是否已存在
  4759. if (!popup) {
  4760. // 创建弹出窗口容器
  4761. popup = document.createElement("div");
  4762. popup.id = "myPopupIframe";
  4763. Object.assign(popup.style, {
  4764. position: "fixed",
  4765. width: "80%",
  4766. height: "80%",
  4767. left: "10%",
  4768. top: "10%",
  4769. zIndex: "10000",
  4770. backgroundColor: "white",
  4771. border: "3px solid black",
  4772. borderRadius: "10px",
  4773. padding: "10px",
  4774. boxSizing: "border-box",
  4775. display: "none",
  4776. boxShadow: "0 4px 8px rgba(0, 0, 0, 0.1)",
  4777. });
  4778.  
  4779. // 创建关闭按钮
  4780. const closeButton = document.createElement("div");
  4781. closeButton.textContent = "关闭";
  4782. Object.assign(closeButton.style, {
  4783. position: "absolute",
  4784. top: "5px",
  4785. right: "10px",
  4786. cursor: "pointer",
  4787. fontSize: "16px",
  4788. fontWeight: "bold",
  4789. });
  4790.  
  4791. closeButton.onclick = function () {
  4792. popup.style.display = "none";
  4793. };
  4794.  
  4795. // 创建 iframe
  4796. iframe = document.createElement("iframe");
  4797. Object.assign(iframe.style, {
  4798. width: "100%",
  4799. height: "calc(100% - 20px)",
  4800. border: "none",
  4801. borderRadius: "8px",
  4802. });
  4803. iframe.id = "popupIframe"; // 给 iframe 设置一个 ID,方便之后访问
  4804.  
  4805. popup.appendChild(closeButton);
  4806. popup.appendChild(iframe);
  4807. document.body.appendChild(popup);
  4808. } else {
  4809. // 如果弹窗已经存在,直接获取 iframe
  4810. iframe = document.getElementById("popupIframe");
  4811. }
  4812.  
  4813. // 设置 iframe 的新 URL 并显示弹窗
  4814. iframe.src = url;
  4815. popup.style.display = "block"; // 显示弹出窗口
  4816. }
  4817.  
  4818. function setMenuButtonPosition(menuButton, container, settings) {
  4819. // 添加按钮到页面以获取其高度
  4820. document.body.appendChild(menuButton);
  4821.  
  4822. const containerRect = settings.menuButtonIsVisible
  4823. ? container.getBoundingClientRect()
  4824. : 100;
  4825.  
  4826. // 设置按钮的顶部位置为容器的顶部位置减去按钮的高度再减去一些间隔
  4827. menuButton.style.top = `${
  4828. containerRect.top - menuButton.offsetHeight - 50
  4829. }px`;
  4830. }
  4831.  
  4832. /**
  4833. * 全站通用的入口方法。为整个站点执行基本操作和应用用户设置。
  4834. *
  4835. * 1. 修改用户勋章显示
  4836. * 2. 添加自定义样式
  4837. * 3. 根据当前页面的URL,选择并执行相应的页面处理逻辑
  4838. * 4. 如果用户登录,尝试执行自动签到操作
  4839. * 5. 将按钮容器附加到页面主体
  4840. *
  4841. * @param {Object} settings - 用户的设置
  4842. */
  4843. async function baseFunction(settings) {
  4844. removeAD();
  4845. if (settings.blockingIndex) {
  4846. removeIndex();
  4847. }
  4848. manipulateMedals(settings); // 修改用户勋章显示
  4849. addStyles(); // 添加自定义样式
  4850. const buttonContainer = createButtonContainer();
  4851. buttonContainer.style.display = settings.menuButtonIsVisible
  4852. ? "flex"
  4853. : "none";
  4854.  
  4855. await delegatePageHandlers(settings, buttonContainer); // 根据URL选择页面处理逻辑
  4856.  
  4857. handleUserSign(buttonContainer); // 执行用户签到逻辑
  4858. blockContentByUsers(settings); //屏蔽用户
  4859.  
  4860. createExchangeRateButton(buttonContainer);
  4861. createGirlFriendButton(buttonContainer);
  4862. createADButton(buttonContainer);
  4863. createAD2Button(buttonContainer);
  4864. document.body.appendChild(buttonContainer); // 将按钮容器附加到页面主体
  4865. PostContent();
  4866. createBaoguoButton(buttonContainer);
  4867. const menuButton = createMenuButton(settings);
  4868. setMenuButtonPosition(menuButton, buttonContainer, settings); // 计算并设置按钮位置
  4869. // 切换容器显示/隐藏
  4870. toggleContainer(menuButton, buttonContainer);
  4871. }
  4872.  
  4873. /**
  4874. * 检查当前页面的URL是否匹配SpacePage的模式。
  4875. * @returns {boolean} 如果匹配则返回true,否则返回false。
  4876. */
  4877. async function delegatePageHandlers(settings, buttonContainer) {
  4878. const isPostPage = () =>
  4879. /forum\.php\?mod=viewthread|\/thread-\d+-\d+-\d+\.html/.test(
  4880. window.location.href
  4881. );
  4882. const isSearchPage = () =>
  4883. /search\.php\?mod=forum/.test(window.location.href);
  4884. const isForumDisplayPage = () =>
  4885. /forum\.php\?mod=forumdisplay|\/forum-\d+-\d+\.html/.test(
  4886. window.location.href
  4887. );
  4888. const isSpacePage = () =>
  4889. /home\.php\?mod=space(.*&&uid=\d+)?.*&do=thread&view=me(.*&from=space)?.*&(type=(reply|thread))?/.test(
  4890. window.location.href
  4891. );
  4892. const isMySpacePage = () =>
  4893. /(forum|home)\.php\?mod=(guide|space|misc)&(view=(hot|digest|new|newthread|sofa|my)|action=showdarkroom|do=favorite)(&type=(thread|reply|postcomment))?/.test(
  4894. window.location.href
  4895. );
  4896. const isMyfavoritePage = () =>
  4897. /home\.php\?mod=space&do=favorite&view=me/.test(window.location.href);
  4898. const isShowdarkroomPage = () =>
  4899. /forum\.php\?mod=misc&action=showdarkroom/.test(window.location.href);
  4900.  
  4901. if (isPostPage()) {
  4902. handlePostPage(settings, buttonContainer);
  4903. } else if (isSearchPage()) {
  4904. handleSearchPage(settings);
  4905. } else if (isForumDisplayPage()) {
  4906. await handleForumDisplayPage(settings, buttonContainer);
  4907. } else if (isSpacePage()) {
  4908. console.log("isSpacePage");
  4909. displayThreadBuyInfoOther(settings);
  4910. initInfiniteScroll("isSpacePage");
  4911. } else if (isMySpacePage()) {
  4912. console.log("isMySpacePage");
  4913. displayThreadBuyInfoOther(settings);
  4914. initInfiniteScroll("isMySpacePage");
  4915. } else if (isMyfavoritePage()) {
  4916. initInfiniteScroll("isMyfavoritePage");
  4917. }
  4918. }
  4919.  
  4920. /**
  4921. * 创建汇率计算按钮
  4922. * @param {Object} settings - 用户的设置
  4923. * @param {Element} buttonContainer - 按钮容器元素
  4924. */
  4925. function createExchangeRateButton(buttonContainer) {
  4926. var exchangeRateButton = createButton(
  4927. "exchangeRateButton",
  4928. "金钱汇率",
  4929. () => createFloatingWindow()
  4930. );
  4931. buttonContainer.appendChild(exchangeRateButton);
  4932. }
  4933.  
  4934. /**
  4935. * 创建保国设置按钮
  4936. * @param {Object} settings - 用户的设置
  4937. * @param {Element} buttonContainer - 按钮容器元素
  4938. */
  4939. function createBaoguoButton(buttonContainer) {
  4940. var baoguoButton = createButton("baoguoButton", "功能设置", () =>
  4941. createSettingsUI(getSettings())
  4942. );
  4943. buttonContainer.appendChild(baoguoButton);
  4944. }
  4945.  
  4946. /**
  4947. * 用户签到处理逻辑。检查用户是否已签到并执行相应操作。
  4948. *
  4949. * 1. 获取用户ID。如果用户未登录,则不执行任何操作。
  4950. * 2. 检查用户今天是否已签到。
  4951. * 3. 根据签到状态,更新签到按钮的文本。
  4952. * 4. 如果用户今天还未签到,尝试自动签到。
  4953. * 5. 将签到按钮添加到指定的按钮容器。
  4954. *
  4955. * @param {HTMLElement} buttonContainer - 存放按钮的容器元素
  4956. */
  4957. async function handleUserSign(buttonContainer) {
  4958. const userid = getUserId(); // 获取用户ID
  4959. if (!userid) return; // 如果用户未登录,结束函数
  4960.  
  4961. // 检查今天是否已经签到
  4962. const lastSignDate = GM_getValue(`lastSignDate_${userid}`, null);
  4963. const today = new Date().toLocaleDateString();
  4964. const hasSignedToday = lastSignDate === today;
  4965.  
  4966. // 更新签到按钮文本
  4967. const signButtonText = hasSignedToday ? "已经签到" : "快去签到";
  4968. const signButton = createButton(
  4969. "signButton",
  4970. signButtonText,
  4971. () => (window.location.href = `${baseURL}/plugin.php?id=dd_sign:index`)
  4972. );
  4973.  
  4974. // 尝试自动签到
  4975. if (!hasSignedToday) {
  4976. const signed = await sign(userid);
  4977. signButton.innerText = signed ? "已经签到" : "快去签到";
  4978. }
  4979.  
  4980. // 添加签到按钮到容器
  4981. buttonContainer.appendChild(signButton);
  4982. }
  4983.  
  4984. /**
  4985. * 移除广告
  4986. */
  4987. async function removeAD() {
  4988. document.querySelectorAll(".show-text.cl").forEach((element) => {
  4989. element.remove();
  4990. });
  4991. const mn_portalelement = document.querySelector("#mn_portal");
  4992. if (mn_portalelement) {
  4993. mn_portalelement.remove();
  4994. }
  4995. const mn_Na5acelement = document.querySelector("#mn_Na5ac");
  4996. if (mn_Na5acelement) {
  4997. mn_Na5acelement.remove();
  4998. }
  4999. const mn_Neaf3element = document.querySelector("#mn_Neaf3");
  5000. if (mn_Neaf3element) {
  5001. mn_Neaf3element.remove();
  5002. }
  5003. const mn_Ne7b9element = document.querySelector("#mn_Ne7b9");
  5004. if (mn_Ne7b9element) {
  5005. mn_Ne7b9element.remove();
  5006. }
  5007. const qmenuelement = document.querySelector("#qmenu");
  5008. if (qmenuelement) {
  5009. qmenuelement.remove();
  5010. }
  5011. }
  5012.  
  5013. /**
  5014. * 移除首页热门
  5015. */
  5016. async function removeIndex() {
  5017. window.addEventListener("load", function () {
  5018. const diyChart = document.querySelector("#diy_chart");
  5019. if (diyChart) {
  5020. diyChart.remove();
  5021. }
  5022. });
  5023. }
  5024.  
  5025. // #endregion
  5026.  
  5027. // #region 持久性设置
  5028.  
  5029. /**
  5030. * 保存用户的设置并执行相应的操作。
  5031. *
  5032. * 1. 获取当前保存的设置。
  5033. * 2. 从页面的UI元素中读取新的设置值。
  5034. * 3. 对某些设置值进行额外处理。
  5035. * 4. 创建一个需要保存的设置对象。
  5036. * 5. 使用GM_setValue存储设置。
  5037. * 6. 根据新的设置值应用更改。
  5038. * 7. 如果某些核心设置已更改,重新加载页面。
  5039. *
  5040. * @param {Object} settings - 用户的设置对象
  5041. */
  5042. function saveSettings(settings) {
  5043. // 获取当前的设置
  5044. const oldSettings = getSettings();
  5045.  
  5046. // 从页面的UI元素中读取设置值
  5047. settings.imageSize = document.getElementById("imageSizeInput").value;
  5048. settings.logoText = document.getElementById("logoTextInput").value;
  5049. settings.titleStyleSize = document.getElementById(
  5050. "titleStyleSizeInput"
  5051. ).value;
  5052. settings.titleStyleWeight = document.getElementById(
  5053. "titleStyleWeightInput"
  5054. ).value;
  5055. settings.tipsText = document.getElementById("tipsTextInput").value;
  5056. settings.showDown = document.getElementById("showDownCheckbox").checked;
  5057. settings.showCopyCode = document.getElementById(
  5058. "showCopyCodeCheckbox"
  5059. ).checked;
  5060. settings.showFastPost = document.getElementById(
  5061. "showFastPostCheckbox"
  5062. ).checked;
  5063. settings.showFastReply = document.getElementById(
  5064. "showFastReplyCheckbox"
  5065. ).checked;
  5066. settings.showQuickGrade = document.getElementById(
  5067. "showQuickGradeCheckbox"
  5068. ).checked;
  5069. settings.showQuickStar = document.getElementById(
  5070. "showQuickStarCheckbox"
  5071. ).checked;
  5072. settings.showClickDouble = document.getElementById(
  5073. "showClickDoubleCheckbox"
  5074. ).checked;
  5075. settings.showViewRatings = document.getElementById(
  5076. "showViewRatingsCheckbox"
  5077. ).checked;
  5078. settings.showPayLog = document.getElementById("showPayLogCheckbox").checked;
  5079. settings.showFastCopy = document.getElementById(
  5080. "showFastCopyCheckbox"
  5081. ).checked;
  5082. settings.blockingIndex = document.getElementById(
  5083. "blockingIndexCheckbox"
  5084. ).checked;
  5085. settings.qiandaoTip = document.getElementById("qiandaoTipCheckbox").checked;
  5086.  
  5087. settings.imageUrl = document.getElementById("imageUrlInput").value;
  5088. settings.displayBlockedTips = document.getElementById(
  5089. "displayBlockedTipsCheckbox"
  5090. ).checked;
  5091. settings.blockedUsers = document
  5092. .getElementById("blockedUsersList")
  5093. .value.split("\n")
  5094. .map((name) => name.trim())
  5095. .filter((user) => user.trim() !== "");
  5096. settings.enableTitleStyle = document.getElementById(
  5097. "enableTitleStyleCheckbox"
  5098. ).checked;
  5099. settings.autoPagination = document.getElementById(
  5100. "autoPaginationCheckbox"
  5101. ).checked;
  5102. settings.blockMedals = getCheckedRadioValue("blockMedals");
  5103. settings.resizeMedals = getCheckedRadioValue("resizeMedals");
  5104. settings.replaceMedals = getCheckedRadioValue("replaceMedals");
  5105. settings.showAvatar = document.getElementById("showAvatarCheckbox").checked;
  5106. settings.displayThreadImages = document.getElementById(
  5107. "displayThreadImagesCheckbox"
  5108. ).checked;
  5109. settings.displayThreadBuyInfo = document.getElementById(
  5110. "displayThreadBuyInfoCheckbox"
  5111. ).checked;
  5112.  
  5113. settings.isShowWatermarkMessage = document.getElementById(
  5114. "isShowWatermarkMessageCheckbox"
  5115. ).checked;
  5116. settings.maxGradeThread = document.getElementById("maxGradeThread").value;
  5117. settings.defaultSwipeToSearch = document.getElementById(
  5118. "defaultSwipeToSearchCheckbox"
  5119. ).checked;
  5120. settings.excludeOptions = [
  5121. ...new Set(
  5122. document
  5123. .getElementById("excludeOptionsTextarea")
  5124. .value.split("\n")
  5125. .map((line) => line.trim())
  5126. .filter((line) => line !== "")
  5127. ),
  5128. ];
  5129. settings.excludePostOptions = [
  5130. ...new Set(
  5131. document
  5132. .getElementById("excludePostOptionsTextarea")
  5133. .value.split("\n")
  5134. .map((line) => line.trim())
  5135. .filter((line) => line !== "")
  5136. ),
  5137. ];
  5138. // 对excludeGroup进行过滤
  5139. settings.excludeGroup = settings.excludeGroup.filter((group) =>
  5140. settings.excludeOptions.includes(group)
  5141. );
  5142.  
  5143. // 创建要保存的设置对象
  5144. const settingsToSave = {
  5145. imageSize: settings.imageSize,
  5146. logoText: settings.logoText,
  5147. tipsText: settings.tipsText,
  5148. imageUrl: settings.imageUrl,
  5149. blockMedals: settings.blockMedals,
  5150. resizeMedals: settings.resizeMedals,
  5151. replaceMedals: settings.replaceMedals,
  5152. displayBlockedTips: settings.displayBlockedTips,
  5153. blockedUsers: settings.blockedUsers,
  5154. enableTitleStyle: settings.enableTitleStyle,
  5155. titleStyleSize: settings.titleStyleSize,
  5156. titleStyleWeight: settings.titleStyleWeight,
  5157. excludeOptions: settings.excludeOptions,
  5158. excludeGroup: settings.excludeGroup,
  5159. autoPagination: settings.autoPagination,
  5160. showAvatar: settings.showAvatar,
  5161. excludePostOptions: settings.excludePostOptions,
  5162. maxGradeThread: settings.maxGradeThread,
  5163. defaultSwipeToSearch: settings.defaultSwipeToSearch,
  5164. displayThreadImages: settings.displayThreadImages,
  5165. displayThreadBuyInfo: settings.displayThreadBuyInfo,
  5166. isShowWatermarkMessage: settings.isShowWatermarkMessage,
  5167. showDown: settings.showDown,
  5168. showCopyCode: settings.showCopyCode,
  5169. showFastPost: settings.showFastPost,
  5170. showFastReply: settings.showFastReply,
  5171. showQuickGrade: settings.showQuickGrade,
  5172. showQuickStar: settings.showQuickStar,
  5173. showClickDouble: settings.showClickDouble,
  5174. showViewRatings: settings.showViewRatings,
  5175. showPayLog: settings.showPayLog,
  5176. showFastCopy: settings.showFastCopy,
  5177. blockingIndex: settings.blockingIndex,
  5178. qiandaoTip: settings.qiandaoTip,
  5179. };
  5180.  
  5181. // 存储设置
  5182. for (let key in settingsToSave) {
  5183. GM_setValue(key, settingsToSave[key]);
  5184. }
  5185.  
  5186. // 根据新的设置值应用更改
  5187. manipulateMedals(settings);
  5188. if (settings.enableTitleStyle) {
  5189. stylePosts(settings);
  5190. } else {
  5191. undoStylePosts();
  5192. }
  5193. showAvatarEvent();
  5194. // 如果核心设置已更改,重新加载页面
  5195.  
  5196. if (
  5197. oldSettings.blockingIndex !== settings.blockingIndex ||
  5198. oldSettings.showFastCopy !== settings.showFastCopy ||
  5199. oldSettings.showViewRatings !== settings.showViewRatings ||
  5200. oldSettings.showPayLog !== settings.showPayLog ||
  5201. oldSettings.showClickDouble !== settings.showClickDouble ||
  5202. oldSettings.showQuickStar !== settings.showQuickStar ||
  5203. oldSettings.showQuickGrade !== settings.showQuickGrade ||
  5204. oldSettings.showFastReply !== settings.showFastReply ||
  5205. oldSettings.showFastPost !== settings.showFastPost ||
  5206. oldSettings.showCopyCode !== settings.showCopyCode ||
  5207. oldSettings.showDown !== settings.showDown ||
  5208. oldSettings.displayBlockedTips !== settings.displayBlockedTips ||
  5209. oldSettings.displayThreadImages !== settings.displayThreadImages ||
  5210. oldSettings.displayThreadBuyInfo !== settings.displayThreadBuyInfo ||
  5211. oldSettings.autoPagination !== settings.autoPagination ||
  5212. oldSettings.blockedUsers.toString() !==
  5213. settings.blockedUsers.toString() ||
  5214. oldSettings.excludeOptions.toString() !==
  5215. settings.excludeOptions.toString() ||
  5216. oldSettings.excludePostOptions.toString() !==
  5217. settings.excludePostOptions.toString() ||
  5218. oldSettings.defaultSwipeToSearch !== settings.defaultSwipeToSearch ||
  5219. settings.replaceMedals === 0 ||
  5220. settings.replaceMedals === 2
  5221. ) {
  5222. location.reload();
  5223. }
  5224. }
  5225. // #endregion
  5226.  
  5227. // #region 高级搜索
  5228.  
  5229. /**
  5230. * 在页面上添加高级搜索功能。
  5231. *
  5232. * 1. 检查页面中是否存在目标元素。
  5233. * 2. 创建一个高级搜索区域并将其附加到页面。
  5234. * 3. 根据传入的设置初始化复选框的状态。
  5235. * 4. 为高级搜索区域的复选框组添加事件监听器。
  5236. *
  5237. * @param {Object} settings - 用户的设置对象
  5238. */
  5239. function addAdvancedSearch(settings) {
  5240. const tlElement = document.querySelector(".tl");
  5241. if (!tlElement) {
  5242. console.error("The .tl element not found!");
  5243. return;
  5244. }
  5245.  
  5246. const advancedSearchDiv = createAdvancedSearchDiv(settings);
  5247. document.body.appendChild(advancedSearchDiv);
  5248.  
  5249. initCheckboxGroupWithSettings(advancedSearchDiv, settings);
  5250. addEventListenerForAdvancedSearch(advancedSearchDiv);
  5251. }
  5252.  
  5253. /**
  5254. * 创建一个高级搜索区域(div)。
  5255. * 区域中包含复选框组,允许用户选择不同的搜索选项。
  5256. *
  5257. * @param {Object} settings - 用户的设置对象
  5258. * @param {Array} TIDOptions - 板块选项,默认值为DEFAULT_TID_OPTIONS
  5259. * @returns {HTMLElement} - 创建的div元素
  5260. */
  5261. function createAdvancedSearchDiv(settings, TIDOptions = DEFAULT_TID_OPTIONS) {
  5262. const advancedSearchDiv = document.createElement("div");
  5263. const excludeOptions = settings.excludeOptions || [];
  5264. const excludeOptionsFormatted = excludeOptions.map((option) => ({
  5265. label: option,
  5266. value: option,
  5267. }));
  5268.  
  5269. advancedSearchDiv.appendChild(
  5270. createCheckboxGroup("excludeGroup", "排除关键字", excludeOptionsFormatted)
  5271. );
  5272. advancedSearchDiv.appendChild(
  5273. createCheckboxGroup("TIDGroup", "只看板块", TIDOptions)
  5274. );
  5275.  
  5276. // 添加样式类
  5277. advancedSearchDiv.classList.add("advanced-search");
  5278.  
  5279. return advancedSearchDiv;
  5280. }
  5281.  
  5282. /**
  5283. * 根据传入的设置初始化复选框的状态。
  5284. *
  5285. * @param {HTMLElement} div - 包含复选框组的div元素
  5286. * @param {Object} settings - 用户的设置对象
  5287. */
  5288. function initCheckboxGroupWithSettings(div, settings) {
  5289. const setCheckboxes = (group, values) => {
  5290. values.forEach((value) => {
  5291. const checkbox = div.querySelector(`#${group} input[value="${value}"]`);
  5292. if (checkbox) checkbox.checked = true;
  5293. });
  5294. };
  5295.  
  5296. setCheckboxes("excludeGroup", settings.excludeGroup);
  5297. setCheckboxes("TIDGroup", settings.TIDGroup);
  5298. }
  5299.  
  5300. /**
  5301. * 为高级搜索区域的复选框组添加事件监听器。
  5302. * 当用户更改复选框的状态时,会更新和保存设置。
  5303. *
  5304. * @param {HTMLElement} div - 包含复选框组的div元素
  5305. */
  5306. function addEventListenerForAdvancedSearch(div) {
  5307. div.addEventListener("change", function (e) {
  5308. const handleCheckboxChange = (group) => {
  5309. if (e.target.closest(`#${group}`)) {
  5310. const selectedValues = [
  5311. ...document.querySelectorAll(`#${group} input:checked`),
  5312. ].map((input) => input.value);
  5313. GM_setValue(group, JSON.stringify(selectedValues));
  5314. }
  5315. };
  5316.  
  5317. handleCheckboxChange("excludeGroup");
  5318. handleCheckboxChange("TIDGroup");
  5319. filterElementsBasedOnSettings(getSettings());
  5320. });
  5321. }
  5322.  
  5323. /**
  5324. * 替换搜索页面的logo。
  5325. */
  5326. function replaceImageSrc() {
  5327. // 等待页面完全加载
  5328. window.addEventListener("load", function () {
  5329. // 查找所有包含旧图片路径的img元素
  5330. document
  5331. .querySelectorAll('img[src="static/image/common/logo_sc_s.png"]')
  5332. .forEach(function (img) {
  5333. // 替换为新的图片路径
  5334. img.src = "static/image/common/logo.png";
  5335. });
  5336. });
  5337.  
  5338. // document.querySelectorAll('img[src="static/image/common/logo_sc_s.png"]').forEach(function (img) {
  5339. // // 替换为新的图片路径
  5340. // img.src = "static/image/common/logo.png";
  5341. // });
  5342. }
  5343.  
  5344. // #endregion
  5345.  
  5346. /**
  5347. * 主程序执行函数。
  5348. *
  5349. * 1. 获取用户的设置。
  5350. * 2. 检查是否需要进行更新。
  5351. * 3. 执行基础功能函数。
  5352. */
  5353. async function main() {
  5354. const settings = getSettings();
  5355.  
  5356. // 如果距离上次检查更新已经超过24小时,则检查更新
  5357. const lastCheckedUpdate = settings.lastCheckedUpdate;
  5358. const oneDayInMillis = 24 * 60 * 60 * 1000;
  5359. if (Date.now() - lastCheckedUpdate > oneDayInMillis) {
  5360. checkForUpdates();
  5361. }
  5362.  
  5363. await baseFunction(settings);
  5364. }
  5365.  
  5366. // 启动主程序
  5367. await main();
  5368. })();