Auto_Sub3

一键快乐-3

当前为 2021-07-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Auto_Sub3
  3. // @name:zh-CN 蒸汽轮盘自动-3
  4. // @namespace https://blog.chrxw.com
  5. // @version 2.16
  6. // @description 一键快乐-3
  7. // @description:zh-CN 一键快乐-3
  8. // @author Chr_
  9. // @include https://keylol.com/*
  10. // @license AGPL-3.0
  11. // @icon https://blog.chrxw.com/favicon.ico
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_xmlhttpRequest
  15. // ==/UserScript==
  16.  
  17. // 版本号
  18. const Ver = '2.16'
  19. // 上次-3时间
  20. let VLast = 0;
  21. // 今天还能不能-3
  22. let VCan3 = true;
  23. // 自动展开
  24. let VShow = false;
  25. // 自动-3
  26. let VAuto = false;
  27. // 音效载入
  28. const Vsound = new Audio('https://blog.chrxw.com/usr/keylol/gas.mp3');
  29. // 轮盘链接
  30. const Vroll = 'https://keylol.com/plugin.php?id=steamcn_lottery:view&lottery_id=46';
  31. // 正则表达式
  32. const Vregex = /plugin\.php\?id=steamcn_lottery:view&lottery_id=45&hash=(.+)&roll/;
  33.  
  34. (() => {
  35. 'use strict';
  36. loadCFG();
  37. addBtns();
  38. if (VShow) {
  39. switchPanel();
  40. }
  41. if (VCan3 && VAuto) {
  42. autoRoll();
  43. }
  44. })();
  45. // 添加GUI
  46. function addBtns() {
  47. function genButton(text, foo, id) {
  48. let b = document.createElement('button');
  49. b.textContent = text;
  50. b.style.cssText = 'margin: 8px 5px;'
  51. b.addEventListener('click', foo);
  52. if (id) { b.id = id; }
  53. return b;
  54. }
  55. function genDiv(cls) {
  56. let d = document.createElement('div');
  57. if (cls) { d.className = cls };
  58. return d;
  59. }
  60. function genPanel(name, visiable) {
  61. let p = genDiv(name);
  62. p.id = name;
  63. p.style.cssText = 'width: 100%;height: 100%;';
  64. if (!visiable) { p.style.display = 'none'; }
  65. return p;
  66. }
  67. let btnSwitch = document.querySelector('.index_left_title>div');
  68.  
  69. if (btnSwitch == null) { return; }
  70.  
  71. btnSwitch.id = 'btnSwitch1';
  72. btnSwitch.title = '点这里开启/隐藏控制面板';
  73. btnSwitch.textContent='关注重点 - Auto Sub 3';
  74. btnSwitch.style.cssText = 'width: auto;padding: 0 5px;cursor: pointer;z-index: 1';
  75. btnSwitch.addEventListener('click', switchPanel);
  76.  
  77. let panelArea = document.querySelector('.index_navi_left');
  78. let panelOri = document.querySelector('.index_left_detail');
  79. panelOri.id = 'panelOri'
  80.  
  81. let panel54 = genPanel('panel54');
  82.  
  83. let aLP = document.createElement('a');
  84. aLP.href = Vroll;
  85. aLP.title = '前往轮盘页';
  86. let img54 = document.createElement('img');
  87. img54.src = 'https://gitee.com/chr_a1/gm_scripts/raw/master/Static/keylol.png';
  88. img54.alt = '总之这里是54的名言';
  89. img54.style.cssText = 'float: right;margin-top: -28px;height: 100%;'
  90. aLP.appendChild(img54);
  91.  
  92. let btnArea = genDiv('btnArea');
  93. btnArea.style.cssText = 'width: 180px;text-align: center;margin-top: -10px;margin-left: -10px;position: absolute;';
  94.  
  95. let btnS3 = genButton('【一键-3】', autoRoll, 'btnS3');
  96.  
  97. if (!VCan3) {
  98. btnS3.style.textDecoration = 'line-through';
  99. btnS3.textContent = '今天已经不能-3了';
  100. }
  101.  
  102. let btnAuto = genButton(bool2txt(VAuto) + '自动每日-3', fBtnAuto, 'btnAuto');
  103.  
  104. btnArea.appendChild(btnS3);
  105. btnArea.appendChild(btnAuto);
  106.  
  107. panel54.appendChild(aLP);
  108. panel54.appendChild(btnArea);
  109. panelArea.insertBefore(panel54, panelArea.children[1]);
  110. }
  111. // 自动-3
  112. function fBtnAuto() {
  113. VAuto = !VAuto;
  114. document.getElementById('btnAuto').textContent = bool2txt(VAuto) + '自动每日-3';
  115. saveCFG();
  116. }
  117. // 显示布尔
  118. function bool2txt(bool) {
  119. return bool ? '【√】' : '【×】';
  120. }
  121. // 隐藏面板
  122. function switchPanel() {
  123. let btnSwitch = document.getElementById( 'btnSwitch1');
  124. let panel1 = document.getElementById('panel54');
  125. let panel2 = document.getElementById('panelOri');
  126. if (panel1.style.display == 'none') {
  127. btnSwitch.textContent = 'Auto Sub 3 - By Chr_ - V ' + Ver;
  128. panel1.style.display = 'block';
  129. panel2.style.display = 'none';
  130. VShow=true;
  131. } else {
  132. btnSwitch.textContent = '关注重点 - Auto Sub 3';
  133. panel1.style.display = 'none';
  134. panel2.style.display = 'block';
  135. VShow=false;
  136. }
  137. saveCFG();
  138. }
  139. // 读取设置
  140. function loadCFG() {
  141. let t = null;
  142. t = GM_getValue('VLast');
  143. t = Number(t);
  144. if (t != t) { t = 0; }
  145. VLast = t;
  146. t = GM_getValue('VCan3');
  147. VCan3 = Boolean(t);
  148. t = GM_getValue('VShow');
  149. VShow = Boolean(t);
  150. t = GM_getValue('VAuto');
  151. VAuto = Boolean(t);
  152. // 日期变更,重置VCan3
  153. let d = new Date();
  154. let day = d.getDate();
  155. let hour = d.getHours();
  156. if (day != VLast && hour >= 8) {
  157. VCan3 = true;
  158. VLast = day;
  159. }
  160. saveCFG();
  161. }
  162. // 保存设置
  163. function saveCFG() {
  164. GM_setValue('VLast', VLast);
  165. GM_setValue('VCan3', VCan3);
  166. GM_setValue('VShow', VShow);
  167. GM_setValue('VAuto', VAuto);
  168. }
  169. // 检查能否-3
  170. function checkZP() {
  171. GM_xmlhttpRequest({
  172. method: "GET",
  173. url: Vroll,
  174. onload: (response) => {
  175. if (response.responseText != null) {
  176. let t = response.responseText;
  177. let can = t.search('<button id="roll">抽奖</button>') != -1;
  178. console.log(can);
  179. if (!can) {
  180. disableS3();
  181. }
  182. saveCFG();
  183. }
  184. },
  185. onerror: (response) => {
  186. showError('【出错了,淦】');
  187. }
  188. });
  189. }
  190. // 禁止-3
  191. function disableS3() {
  192. let b = document.getElementById('btnS3');
  193. b.style.textDecoration = 'line-through';
  194. b.textContent = '今天已经不能-3了';
  195. VCan3 = false;
  196. }
  197. // 自动-3
  198. function autoRoll() {
  199. try {
  200. Vsound.play();
  201. } catch (e) {
  202. console.error(e);
  203. }
  204. // if (!VCan3) {
  205. // return;
  206. // }
  207. let v = 0;
  208. gethash();
  209.  
  210. function gethash() {
  211. GM_xmlhttpRequest({
  212. method: "GET",
  213. url: Vroll,
  214. onload: (response) => {
  215. if (response.status == 200) {
  216. let m = response.responseText.match(Vregex);
  217. let hash = m ? m[1] : null;
  218. console.log(hash);
  219. if (hash != null) {
  220. roll(hash);
  221. roll(hash);
  222. roll(hash);
  223. } else {
  224. disableS3();
  225. saveCFG();
  226. showError('【今天已经无法 -3 了哟】');
  227. }
  228. } else {
  229. showError('【出错了,淦】');
  230. }
  231. },
  232. onerror: (response) => {
  233. showError('【出错了,淦】');
  234. }
  235. });
  236. }
  237.  
  238. function roll(hash) {
  239. GM_xmlhttpRequest({
  240. method: "GET",
  241. url: Vroll + '&hash=' + hash + '&roll',
  242. onload: (response) => {
  243. if (response.status == 200) {
  244. console.log(response.responseText);
  245. } else {
  246. showError('【出错了,淦】');
  247. console.error('出错')
  248. }
  249. if (++v == 3) {
  250. disableS3();
  251. saveCFG();
  252. showError('【自动 -3 完成,祝你好运】');
  253. setTimeout(() => { window.location.reload(); }, 600);
  254.  
  255. }
  256. },
  257. onerror: (response) => {
  258. showError('【出错了,淦】');
  259. }
  260. });
  261. }
  262. }

QingJ © 2025

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