BiliBili每日任务

自动完成bilibili的每日任务

  1. // ==UserScript==
  2. // @name BiliBili每日任务
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 自动完成bilibili的每日任务
  6. // @author maxinimize
  7. // @match https://account.bilibili.com/account/home
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const getRandomInt = (min, max) => {
  15. min = Math.ceil(min);
  16. max = Math.floor(max);
  17. return Math.floor(Math.random() * (max - min)) + min;
  18. }
  19.  
  20. const fetchAttentions = async () => {
  21. try {
  22. let attentionList = [];
  23. const uid = document.cookie.split('; ').find(x => x.substr(0,11) === 'DedeUserID=').substr(11);
  24. const response = await fetch(`https://api.bilibili.com/x/relation/followings?vmid=${uid}&ps=50&order=desc`)
  25. const data = await response.json();
  26. if (data.code === 0) {
  27. let attentionList = data.data.list.map(a => a.mid)
  28. return attentionList
  29. } else {
  30. console.log(data.message);
  31. }
  32. } catch (error) {
  33. console.log('错误', error);
  34. }
  35. }
  36.  
  37. const fetchVideos = async () => {
  38. try {
  39. let attentionList = await fetchAttentions();
  40. let videoList = [];
  41. for (let a of attentionList) {
  42. let response = await fetch(`https://space.bilibili.com/ajax/member/getSubmitVideos?mid=${a}&pagesize=100&tid=0`)
  43. let data = await response.json();
  44. videoList = videoList.concat(data.data.vlist.map(v => v.aid))
  45. }
  46. return videoList
  47.  
  48. } catch (error) {
  49. console.log('错误', error);
  50. }
  51. }
  52.  
  53. /*
  54. const fetchFiveMinsVideos = async () => {
  55. try {
  56. let attentionList = await fetchAttentions();
  57. let videoList = [];
  58. for (let a of attentionList) {
  59. let response = await fetch(`https://space.bilibili.com/ajax/member/getSubmitVideos?mid=${a}&pagesize=100&tid=0`)
  60. let data = await response.json(); // parseInt(data.data.vlist[0].length.split(':'))
  61. let result = data.data.vlist.filter(v => v.length.split(':').length > 2 || v.length.split(':') = 2 && parseInt(v.length.split(':')[0], 10))
  62. videoList = videoList.concat(data.data.vlist.map(v => v.aid))
  63. }
  64. return videoList
  65.  
  66. } catch (error) {
  67. console.log('错误', error);
  68. }
  69. }
  70. */
  71.  
  72.  
  73. const fetchWatch = async (aid) => {
  74. try {
  75. let response = await fetch('https://api.bilibili.com/x/web-interface/view?aid='+aid)
  76. let data = await response.json();
  77. if (data.code === 0) {
  78. const cid = data.data.cid;
  79. const duration = data.data.duration;
  80. const sid = document.cookie.split('; ').find(x => x.substr(0,4) === 'sid=').substr(4);
  81. const uid = document.cookie.split('; ').find(x => x.substr(0,11) === 'DedeUserID=').substr(11);
  82. const csrf = document.cookie.split('; ').find(x => x.substr(0,9) === 'bili_jct=').substr(9);
  83. response = await fetch('https://api.bilibili.com/x/report/click/h5', {
  84. credentials: 'include',
  85. method: 'post',
  86. headers: {'Content-type': 'application/x-www-form-urlencoded'},
  87. body: `aid=${aid}&cid=${cid}&part=1&did=${sid}&ftime=${new Date().getTime()}&jsonp=jsonp&lv=None&mid=${uid}&csrf=${csrf}&stime=${new Date().getTime()}`
  88. })
  89. data = await response.json();
  90. if (data.code === 0) {
  91. response = await fetch('https://api.bilibili.com/x/report/web/heartbeat', {
  92. credentials: 'include',
  93. method: 'post',
  94. headers: {'Content-type': 'application/x-www-form-urlencoded'},
  95. body: `aid=${aid}&cid=${cid}&jsonp=jsonp&mid=${uid}&csrf=${csrf}&played_time=0&pause=false&realtime=${duration}&dt=7&play_type=1&start_ts=${new Date().getTime()}`
  96. })
  97. data = await response.json();
  98. if (data.code === 0) {
  99. const controller = new AbortController();
  100. const signal = controller.signal;
  101. const fetchPromise = fetch('https://api.bilibili.com/x/report/web/heartbeat', {
  102. credentials: 'include',
  103. method: 'post',
  104. headers: {'Content-type': 'application/x-www-form-urlencoded'},
  105. body: `aid=${aid}&cid=${cid}&jsonp=jsonp&mid=${uid}&csrf=${csrf}&played_time=${duration-1}&pause=false&realtime=${duration}&dt=7&play_type=0&start_ts=${new Date().getTime()}`
  106. })
  107. const timeoutId = setTimeout(() => controller.abort(), 5000);
  108. data = await fetchPromise.then(response => response.json());
  109. if (data.code === 0) {
  110. console.log('观看成功');
  111. return true
  112. } else {
  113. console.log('观看失败@4: ', data.message);
  114. return false
  115. }
  116. } else {
  117. console.log('观看失败@3: ', data.message);
  118. return false
  119. }
  120.  
  121. } else {
  122. console.log('观看失败@2: ', data.message);
  123. return false
  124. }
  125. } else {
  126. console.log('获取视频信息失败: ', data.message);
  127. return false
  128. }
  129. } catch (error) {
  130. console.log('错误', error);
  131. return false
  132. }
  133. }
  134.  
  135. const fetchShare = async (body) => {
  136. try {
  137. const response = await fetch('https://api.bilibili.com/x/web-interface/share/add', {
  138. credentials: 'include',
  139. method: 'post',
  140. headers: {'Content-type': 'application/x-www-form-urlencoded'},
  141. body: body
  142. })
  143. const data = await response.json();
  144. if (data.code === 0) {
  145. console.log("分享成功");
  146. return true
  147. } else {
  148. console.log(data.message);
  149. return false
  150. }
  151. } catch (error) {
  152. console.log('错误', error);
  153. return false
  154. }
  155. }
  156.  
  157. const fetchCoin = async (body) => {
  158. try {
  159. const response = await fetch('https://api.bilibili.com/x/web-interface/coin/add', {
  160. credentials: 'include',
  161. method: 'post',
  162. headers: {'Content-type': 'application/x-www-form-urlencoded'},
  163. body: body
  164. })
  165. const data = await response.json()
  166. if (data.code === 0) {
  167. console.log("投币成功");
  168. return true
  169. } else {
  170. console.log(data.message);
  171. return false
  172. }
  173. } catch (error) {
  174. console.log('错误', error);
  175. return false
  176. }
  177. }
  178.  
  179. const watch = async () => {
  180. let videoList = await fetchVideos();
  181. let aid = videoList[getRandomInt(0, videoList.length)];
  182. return fetchWatch(aid);
  183. }
  184.  
  185. const share = async () => {
  186. let videoList = await fetchVideos();
  187. let aid = videoList[getRandomInt(0, videoList.length)];
  188. let csrf = document.cookie.split('; ').find(x => x.substr(0,9) === 'bili_jct=').substr(9);
  189. let payload = `aid=${aid}&csrf=${csrf}`;
  190. return fetchShare(payload);
  191. }
  192.  
  193. const coin = async () => {
  194. let videoList = await fetchVideos();
  195. let aid = videoList[getRandomInt(0, videoList.length)];
  196. let csrf = document.cookie.split('; ').find(x => x.substr(0,9) === 'bili_jct=').substr(9);
  197. let payload = `aid=${aid}&multiply=1&csrf=${csrf}`;
  198. return fetchCoin(payload);
  199. }
  200.  
  201. window.setTimeout(() => {
  202. if (document.querySelector('#app > div > div.security_content > div.security-right > div > div:nth-child(2) > div.home-daily-task-warp > div > div:nth-child(2) > div.home-dialy-exp-icon.position-rest')) {
  203. watch()
  204. }
  205.  
  206. if (document.querySelector('#app > div > div.security_content > div.security-right > div > div:nth-child(2) > div.home-daily-task-warp > div > div:nth-child(3) > div.home-dialy-exp-icon.position-rest')) {
  207. if (document.querySelector('#app > div > div.security_content > div.security-right > div > div:nth-child(2) > div.home-daily-task-warp > div > div:nth-child(3) > p.re-exp-none').innerHTML === '未完成' || document.querySelector('#app > div > div.security_content > div.security-right > div > div:nth-child(2) > div.home-daily-task-warp > div > div:nth-child(3) > p.re-exp-none').innerHTML === '已获得0/50') {
  208. if (parseInt(document.querySelector('#app > div > div.security_content > div.security-right > div > div:nth-child(1) > div.index-info > div.home-right > div.home-top-bp > span:nth-child(4)').innerHTML, 10) >= 5) {
  209. let i = 0;
  210. let timer = setInterval(() => {
  211. coin();
  212. i = i + 1;
  213. if (i >= 5) {
  214. clearInterval(timer);
  215. }
  216. },2000);
  217. }
  218. }
  219. }
  220.  
  221. if (document.querySelector('#app > div > div.security_content > div.security-right > div > div:nth-child(2) > div.home-daily-task-warp > div > div:nth-child(4) > div.home-dialy-exp-icon.position-rest')) {
  222. share()
  223. }
  224. }, 5000)
  225. })();

QingJ © 2025

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