Auto_Sub3

一键快乐-3

目前为 2021-09-14 提交的版本。查看 最新版本

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

QingJ © 2025

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