javdb auto open

增加页面顶部底部按钮和一键下种按钮

От 24.01.2024. Виж последната версия.

  1. // ==UserScript==
  2. // @name javdb auto open
  3. // @namespace websiteEnhancement
  4. // @author jimmly
  5. // @version 2024.1.24
  6. // @description 增加页面顶部底部按钮和一键下种按钮
  7. // @create 2023-9-21
  8. // @include *javdb*
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM.getValue
  12. // @grant GM.setValue
  13. // @license MIT
  14. // @run-at document-idle
  15. // ==/UserScript==
  16.  
  17. /**
  18. * source of GM_config https://raw.githubusercontent.com/niubilityfrontend/GM_config/v20230928/gm_config.js
  19. * @typedef { import('jquery') } $
  20. * @typedef { import('jQuery') } jQuery
  21. */;
  22. ; (async function (loadJS) {
  23. loadJS("https://update.greasyfork.org/scripts/483173/GM_config_cnjames.js")
  24. .then(v => loadJS("https://update.sleazyfork.org/scripts/476583/common_libs_of_array.js"))
  25. .then(v => {
  26. withJQuery(function ($, win) {
  27.  
  28. let w = 40, h = 40;
  29. addStyle(`
  30. a:link{color:green;}
  31. a:hover{color:red;}
  32. a:active{color:yellow;}
  33. a:visited{color:orange;}
  34. .btn1 {
  35. opacity:0.8;-moz-transition-duration:0.2s;-webkit-transition-duration:0.2s;
  36. padding:1px; margin-top:1px;
  37. font-size: 10; text-align: center; vertical-align: middle; line-height:${h}px;
  38. border-radius:5px 5px 5px 5px;cursor:pointer; left:0px;z-index:9999;
  39. background:white;
  40. width:${w}px;height:${h}px;
  41. }
  42. `);
  43. let container = $(document.createElement('div')).css({
  44. 'cssText': `position:fixed;top:15%;width:${w}px;height:${h * 7}px;left:0px;z-index:9999`
  45. });
  46.  
  47. if (window.location.href.indexOf('tags') == -1) {
  48. //下载按钮
  49. let downloadBtn = $(document.createElement('div')).text('下載').appendTo(container)
  50. .click(function () {
  51. let url = $(".t_attachlist > dt > a:eq(1)").prop('href');
  52. let filename = $("div.mainbox.viewthread>h1").text().trim() + '.torrent';
  53. console.log(filename)
  54. $.ajax({
  55. url,
  56. success: function (result, status, xhr) {
  57. let alink = document.createElement('a');
  58. alink.download = filename;
  59. alink.href = $(result).find("#downloadBtn").prop('href');
  60. document.body.appendChild(alink);
  61. alink.click();
  62. },
  63. error: function (xhr, status, error) {
  64. console.log(status, error)
  65. }
  66. });
  67. });
  68.  
  69. $(document).keydown(function (event) {
  70. let e = event || window.event;
  71. let k = e.keyCode || e.which;
  72. if (k === 16) {
  73. // isCtrl = true;
  74. startBtn.click()
  75. } else if (k === 38) { //up
  76. event.stopPropagation()
  77. slowBtn.click()
  78.  
  79. } else if (k === 40) {//down
  80. event.stopPropagation()
  81. //fastBtn.click()
  82. }
  83. })
  84. // $(window).blur(function () {
  85. // clearTimeout(win.___t)
  86. // win.___t = 0
  87. // }).focus(function () {
  88. // win.___func();
  89. // })
  90.  
  91. win.__wait = 900
  92. win.__step = 100;
  93. win.___func = function () {
  94. win.______h = $(document).scrollTop() + win.__step;
  95. if (win.______h >= $(document).height() - $(window).height()) {
  96. clearTimeout(win.___t)
  97. // win.___t = setTimeout(win.___func, 30000)
  98. } else {
  99. $(document).scrollTop(win.______h);
  100. win.___t = setTimeout(win.___func, win.__wait)
  101. }
  102. };
  103. }
  104. else {
  105. $('tr').hover(
  106. function () {
  107. $(this).find('*').css("background-color", "#9AAAC7")
  108. }, function () {
  109. $(this).find('*').css("background-color", '');
  110. });
  111. }
  112.  
  113. //最顶按钮
  114. let
  115. toTopBtn = $(document.createElement('div')).text('Top').appendTo(container)
  116. .click(function () {
  117. window.scrollTo(0, 0);
  118. }),
  119. //最低按钮
  120. toBottomBtn = $(document.createElement('div')).text('Bottom').appendTo(container)
  121. .click(function () {
  122. window.scrollTo(0, document.body.scrollHeight);
  123. }),
  124. //加速
  125. fastBtn = $(document.createElement('div')).text('加速').appendTo(container)
  126. .click(function () {
  127. if (win.__wait > 5) {
  128. win.__wait = win.__wait / 1.5
  129. } else {
  130. win.__wait = 5
  131. }
  132. }),
  133. startBtn = $(document.createElement('div')).text('啓停').appendTo(container)
  134. .click(function () {
  135. if (!!!win.___t) {
  136. win.___func();
  137. } else {
  138. clearTimeout(win.___t)
  139. win.___t = 0
  140. }
  141. }),
  142. slowBtn = $(document.createElement('div')).text('減速').appendTo(container)
  143. .click(function () {
  144. win.__wait *= 1.5
  145. }),
  146. setBtn = $(document.createElement('div')).attr('id', 'btnSet').text('設置').appendTo(container)
  147. .click(function () {
  148.  
  149. });
  150. container
  151. .find('div')
  152. .addClass('btn1')
  153. .hover(function (e) {
  154. let o = $(this)
  155. o.data('old_opacity', o.css('opacity'))
  156. .data('old_border', o.css('border'))
  157. o.css('opacity', 1).css('border', '1px solid black')
  158. }, function (e) {
  159. let o = $(this)
  160. o.css('opacity', o.data('old_opacity')).css('border', o.data('old_border'))
  161. })
  162. container.appendTo('body');
  163.  
  164. autoFind(() => window.location.href.indexOf('tags') > -1, 'javdb', '.item a', el => el.attr('title'), $, setBtn);
  165.  
  166. })
  167. })
  168.  
  169. })(function (FILE_URL, async = true) {
  170. return new Promise((resolve, reject) => {
  171. let scriptEle = document.createElement("script");
  172. scriptEle.setAttribute("src", FILE_URL);
  173. scriptEle.setAttribute("type", "text/javascript");
  174. scriptEle.setAttribute("async", async);
  175. // success event
  176. scriptEle.addEventListener("load", () => {
  177. resolve(FILE_URL)
  178. });
  179. // error event
  180. scriptEle.addEventListener("error", (ev) => {
  181. reject(ev);
  182. });
  183. if (document.currentScript)
  184. document.currentScript.insertBefore(scriptEle)
  185. else
  186. (document.head || document.getElementsByTagName('head')[0]).appendChild(scriptEle);
  187. })
  188. });