javdb auto open

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

  1. // ==UserScript==
  2. // @name javdb auto open
  3. // @namespace websiteEnhancement
  4. // @author jimmly
  5. // @version 2024.9.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. // @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. ["https://cdn.jsdelivr.net/gh/sodiray/radash@master/cdn/radash.min.js",
  24. "https://update.greasyfork.org/scripts/483173/1301961/GM_config_cnjames.js",
  25. "https://update.sleazyfork.org/scripts/476583/common_libs_of_array.js"
  26. ].reduce((p, url) => { return p.then(() => loadJS(url)) }, Promise.resolve())
  27. .then(v => {
  28. withJQuery(function ($, win) {
  29.  
  30. // 替换这些值为你的实际设置
  31. const baseUrl = 'https://192.168.8.249:30024'; // 例如 http://localhost:8080
  32. const username = 'admin';
  33. const password = 'adminadmin';
  34.  
  35. // 登录到qBittorrent Web UI
  36. async function login() {
  37. const response = await fetch(`${baseUrl}/api/v2/auth/login`, {
  38. method: 'POST',
  39. headers: {
  40. 'Content-Type': 'application/x-www-form-urlencoded'
  41. },
  42. body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`
  43. });
  44.  
  45. if (response.ok) {
  46. console.log('Logged in successfully.');
  47.  
  48. } else {
  49. console.error('Failed to log in.');
  50.  
  51. }
  52. return response
  53. }
  54.  
  55. // 添加新的torrent下载任务
  56. async function addTorrent(url) {
  57. const response = await fetch(`${baseUrl}/api/v2/torrents/add`, {
  58. method: 'POST',
  59. headers: {
  60. 'Content-Type': 'application/x-www-form-urlencoded'
  61. },
  62. body: `urls=${encodeURIComponent(url)}`
  63. });
  64.  
  65. if (response.ok) {
  66. console.log('added successfully.');
  67. } else {
  68. console.log('Failed to add.', response.body);
  69. }
  70. return response
  71. }
  72.  
  73. win.funcDownload = function () {
  74. (async () => {
  75.  
  76. login()
  77. .then(v => {
  78.  
  79. let torrentUrl = $('div.magnet-name.column.is-four-fifths>a').first().prop('href')
  80. return addTorrent(torrentUrl)
  81.  
  82. })
  83. .then(res => {
  84. if (res.ok) {
  85. window.close();
  86. window.open("about:blank", "_self").close();
  87. }
  88. else {
  89. console.log('Failed to add.', response);
  90. alert('add error')
  91. }
  92. }).catch(err => console.log(err))
  93.  
  94. })();
  95. }
  96. // win.funcList = function () { }
  97. // win.funcDetail = function () { }
  98. // const reg = /.*thread-(\d+)-.*/
  99. // win.__compareKey = function (cache, curr) {
  100. // if (cache === curr)
  101. // return true
  102. // ///thread-6638382-
  103. // if (reg.test(cache))
  104. // return cache.replace(reg, "$1") === curr
  105. // return false
  106. // }
  107. // win.fixValue = function (value) {
  108. // if (reg.test(value))
  109. // return value.replace(reg, "$1")
  110. // return value
  111. // }
  112. $('table a').removeAttr('style')
  113.  
  114. autoFind(() => ['/', '/tags', '/tags/uncensored'].includes(window.location.pathname), 'javdb', '.item a', el => el.attr('title'), $, {}, win);
  115.  
  116.  
  117. })
  118. })
  119.  
  120. })(function (FILE_URL, async = true) {
  121. return new Promise((resolve, reject) => {
  122. let scriptEle = document.createElement("script");
  123. scriptEle.setAttribute("src", FILE_URL);
  124. scriptEle.setAttribute("type", "text/javascript");
  125. scriptEle.setAttribute("async", async);
  126. // success event
  127. scriptEle.addEventListener("load", () => {
  128. resolve(FILE_URL)
  129. });
  130. // error event
  131. scriptEle.addEventListener("error", (ev) => {
  132. reject(ev);
  133. });
  134. if (document.currentScript)
  135. document.currentScript.insertBefore(scriptEle)
  136. else
  137. (document.head || document.getElementsByTagName('head')[0]).appendChild(scriptEle);
  138. })
  139. });