North-Plus Auto Task

自动领取和完成北+日常和周常任务

  1. // ==UserScript==
  2. // @name North-Plus Auto Task
  3. // @namespace https://github.com/starliiit
  4. // @version 0.5.2
  5. // @description 自动领取和完成北+日常和周常任务
  6. // @author sl
  7. // @match https://*.summer-plus.net
  8. // @match https://*.summer-plus.net/index.php
  9. // @match https://*.level-plus.net
  10. // @match https://*.level-plus.net/index.php
  11. // @match https://*.white-plus.net
  12. // @match https://*.white-plus.net/index.php
  13. // @match https://*.south-plus.net
  14. // @match https://*.white-plus.net/index.php
  15. // @match https://*.imoutolove.me
  16. // @match https://*.imoutolove.me/index.php
  17. // @grant GM_setValue
  18. // @grant GM_getValue
  19. // ==/UserScript==
  20.  
  21. (function () {
  22. 'use strict';
  23.  
  24. // Your code here...
  25.  
  26. const LOGIN_SPAN_ID = 'login_0';
  27.  
  28. const TASK_BASEURL = 'plugin.php?H_name=tasks&action=ajax&actions=job&cid=';
  29. const REWARD_BASEURL = 'plugin.php?H_name=tasks&action=ajax&actions=job2&cid=';
  30.  
  31. const DAILY_ID = '15';
  32. const WEEKLY_ID = '14';
  33.  
  34. const TASK_DAILY_KEY = 'lastTaskDaily';
  35. const TASK_WEEKLY_KEY = 'lastTaskWeekly';
  36.  
  37. const HOUR = 1000 * 60 * 60;
  38. const DAILY_INTERVAL = HOUR * 18;
  39.  
  40. // const WEEKLY_INTERVAL = HOUR * 158;
  41. const WEEKLY_INTERVAL = DAILY_INTERVAL;
  42.  
  43. const TIME_BEING_GRACEFUL = 1500;
  44.  
  45.  
  46. function checkTask(now, taskID, taskKey, taskInterval) {
  47. let lastSignIn = GM_getValue(taskKey);
  48. if (lastSignIn === undefined || (now - lastSignIn) > taskInterval) {
  49. // 领取任务
  50. ajax.send(TASK_BASEURL + taskID, '', function () {
  51. console.log(ajax.request.responseText);
  52.  
  53. setTimeout(function () {
  54. // 等 1.5s,领取奖励
  55. ajax.send(REWARD_BASEURL + taskID, '', function () {
  56. console.log(ajax.request.responseText);
  57. GM_setValue(taskKey, now);
  58. });
  59. }, TIME_BEING_GRACEFUL);
  60.  
  61. });
  62. }
  63. else {
  64. // do nothing.
  65. let interval = (now - lastSignIn) / (HOUR);
  66. console.log('距离上次任务过了 ' + interval.toFixed(2) + ' 小时');
  67. }
  68. }
  69.  
  70. // 检查是否已经登录
  71. if(document.getElementById(LOGIN_SPAN_ID) === null) {
  72.  
  73. let now = Date.now();
  74. checkTask(now, DAILY_ID, TASK_DAILY_KEY, DAILY_INTERVAL);
  75. setTimeout(function () {
  76. checkTask(now, WEEKLY_ID, TASK_WEEKLY_KEY, WEEKLY_INTERVAL);
  77. }, TIME_BEING_GRACEFUL);
  78.  
  79. }
  80.  
  81.  
  82. })();