掘金日常操作

后台判断自动签到;抽奖;一键全赞,在 bug 收集页面自动收集

  1. // ==UserScript==
  2. // @name 掘金日常操作
  3. // @version 2.4.5
  4. // @description 后台判断自动签到;抽奖;一键全赞,在 bug 收集页面自动收集
  5. // @match https://juejin.cn/**
  6. // @run-at document-end
  7. // @icon https://img2.baidu.com/it/u=4226010475,2406859093&fm=26&fmt=auto
  8. // @require https://code.jquery.com/jquery-3.1.1.min.js
  9. // @namespace https://gf.qytechs.cn/users/823922
  10. // @grant GM.registerMenuCommand
  11. // ==/UserScript==
  12. {
  13. // aid 写死实测发现没大问题,有问题在自己换吧;uuid 不确定干嘛的,给个随机数拉到
  14. function createUUID() {
  15. return '7' + parseInt(Math.random() * (10 ** 9)) + '' + parseInt(Math.random() * (10 ** 9));
  16. }
  17.  
  18. function userInfo() {
  19. return 'aid=2608&uuid=' + createUUID();
  20. }
  21. var run = (function() { // 用于处理,页面内点击时,异步刷新页面
  22. let clickTime;
  23.  
  24. function once() {
  25. clearTimeout(clickTime);
  26. clickTime = setTimeout(() => {
  27. let sysDate = unsafeWindow.localStorage.juejinDayTask;
  28. if (sysDate == null || sysDate != currDate()) {
  29. dayTask();
  30. }
  31. let $menu = $('.nav-list>.main-nav-list>ul');
  32. if ($('#ou-chi-mao').length > 0) return;
  33. // 当发现页面元素变化时,重写渲染,并绑定元素
  34. $menu.find('li:gt(4)').remove();
  35. $menu.find('li:last>a').attr({
  36. 'id': 'ou-chi-mao',
  37. 'href': 'javascript:void(0);',
  38. }).css({
  39. 'color': '#03f9',
  40. // 'font-family': 'serif',
  41. 'font-weight': 'bolder'
  42. }).text('血统鉴定');
  43. // 通过 html 删除,再添加的方式,移除这个按钮上的绑定事件
  44. let html = $('#ou-chi-mao').parent().prop('outerHTML');
  45. $('#ou-chi-mao').parent().remove();
  46. $menu.append(html);
  47. $('#ou-chi-mao').click(function() {
  48. choujiang();
  49. console.log('false')
  50. return false;
  51. })
  52.  
  53. }, 500)
  54.  
  55. };
  56. return {
  57. once: once,
  58. }
  59. })();
  60.  
  61. // init
  62. unsafeWindow.$ = $;
  63. setTimeout(() => run.once(), 400);
  64. // 检查是否有未确认的中奖通知
  65. if ((unsafeWindow.localStorage.luckyGay || '') != '') {
  66. tipLuckyGay();
  67. }
  68.  
  69. function choujiang() {
  70. console.log('调用抽奖函数');
  71. let obj = {};
  72. let flag = true;
  73. simpleDialog.open();
  74. new Promise((resolve, reject) => {
  75. call();
  76.  
  77. function call() {
  78. fetch(`https://api.juejin.cn/growth_api/v1/lottery/draw?${userInfo()}`, httpConfig).then(resp => resp.json()).then(data => {
  79. if (data.err_msg != 'success') {
  80. resolve();
  81. return;
  82. }
  83. let name = data.data.lottery_name;
  84. console.log(name);
  85. simpleDialog.addRecord(name)
  86. obj[name] = obj[name] || 0;
  87. obj[name] = obj[name] + 1;
  88. setTimeout(() => call(), parseInt(Math.random() * 1500) + 300);
  89. if (['矿石', 'Bug'].indexOf(data.data.lottery_name.replace(/[0-9]/g, '')) == -1) {
  90. unsafeWindow.localStorage.luckyGay += ('\n' + name);
  91. }
  92. })
  93. }
  94. }).then(data => {
  95. let keys = Object.keys(obj);
  96. simpleDialog.empty();
  97. let msg = keys.length > 0 ? keys.map(k => k + ': ' + obj[k]).join('<br>') : '抽奖次数不足!';
  98. simpleDialog.addRecord(msg);
  99. simpleDialog.close();
  100. })
  101. return false;
  102. }
  103.  
  104. async function dayTask() {
  105. console.log('调用日活函数')
  106. // return false;
  107. let msgs = [];
  108. let freeLottery = true;
  109. let bigLottery = false; // 超级大奖
  110. // 签到
  111. await fetch(
  112. `https://api.juejin.cn/growth_api/v1/check_in?${userInfo()}&_signature=_02B4Z6wo00101q966EAAAIDCL3gSAGCq5SKvfuzAAMrJs3JkiZSLejXKJy5lR-3Rot9hYdZVnmHKrdQPh0MmwDCQsjT9tEIN0G3uIK8RsU7pcEznZ9.oqqfseed8PMV.rul6lxG-dkqFtwsq61`,
  113. httpConfig).then(resp => resp.json()).then(data => {
  114. if (data.err_msg == 'success') {
  115. msgs.push('签到成功!');
  116. } else {
  117. freeLottery = false;
  118. msgs.push(data.err_msg);
  119. unsafeWindow.localStorage.juejinDayTask = currDate();
  120. }
  121. console.log(data);
  122. });
  123. if (!freeLottery) return false; // 没有免费抽奖就退出
  124. await fetch(`https://api.juejin.cn/growth_api/v1/lottery/draw?${userInfo()}`, httpConfig).then(resp => resp.json()).then(data => {
  125. if (data.err_msg == 'success') {
  126. msgs.push(`获得奖品 ${data.data.lottery_name}`);
  127. }
  128. if (['矿石', 'Bug'].indexOf(data.data.lottery_name.replace(/[0-9]/g, '')) == -1) { // 特地标记中奖了!
  129. bigLottery = true;
  130. unsafeWindow.localStorage.luckyGay = `获得奖品 ${data.data.lottery_name}`;
  131. }
  132. console.log(data);
  133. });
  134. await fetch(`https://api.juejin.cn/growth_api/v1/lottery_lucky/dip_lucky?${userInfo()}`, httpConfig).then(resp => resp.json()).then(data => {
  135. console.log('沾点蚊子腿的幸运值 ' + data.dip_value)
  136. });
  137. simpleDialog.open();
  138. simpleDialog.addRecord(msgs.join('<br>'));
  139. simpleDialog.close(1200);
  140. if (bigLottery) {
  141. tipLuckyGay();
  142. }
  143. }
  144.  
  145. function tipLuckyGay() {
  146. // 缓存写入中奖信息,等手动确认了再清空
  147. if (confirm('请确认已经知道中奖!\n\n' + unsafeWindow.localStorage.luckyGay)) {
  148. unsafeWindow.localStorage.removeItem('luckyGay')
  149. }
  150. }
  151.  
  152. function currDate() {
  153. let date = new Date();
  154. return [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-');
  155. }
  156. var httpConfig = {
  157. "headers": {
  158. "accept": "*/*",
  159. "accept-language": "zh-CN,zh;q=0.9",
  160. "content-type": "application/json",
  161. "sec-ch-ua": "\"Chromium\";v=\"94\", \"Google Chrome\";v=\"94\", \";Not A Brand\";v=\"99\"",
  162. "sec-ch-ua-mobile": "?0",
  163. "sec-ch-ua-platform": "\"Windows\"",
  164. "sec-fetch-dest": "empty",
  165. "sec-fetch-mode": "cors",
  166. "sec-fetch-site": "same-site"
  167. },
  168. "referrer": "https://juejin.cn/",
  169. "referrerPolicy": "strict-origin-when-cross-origin",
  170. "body": "{}",
  171. "method": "POST",
  172. "mode": "cors",
  173. "credentials": "include"
  174. };
  175.  
  176. var simpleDialog = (function() { // 简易的弹窗效果
  177. return {
  178. open: () => {
  179. let html =
  180. `<div id="lotteryResultDialog" style="position: absolute;z-index: 9999;width: 200px;height: 200px;left: calc(50vw - 100px);top: calc(30vh - 100px);
  181. border-radius: 5px;padding: 10px;overflow: hidden;box-shadow: 0 0 7px 1px #f00a;background: #fffa;">
  182. <div style="overflow: auto;width: 240px;height: 200px;"></div>
  183. </div>
  184. `;
  185. $('body').append(html);
  186. },
  187. addRecord: (msg) => {
  188. let html = `<div style="padding: 5px;font-size: 16px;display:none">${msg}</div>`;
  189. $('#lotteryResultDialog>div').prepend(html);
  190. $('#lotteryResultDialog>div>div:first').show(100).css({
  191. 'color': 'red'
  192. })
  193. .siblings().css({
  194. 'color': '#000'
  195. })
  196. },
  197. close: (time = 1200) => {
  198. setTimeout(() => $('#lotteryResultDialog').slideUp(300, function() {
  199. $('#lotteryResultDialog').remove()
  200. }), time)
  201. },
  202. empty: () => {
  203. $('#lotteryResultDialog>div').empty();
  204. }
  205. }
  206. })();
  207. unsafeWindow.simpleDialog = simpleDialog;
  208. // ------------------------------- 点赞 -------------------------------------------
  209. function myFetch(url, config) {
  210. return fetch(url, {
  211. "headers": {
  212. "accept": "*/*",
  213. "accept-language": "zh-CN,zh;q=0.9",
  214. "content-type": "application/json",
  215. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"96\", \"Google Chrome\";v=\"96\"",
  216. "sec-fetch-dest": "empty",
  217. "sec-fetch-mode": "cors",
  218. "sec-fetch-site": "same-site"
  219. },
  220. "referrer": "https://juejin.cn/",
  221. "referrerPolicy": "strict-origin-when-cross-origin",
  222. "body": config.body,
  223. "method": "POST",
  224. "mode": "cors",
  225. "credentials": "include"
  226. }).then(r => r.json());
  227. }
  228. // 文章获取
  229. function articleFetch(cursor) {
  230. return myFetch("https://api.juejin.cn/content_api/v1/article/query_list?" + userInfo(), {
  231. 'body': JSON.stringify({
  232. user_id: getUserId(),
  233. sort_type: 2,
  234. cursor: cursor
  235. })
  236. });
  237. }
  238. // 点赞安排
  239. function diggFetch(articleId) {
  240. return myFetch("https://api.juejin.cn/interact_api/v1/digg/save?" + userInfo(), {
  241. 'body': JSON.stringify({
  242. item_id: articleId,
  243. item_type: 2,
  244. client_type: 2608
  245. })
  246. });
  247. }
  248.  
  249. // 判断文章的数量
  250. let arr = [];
  251. // 文章到底,或者连续 10 篇以点赞,就不继续遍历了
  252. function call(cursor = '0') {
  253. if (getUserId() == '') {
  254. alert('请到用户的主页,再执行此操作!')
  255. return false;
  256. }
  257. // console.log(cursor)
  258. articleFetch(cursor).then(d => {
  259. let temp = d.data.filter(n => !n.user_interact.is_digg).map(n => n.article_info.article_id);
  260. arr.push(...temp);
  261. if (d.count != parseInt(d.cursor) && temp.length > 0) {
  262. setTimeout(() => call(d.cursor), 100);
  263. } else {
  264. let msg = `共 ${arr.length} 篇文章点赞完成!`;
  265.  
  266. function temp1() {
  267. new Promise((resolve, reject) => {
  268. if (arr.length == 0) {
  269. reject();
  270. } else {
  271. resolve();
  272. }
  273. }).then(() => {
  274. setTimeout(() => {
  275. diggFetch(arr.pop());
  276. temp1();
  277. }, parseInt(Math.random() * 300) + 30)
  278. }).catch(() => {
  279. alert(msg);
  280. })
  281. }
  282. temp1();
  283.  
  284. }
  285. })
  286. }
  287.  
  288. function getUserId() {
  289. let url = unsafeWindow.location.href;
  290. if (url.indexOf('https://juejin.cn/user/') == -1) {
  291. return '';
  292. } else {
  293. return url.split('/')[4];
  294. }
  295. }
  296.  
  297. function collectBugs() {
  298. for (let i = 1; i < 4; i++) {
  299. let time = setTimeout(() => $('[src="//lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/img/timedGeneration.fa59c66.png"]').click(), i * 1500)
  300. console.log(time)
  301. }
  302. }
  303.  
  304. {
  305. bugsTimeCount = 10;
  306. let collectBugsTime = setInterval(() => {
  307. if (bugsTimeCount-- < 0) {
  308. clearInterval(collectBugsTime);
  309. }
  310. if ('https://juejin.cn/user/center/bugfix?enter_from=bugFix_bar' == unsafeWindow.location.href) {
  311. collectBugs();
  312. clearInterval(collectBugsTime);
  313. }
  314. }, 2000)
  315. }
  316. GM.registerMenuCommand('一键全赞', call)
  317. GM.registerMenuCommand(collectBugs)
  318. }

QingJ © 2025

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