通用_加载更多

通过 Shift 加左右方向键实现快速页面切换,配置为加载更多模式还可全自动操作。

  1. // ==UserScript==
  2. // @name 通用_加载更多
  3. // @name:zh-CN 通用_加载更多
  4. // @name:en-US Uni_More Message
  5. // @description 通过 Shift 加左右方向键实现快速页面切换,配置为加载更多模式还可全自动操作。
  6. // @version 2.0.4
  7. // @author LiuliPack
  8. // @license WTFPL
  9. // @namespace https://gitlab.com/LiuliPack/UserScript
  10. // @match *://*/*
  11. // @grant GM_log
  12. // @run-at document-idle
  13. // ==/UserScript==
  14.  
  15. /* 参数示范 / Config demo
  16. {
  17. "remark": "备注信息 || 适配站点_页面描述 || 模板(适配站点)_页面描述",
  18. ...
  19. "match": ["元素选取器", "元素文本", "正则匹配路径、参数和段落"],
  20. "match": ["元素选取器", "正则匹配路径、参数和段落"],
  21. "match": ["元素选取器", "元素文本"],
  22. "match": ["正则匹配路径和参数"],
  23. "match": ["元素选取器"],
  24. ...
  25. "ele": {
  26. "more": "加载更多",
  27. "prev": "上一页",
  28. "next": "下一页"
  29. }
  30. },
  31. {
  32. "remark": "Remark info || Adapted site_Page description || Template(Adapted site)_Page description",
  33. ...
  34. "match": ["Element Selector", "Element Text", "RegExp match path, query and fragment"],
  35. "match": ["Element Selector", "RegExp match path, query and fragment"],
  36. "match": ["Element Selector", "Element Text"],
  37. "match": ["RegExp match domain and path"],
  38. "match": ["Element Selector"],
  39. ...
  40. "ele": {
  41. "more": "Load More",
  42. "prev": "Prev page",
  43. "next": "Next page"
  44. }
  45. },
  46. */
  47.  
  48. 'use strict';
  49.  
  50. // 定义配置(cfg)变量,元素快捷选择($(元素定位符))函数
  51. let cfg = [
  52. {
  53. "remark": "Discuz!_全站",
  54. "match": ["#footer .borders > p:nth-child(2) a:nth-child(1)", "Discuz!", "^/(thread|forum|u|read).php$"],
  55. "ele": {
  56. "prev": "#fd_page_bottom .prev, .pgs .prev, .pg .pgb a",
  57. "next": "#fd_page_bottom .nxt, .pgs .nxt, .pg > a:last-child"
  58. }
  59. },
  60. {
  61. "remark": "PHPWind_全站",
  62. "match": ["#footer #windspend + br + a", "Pu!mdHd"],
  63. "ele": {
  64. "prev": () => {
  65. // 定义元素(ele)
  66. let ele = $(".pages li b");
  67.  
  68. // 如果存在且非当前页面,就点击
  69. try {
  70. ele = ele.parentNode.previousSibling.childNodes[0];
  71. ele.href !== location.href ? ele.click() : '' ;
  72. }catch {}
  73. },
  74. "next": () => {
  75. // 定义元素(ele)
  76. let ele = $(".pages li b");
  77.  
  78. // 如果存在且非当前页面,就点击
  79. try {
  80. ele = ele.parentNode.nextSibling.childNodes[0];
  81. ele.href !== location.href ? ele.click() : '' ;
  82. }catch {}
  83. }
  84. }
  85. },
  86. {
  87. "remark": "Flarum_帖子列表",
  88. "match": [".DiscussionList-loadMore button", "^/(t/.{2,})?$"],
  89. "ele": {
  90. "more": ".DiscussionList-loadMore button"
  91. }
  92. },
  93. {
  94. "remark": "WordPress-TwentyEleven 主题_投稿索引",
  95. "match": ["#page > #branding > hgroup", "^/(wp/)?(.+.html|(author|category|tag)/.+)?(page/[0-9].)?"],
  96. "ele": {
  97. "prev": ".wp-pagenavi .previouspostslink, #nav-below .nav-next a",
  98. "next": ".wp-pagenavi .nextpostslink, #nav-below, .nav-previous a"
  99. }
  100. },
  101. {
  102. "remark": "WordPress-TwentyFifteen 主题_投稿索引",
  103. "match": ["#page > #sidebar > #masthead", "^/(archives/(author|category|tag)/.+|search/.+)?(page/[0-9]+)?$"],
  104. "ele": {
  105. "prev": () => {
  106. // 定义元素(ele)
  107. let ele = $(".wp-pagenavi[role='navigation'] .current");
  108.  
  109. // 如果存在且元素节点不是文本,就点击
  110. try {
  111. ele = ele.previousSibling;
  112. ele.nodeName !== "#text" ? ele.click() : '' ;
  113. }catch {}
  114. },
  115. "next": ".wp-pagenavi[role='navigation'] .current + a:not(.sfwppa-last)"
  116. }
  117. },
  118. {
  119. "remark": "WordPress_INN-AO 主题_全站",
  120. "match": ["#inn-user-menu__container", "^/((bbs|tag)/.+|search/-)$"],
  121. "ele": {
  122. "prev": ".poi-pager .poi-pager__item_prev",
  123. "next": ".poi-pager .poi-pager__item_next"
  124. }
  125. },
  126. {
  127. "remark": "WordPress_GridMe 主题_全站",
  128. "match": [".gridme-credit", "Design by ThemesDNA.com", "^/((category|archives/author|tag)/.+)?(page/[0-9].)?"],
  129. "ele": {
  130. "prev": ".nav-links .prev",
  131. "next": ".nav-links .next"
  132. }
  133. },
  134. {
  135. "remark": "VNDB_索引",
  136. "match": ["^vndb.org/.+$"],
  137. "ele": {
  138. "prev": ".maintabs .browsetabs li:first-child a[rel='prev']",
  139. "next": ".maintabs .browsetabs li:last-child a[rel='next']"
  140. }
  141. },
  142. {
  143. "remark": "Nyaa_索引",
  144. "match": ["^(sukebei.)?nyaa.si/$"],
  145. "ele": {
  146. "prev": ".pagination a[rel='prev']",
  147. "next": ".pagination a[rel='next']"
  148. }
  149. },
  150. {
  151. "remark": "琉璃神社-社区_用户动态和搜索",
  152. "match": ["^www.hacg.mom/wp/(bbs|participant/.{2,14}/paged/[0-9]{0,})?$"],
  153. "ele": {
  154. "prev": ".wpf-navi .wpf-prev-button",
  155. "next": ".wpf-navi .wpf-next-button"
  156. }
  157. },
  158. {
  159. "remark": "琉璃神社-社区_帖子列表",
  160. "match": ["^www.hacg.mom/wp/bbs$"],
  161. "ele": {
  162. "more": ".wpf-more-topics a"
  163. }
  164. },
  165. {
  166. "remark": "DuckDuckGo, 鸭鸭溜_搜索页",
  167. "match": ["^duckduckgo.com/$"],
  168. "ele": {
  169. "more": "[id^='rld-'] a"
  170. }
  171. },
  172. {
  173. "remark": "Yandex, 央捷科斯_搜索页",
  174. "match": ["^yandex.(com|ru)/search/$"],
  175. "ele": {
  176. "prev": () => {
  177. // 定义元素(ele)
  178. let ele = $("#pager__header_id + [role='list'] span");
  179.  
  180. // 如果存在,就点击
  181. try {
  182. ele = ele.previousSibling;
  183. ele ? ele.click() : '' ;
  184. }catch {}
  185. },
  186. "next": "#pager__header_id + [role='list'] a:last-child"
  187. }
  188. },
  189. {
  190. "remark": "Google, 谷歌_搜索页",
  191. "match": ["^www.google.com/search$"],
  192. "ele": {
  193. "prev": "[role='navigation'] tr td:first-child a",
  194. "next": "[role='navigation'] tr td:last-child a"
  195. }
  196. },
  197. {
  198. "remark": "Bing, 必应_搜索页",
  199. "match": ["^(www|cn).bing.com/search$"],
  200. "ele": {
  201. "prev": ".b_pag ul li:first-child a:not(.sb_inactP)",
  202. "next": ".b_pag ul li:last-child a"
  203. }
  204. },
  205. {
  206. "remark": "哔哩哔哩_搜索",
  207. "match": ["^search.bilibili.com/"],
  208. "ele": {
  209. "prev": ".vui_pagenation button:first-child:not(.vui_button--disabled)",
  210. "next": ".vui_pagenation button:last-child:not(.vui_button--disabled)"
  211. }
  212. },
  213. {
  214. "remark": "哔哩哔哩_UP 主视频清单",
  215. "match": ["^space.bilibili.com/[0-9]+/video$"],
  216. "ele": {
  217. "prev": ".be-pager .be-pager-prev",
  218. "next": ".be-pager .be-pager-next"
  219. }
  220. },
  221. {
  222. "remark": "極彩花夢_投稿索引",
  223. "match": ["^kyokusai.com/(moe/)?((category|author)/.+)?(page/[0-9].)?$"],
  224. "ele": {
  225. "prev": ".pagination .page-item [aria-label^='Previous']",
  226. "next": ".pagination .page-item [aria-label^='Next']"
  227. }
  228. },
  229. {
  230. "remark": "hanime.tv_播放清单",
  231. "match": ["^hanime.tv/playlists/*"],
  232. "ele": {
  233. "more": ".panel__content > .btn"
  234. }
  235. },
  236. {
  237. "remark": "hanime.tv_搜索",
  238. "match": ["^hanime.tv/search$"],
  239. "ele": {
  240. "prev": ".pagination li:first-child button:not(.pagination__navigation--disabled)",
  241. "next": ".pagination li:last-child button:not(.pagination__navigation--disabled)"
  242. }
  243. },
  244. {
  245. "remark": "(Greasy|SleazyFork)Fork_搜索",
  246. "match": ["#site-name-text a", "Greasy Fork镜像", "^/[a-zA-Z-]{1,5}/scripts(/libraries|/by-site/*)?"],
  247. "ele": {
  248. "prev": ".pagination .previous_page",
  249. "next": ".pagination .next_page"
  250. }
  251. },
  252. {
  253. "remark": "FreeBuf_投稿索引",
  254. "match": [".more-view .btn-text", "\n 查看更多内容\n ", "/"],
  255. "ele": {
  256. "more": ".more-view .btn-text"
  257. }
  258. },
  259. {
  260. "remark": "WinSite_清单",
  261. "match": ["^www.winsite.com/[a-zA-Z-]+(/[a-zA-Z-]+)?/([0-9]+/)?$"],
  262. "ele": {
  263. "prev": "#main div[style='float: left;'] a:first-child",
  264. //"next": "#main div[style='float: left;'] a:last-of-type"
  265. "next": () => {
  266. // 定义元素(ele)变量。
  267. let ele = $("#main div[style='float: left;'] a:last-of-type");
  268.  
  269. // 元素文本是“>”,就点击。
  270. if(ele.textContent === '>') {
  271. ele.click();
  272. }
  273. },
  274. }
  275. },
  276. ],
  277. $ = ele => document.querySelector(ele);
  278.  
  279. // 等待 .3 秒
  280. setTimeout(() => {
  281. // 遍历配置
  282. cfg.forEach((data) => {
  283. // 判断是否匹配
  284. if(data.match.length === 3 && $(data.match[0]) && $(data.match[0]).textContent === data.match[1] && new RegExp(data.match[2]).test(location.href.split(location.host)[1]) ||data.match.length === 2 && data.match[1][0] !== "^" && $(data.match[0]) && $(data.match[0]).textContent === data.match[1] || data.match.length === 2 && data.match[1][0] === "^" && $(data.match[0]) && new RegExp(data.match[1]).test(location.href.split(location.host)[1]) || data.match.length === 1 && data.match[0][0] === "^" && new RegExp(data.match[0]).test(location.host + location.pathname) || data.match.length === 1 && data.match[0][0] !== "^" && $(data.match[0])) {
  285. // 展示匹配配置
  286. GM_log(`加载更多 > 已载入配置“${data.remark}”。`)
  287. // 如果“更多”按钮选择器存在
  288. if(data.ele.more !== undefined) {
  289. // 监听页面滚动
  290. addEventListener('scroll', () => {
  291. // 定义页面滚动位置(Pos)变量
  292. let Pos = document.documentElement.scrollTop / (document.documentElement.scrollHeight - document.documentElement.clientHeight);
  293.  
  294. // 如果页面滚动位置大于 .75 且存在对应元素,点击加载更多元素
  295. if(Pos > .75 && $(data.ele.more)) {
  296. $(data.ele.more).click();
  297. }
  298. });
  299. }else {
  300. // 否则,监听按键按下
  301. addEventListener('keydown', (e) => {
  302. // 定义按下按键(Key)和按下转换键(Shift)变量
  303. let Key = e.key,
  304. Shift = e.shiftKey;
  305.  
  306. if(Shift && Key === 'ArrowRight') {
  307. // 阻止默认事件
  308. e.preventDefault();
  309. // 如果按下右方向键就,尝试执行自定义函数,失败的话就尝试点击元素
  310. try {
  311. data.ele.next();
  312. } catch {
  313. $(data.ele.next) ? $(data.ele.next).click() : '' ;
  314. }
  315. }else if(Shift && Key === 'ArrowLeft') {
  316. // 阻止默认事件
  317. e.preventDefault();
  318. // 如果按下左方向键就,尝试执行自定义函数,失败的话就尝试点击元素
  319. try {
  320. data.ele.prev();
  321. } catch(e) {
  322. $(data.ele.prev) ? $(data.ele.prev).click() : '' ;
  323. }
  324. };
  325. });
  326. }
  327. }
  328. })
  329. }, 300);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址