Auto Loot

lootlink.me 自动领取日常奖励,自动抽奖

  1. // ==UserScript==
  2. // @name Auto Loot
  3. // @namespace https://blog.chrxw.com
  4. // @version 1.2
  5. // @description lootlink.me 自动领取日常奖励,自动抽奖
  6. // @author Chr_
  7. // @include https://www.lootlink.me/*
  8. // @license AGPL-3.0
  9. // @icon https://blog.chrxw.com/favicon.ico
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. showLabel();
  16. dailyClaim();
  17. add10xBtn();
  18. })();
  19. // 显示标签
  20. function showLabel() {
  21. let uname = document.querySelector('#profileMenuInvoker>span');
  22. let tag1 = document.createElement('span');
  23. tag1.textContent = ' (反馈 ';
  24. tag1.addEventListener('click', () => {
  25. window.open('https://keylol.com/t676764-1-1');
  26. });
  27. let tag2 = document.createElement('span');
  28. tag2.textContent = '| By Chr_) ';
  29. tag2.addEventListener('click', () => {
  30. window.open('https://blog.chrxw.com');
  31. });
  32. uname.appendChild(tag1);
  33. uname.appendChild(tag2);
  34. }
  35. // 每日签到&自动开箱
  36. function dailyClaim() {
  37. const MAX = 20;
  38. let tries = 0;
  39. clickDaily();
  40. function clickDaily() {
  41. let coin = document.querySelector('#wallet2 a[data-modal-target="#crate-modal"]');
  42. if (coin) {
  43. coin.click();
  44. tries = 0;
  45. retry(claimCoin, 1000);
  46. } else {
  47. let coin = document.querySelector('#wallet2 div:not([style*="display:none"])>[src="/images/art/crate.png"]:not(.grayscale)');
  48. if (coin) {
  49. coin.parentElement.click();
  50. tries = 0;
  51. retry(claimCoin, 1000);
  52. }
  53. }
  54. }
  55. function claimCoin() {
  56. let claimbtn = document.querySelector("#cratetab > a");
  57. if (claimbtn) {
  58. claimbtn.click();
  59. tries = 0;
  60. retry(closePanel, 1000);
  61. } else {
  62. retry(claimCoin, 500);
  63. }
  64. }
  65. function closePanel() {
  66. let title = document.querySelector("#cratetab > h4");
  67. if (title.textContent.search('Opened') != -1 || title.textContent.search('Received') != -1) {
  68. let closebtn = document.querySelector("#crate-modal > button");
  69. closebtn.click();
  70. window.location.reload();
  71. } else {
  72. retry(closePanel, 500);
  73. }
  74. }
  75. function retry(foo, t) {
  76. console.log(foo.name);
  77. if (tries++ <= MAX) {
  78. setTimeout(() => {
  79. try {
  80. foo();
  81. }
  82. catch (e) {
  83. console.log(e);
  84. throw e;
  85. }
  86. }, t);
  87. } else {
  88. console.log('操作超时');
  89. }
  90. }
  91. }
  92. // 添加x连按钮
  93. function add10xBtn() {
  94. function genBtn(txt, time, index) {
  95. let btn = document.createElement('button');
  96. console.log('loot' + time.toString() + 'x' + (index).toString())
  97. btn.id = 'loot' + time.toString() + 'x' + (index).toString();
  98. btn.onclick = loot10x;
  99. btn.className = 'float-right btn btn-lg u-btn-cyan g-color-white u-btn-hover-v2-1';
  100. btn.textContent = txt;
  101. return btn;
  102. }
  103. let lootBtns = document.querySelectorAll('button[data-modal-target="#loot-modal"]');
  104. let i = 0;
  105. for (let lootBtn of lootBtns) {
  106. let bar = lootBtn.parentElement.parentElement.children[0];
  107. let box = document.createElement('div');
  108. let btn5x = genBtn('五连', 5, i);
  109. let btn10x = genBtn('十连', 10, i);
  110. let btn100x = genBtn('梭哈', 100, i);
  111. box.appendChild(btn5x);
  112. box.appendChild(btn10x);
  113. box.appendChild(btn100x);
  114. bar.insertBefore(box, bar.children[0]);
  115. i++;
  116. }
  117. }
  118. // x连
  119. function loot10x(e) {
  120. const MAX = 50;
  121. let LOOT = 0;
  122. let tries = 0;
  123. let count = 0;
  124. clickLoot();
  125. function clickLoot() {
  126. let id = e.target.getAttribute('id');
  127. let t = id.match(/^loot(\d+)x(\d+)$/);
  128. t = t ? [t[1], t[2]] : [0, 0];
  129. let lootBtns = document.querySelectorAll('button[data-modal-target="#loot-modal"]');
  130. if (lootBtns == null) {
  131. alert('未找到Loot按钮');
  132. return;
  133. }
  134. LOOT = Number(t[0]);
  135. lootBtns[Number(t[1])].click();
  136. tries = 0;
  137. retry(claimLoot, 1000);
  138. }
  139. function claimLoot() {
  140. let lootbtn = document.querySelector('#rollit');
  141. if (lootbtn) {
  142. document.getElementById('rollmessage').textContent = '第' + (count + 1).toString() + '/' + LOOT.toString() + '抽';
  143. lootbtn.click();
  144. tries = 0;
  145. retry(waitLoot, 1000);
  146. } else {
  147. retry(claimLoot, 1000);
  148. }
  149. }
  150. function waitLoot() {
  151. let lootbtn = document.querySelector("#rollit");
  152. if (lootbtn.textContent.search('Try') != -1) {
  153. if (++count >= LOOT) {
  154. document.getElementById('rollmessage').textContent = '抽完啦';
  155. console.log('done');
  156. return;
  157. }
  158. tries = 0;
  159. retry(claimLoot, 1000);
  160. } else {
  161. retry(waitLoot, 1000);
  162. }
  163. }
  164. function retry(foo, t) {
  165. console.log(foo.name);
  166. if (tries++ <= MAX) {
  167. setTimeout(() => {
  168. try {
  169. if (document.getElementById('rolltab') == null) {
  170. console.log('cancel');
  171. return;
  172. }
  173. foo();
  174. }
  175. catch (e) {
  176. console.log(e);
  177. throw e;
  178. }
  179. }, t);
  180. } else {
  181. console.log('操作超时');
  182. }
  183. }
  184. }