javdb auto open

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

Устаревшая версия за 21.09.2023. Перейдите к последней версии.

  1. // ==UserScript==
  2. // @name javdb auto open
  3. // @namespace javdb enhancement
  4. // @author jimmly
  5. // @version 0.3.3
  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. // @require https://openuserjs.org/src/libs/sizzle/GM_config.min.js
  14. // @license MIT
  15. // @run-at document-idle
  16. // ==/UserScript==
  17.  
  18. /**
  19. * @typedef { import('jquery') } $
  20. * @typedef { import('jQuery') } jQuery
  21. */
  22. (async withJQuery => {
  23.  
  24. let conf = new GM_config({
  25. id: 'GM_config_javdb',
  26. title: 'Configurable Options Script',
  27. fields: {
  28. 'asdf': {
  29. 'label': 'Search keys',
  30. 'type': 'textarea',
  31. 'default': '萝莉;奴隶;奴隸;调教;調教;拘束;軟體;软体;痙;攣;拘;束;固定;sm;白虎,捆绑,捆綁;束縛;束缚,母狗;'
  32. },
  33. },
  34. })
  35.  
  36.  
  37. var addStyle = function (css) {
  38. var s = document.createElement('style');
  39. s.appendChild(document.createTextNode(css));
  40. document.getElementsByTagName('head')[0].appendChild(s);
  41. }
  42. addStyle(`
  43. a:link{color:green;}
  44. a:hover{color:red;}
  45. a:active{color:yellow;}
  46. a:visited{color:orange;}
  47. .btn1 {
  48. opacity:0.3;-moz-transition-duration:0.2s;-webkit-transition-duration:0.2s;
  49. padding:1px;background:white;font-size: 10; text-align: center; vertical-align: middle;
  50. border-radius:5px 5px 5px 5px;cursor:pointer; left:0px;z-index:9999;
  51. background:white;
  52. width:40px;height:40px;line-height:40px;
  53. }
  54. `);
  55. // 创建超链接,不会被拦截
  56. function createSuperLabel(url, id) {
  57. if (!id)
  58. id = url;
  59. // 防止反复添加
  60. if (!document.getElementById(id) && !localStorage[id]) {
  61. let tmpLink = document.createElement("a");
  62. localStorage[id] = true
  63. tmpLink.setAttribute("href", url);
  64. tmpLink.setAttribute("target", "_blank");
  65. tmpLink.setAttribute("id", id);
  66. document.body.appendChild(tmpLink);
  67. tmpLink.click();
  68. return true
  69. }
  70. return false;
  71. }
  72. withJQuery(/** @param { $ } $ */function ($, win) {
  73. //$('item a').removeAttr('style')
  74. new Promise((resolve, reject) => resolve(conf.get('asdf')))
  75. .then(conf => {
  76. console.log('config value of keys', conf)
  77. return (conf.toString()).split(/;|;|,|,/i)
  78. })
  79. .then(keys => {
  80. if (window.location.href.indexOf('tags') > -1)
  81. $('.item a').each((i, element) => {
  82. let el = $(element)
  83. $.each(keys, (inex, key) => {
  84. if (key && el.attr('title').toLowerCase().indexOf(key.toLowerCase()) > -1) {
  85.  
  86. console.log(key, createSuperLabel(el.prop('href')), el.prop('href'))
  87.  
  88. return false;
  89. }
  90. })
  91.  
  92. });
  93. })
  94.  
  95. let container = $(document.createElement('div')).css({
  96. 'cssText': `position:fixed;top:15%;width:40px;height:240px;left:0px;z-index:9999`
  97. });
  98. let topref = 80;
  99. //最顶按钮
  100. let toTopBtn = $(document.createElement('div')).text('Top');
  101. toTopBtn.click(function () {
  102. window.scrollTo(0, 0);
  103. });
  104.  
  105. container.append(toTopBtn).append($('<br />'));
  106. if (window.location.href.indexOf("thread") == -1) {
  107. //下载按钮
  108. let downloadBtn = $(document.createElement('div')).text('Lod');
  109. downloadBtn.click(function () {
  110. let url = $(".t_attachlist > dt > a:eq(1)").prop('href');
  111. let filename = $("div.mainbox.viewthread>h1").text().trim() + '.torrent';
  112. console.log(filename)
  113. $.ajax({
  114. url,
  115. success: function (result, status, xhr) {
  116. let alink = document.createElement('a');
  117. alink.download = filename;
  118. alink.href = $(result).find("#downloadBtn").prop('href');
  119. document.body.appendChild(alink);
  120. alink.click();
  121. },
  122. error: function (xhr, status, error) {
  123. console.log(status, error)
  124. }
  125. });
  126. });
  127. container.append(downloadBtn).append($('<br />'));
  128.  
  129. }
  130. else {
  131. $('tr').hover(function () {
  132. // $(this).find('*').each(function (item) {
  133. // $(this).data('oldcolor', $(this).css("background-color"))
  134. // })
  135. $(this).find('*').css("background-color", "#9AAAC7")
  136. },
  137. function () {
  138. $(this).find('*').css("background-color", '');
  139. });
  140. }
  141. //最低按钮
  142.  
  143. let toBottomBtn = $(document.createElement('div')).text('Bot');;
  144.  
  145. toBottomBtn.click(function () {
  146. window.scrollTo(0, document.body.scrollHeight);
  147. });
  148. container.append(toBottomBtn).append($('<br />'));
  149.  
  150. let fastBtn = $(document.createElement('div')).text('Set'),
  151. middleBtn = $(document.createElement('div')).text('Sta'),
  152. slowBtn = $(document.createElement('div')).text('Low');
  153. container.append(fastBtn).append($('<br />'))
  154. .append(middleBtn).append($('<br />'))
  155. .append(slowBtn).append($('<br />'))
  156.  
  157. container.find('div')
  158. .addClass('btn1')
  159. .hover(
  160. function (item) {
  161. $(this).css('opacity', 1).css('border', '1px solid black')
  162. }, function (item) {
  163. $(this).css('opacity', 0.3).css('border', 'none')
  164. })
  165.  
  166.  
  167. win.__wait = 900
  168. win.__step = 100;
  169.  
  170. fastBtn.click(function () {
  171. conf.open();
  172. // if (win.__wait > 5) {
  173. // win.__wait = win.__wait / 1.5
  174. // } else {
  175. // win.__wait = 5
  176. // }
  177.  
  178. });
  179. slowBtn.click(function () { win.__wait *= 1.5 });
  180. win.___func = function () {
  181. win.______h = $(document).scrollTop() + win.__step;
  182. if (win.______h >= $(document).height() - $(window).height()) {
  183. clearTimeout(win.___t)
  184. // win.___t = setTimeout(win.___func, 30000)
  185. } else {
  186. $(document).scrollTop(win.______h);
  187. win.___t = setTimeout(win.___func, win.__wait)
  188. }
  189. };
  190. $(document).keydown(function (event) {
  191. let e = event || window.event;
  192. let k = e.keyCode || e.which;
  193. if (k === 16) {
  194. // isCtrl = true;
  195. middleBtn.click()
  196. } else if (k === 38) { //up
  197. event.stopPropagation()
  198. slowBtn.click()
  199.  
  200. } else if (k === 40) {//down
  201. event.stopPropagation()
  202. //fastBtn.click()
  203. }
  204. })
  205.  
  206.  
  207.  
  208.  
  209. middleBtn.click(function () {
  210. if (!!!win.___t) {
  211. win.___func();
  212. } else {
  213. clearTimeout(win.___t)
  214. win.___t = 0
  215. }
  216. })
  217.  
  218. container.appendTo('body');
  219.  
  220. $(window).blur(function () {
  221. clearTimeout(win.___t)
  222. win.___t = 0
  223. }).focus(function () {
  224. win.___func();
  225. })
  226.  
  227.  
  228. })
  229. })(function (callback, safe) {
  230. if (typeof jQuery == "undefined") {
  231. let script = document.createElement("script")
  232. script.type = "text/javascript"
  233. script.src = "https://code.jquery.com/jquery-3.6.1.min.js"
  234. if (safe) {
  235. let cb = document.createElement("script")
  236. cb.type = "text/javascript"
  237. cb.textContent = "jQuery.noConflict();(" + callback.toString() + ")(jQuery, window);"
  238. script.addEventListener("load", function () {
  239. document.head.appendChild(cb)
  240. })
  241. } else {
  242. let dollar = undefined
  243. if (typeof $ != "undefined") dollar = $
  244. script.addEventListener("load", function () {
  245. jQuery.noConflict()
  246. $ = dollar
  247. callback(jQuery, window)
  248. })
  249. }
  250. document.head.appendChild(script)
  251. } else {
  252. setTimeout(function () {
  253. //Firefox supports
  254. callback(jQuery, typeof unsafeWindow === "undefined" ? window : unsafeWindow)
  255. }, 30)
  256. }
  257. });