Auto_Sub3

一键快乐-3

目前為 2021-10-11 提交的版本,檢視 最新版本

  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_info
  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.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. })();
  60. // 添加GUI
  61. function addBtns() {
  62. function genButton(text, foo, id) {
  63. let b = document.createElement('button');
  64. b.textContent = text;
  65. b.style.cssText = 'margin: 8px 5px;'
  66. b.addEventListener('click', foo);
  67. if (id) { b.id = id; }
  68. return b;
  69. }
  70. function genDiv(cls) {
  71. let d = document.createElement('div');
  72. if (cls) { d.className = cls };
  73. return d;
  74. }
  75. function genPanel(name, visiable) {
  76. let p = genDiv(name);
  77. p.id = name;
  78. p.style.cssText = 'width: 100%;height: 100%;';
  79. if (!visiable) { p.style.display = 'none'; }
  80. return p;
  81. }
  82. let btnSwitch = document.querySelector('.index_left_title>div');
  83.  
  84. if (btnSwitch == null) { return; }
  85.  
  86. btnSwitch.id = 'btnSwitch1';
  87. btnSwitch.title = '点这里开启/隐藏控制面板';
  88. btnSwitch.textContent='关注重点 - Auto Sub 3';
  89. btnSwitch.style.cssText = 'width: auto;padding: 0 5px;cursor: pointer;z-index: 1';
  90. btnSwitch.addEventListener('click', switchPanel);
  91.  
  92. let panelArea = document.querySelector('.index_navi_left');
  93. let panelOri = document.querySelector('.index_left_detail');
  94. panelOri.id = 'panelOri'
  95.  
  96. let panel54 = genPanel('panel54');
  97.  
  98. let aLP = document.createElement('a');
  99. aLP.href = Vroll;
  100. aLP.title = '前往轮盘页';
  101. let img54 = document.createElement('img');
  102. img54.src = 'https://gitee.com/chr_a1/gm_scripts/raw/master/Static/keylol.png';
  103. img54.alt = '总之这里是54的名言';
  104. img54.style.cssText = 'float: right;margin-top: -28px;height: 100%;'
  105. aLP.appendChild(img54);
  106.  
  107. let btnArea = genDiv('btnArea');
  108. btnArea.style.cssText = 'width: 180px;text-align: center;margin-top: -10px;margin-left: -10px;position: absolute;';
  109.  
  110. let btnS3 = genButton('【一键-3】', autoRoll, 'btnS3');
  111.  
  112. if (!VCan3) {
  113. btnS3.style.textDecoration = 'line-through';
  114. btnS3.textContent = '今天已经不能-3了';
  115. }
  116.  
  117. let btnAuto = genButton(bool2txt(VAuto) + '自动每日-3', fBtnAuto, 'btnAuto');
  118.  
  119. btnArea.appendChild(btnS3);
  120. btnArea.appendChild(btnAuto);
  121.  
  122. panel54.appendChild(aLP);
  123. panel54.appendChild(btnArea);
  124. panelArea.insertBefore(panel54, panelArea.children[1]);
  125. }
  126. // 自动-3
  127. function fBtnAuto() {
  128. VAuto = !VAuto;
  129. document.getElementById('btnAuto').textContent = bool2txt(VAuto) + '自动每日-3';
  130. saveCFG();
  131. }
  132. // 显示布尔
  133. function bool2txt(bool) {
  134. return bool ? '【√】' : '【×】';
  135. }
  136. // 隐藏面板
  137. function switchPanel() {
  138. let btnSwitch = document.getElementById( 'btnSwitch1');
  139. let panel1 = document.getElementById('panel54');
  140. let panel2 = document.getElementById('panelOri');
  141. if (panel1.style.display == 'none') {
  142. btnSwitch.textContent = 'Auto Sub 3 - By Chr_ - V ' + Ver;
  143. panel1.style.display = 'block';
  144. panel2.style.display = 'none';
  145. VShow=true;
  146. } else {
  147. btnSwitch.textContent = '关注重点 - Auto Sub 3';
  148. panel1.style.display = 'none';
  149. panel2.style.display = 'block';
  150. VShow=false;
  151. }
  152. saveCFG();
  153. }
  154. // 读取设置
  155. function loadCFG() {
  156. let t = null;
  157. t = GM_getValue('VLast');
  158. t = Number(t);
  159. if (t != t) { t = 0; }
  160. VLast = t;
  161. t = GM_getValue('VCan3');
  162. VCan3 = Boolean(t);
  163. t = GM_getValue('VShow');
  164. VShow = Boolean(t);
  165. t = GM_getValue('VAuto');
  166. VAuto = Boolean(t);
  167. // 日期变更,重置VCan3
  168. let d = new Date();
  169. let day = d.getDate();
  170. let hour = d.getHours();
  171. if (day != VLast && hour >= 8) {
  172. VCan3 = true;
  173. VLast = day;
  174. }
  175. saveCFG();
  176. }
  177. // 保存设置
  178. function saveCFG() {
  179. GM_setValue('VLast', VLast);
  180. GM_setValue('VCan3', VCan3);
  181. GM_setValue('VShow', VShow);
  182. GM_setValue('VAuto', VAuto);
  183. }
  184. // 检查能否-3
  185. function checkZP() {
  186. GM_xmlhttpRequest({
  187. method: "GET",
  188. url: Vroll,
  189. onload: (response) => {
  190. if (response.responseText != null) {
  191. let t = response.responseText;
  192. let can = t.search('<button id="roll">抽奖</button>') != -1;
  193. console.log(can);
  194. if (!can) {
  195. disableS3();
  196. }
  197. saveCFG();
  198. }
  199. },
  200. onerror: (response) => {
  201. showError('【出错了,淦】');
  202. }
  203. });
  204. }
  205. // 禁止-3
  206. function disableS3() {
  207. let b = document.getElementById('btnS3');
  208. b.style.textDecoration = 'line-through';
  209. b.textContent = '今天已经不能-3了';
  210. VCan3 = false;
  211. }
  212. // 自动-3
  213. function autoRoll() {
  214. try {
  215. Vsound.play();
  216. } catch (e) {
  217. console.error(e);
  218. }
  219. // if (!VCan3) {
  220. // return;
  221. // }
  222. let v = 0;
  223. gethash();
  224.  
  225. function gethash() {
  226. GM_xmlhttpRequest({
  227. method: "GET",
  228. url: Vroll,
  229. onload: (response) => {
  230. if (response.status == 200) {
  231. let m = response.responseText.match(Vregex);
  232. let hash = m ? m[1] : null;
  233. console.log(hash);
  234. if (hash != null) {
  235. roll(hash);
  236. roll(hash);
  237. roll(hash);
  238. } else {
  239. disableS3();
  240. saveCFG();
  241. showError('【今天已经无法 -3 了哟】');
  242. }
  243. } else {
  244. showError('【出错了,淦】');
  245. }
  246. },
  247. onerror: (response) => {
  248. showError('【出错了,淦】');
  249. }
  250. });
  251. }
  252.  
  253. function roll(hash) {
  254. GM_xmlhttpRequest({
  255. method: "GET",
  256. url: Vroll + '&hash=' + hash + '&roll',
  257. onload: (response) => {
  258. if (response.status == 200) {
  259. console.log(response.responseText);
  260. } else {
  261. showError('【出错了,淦】');
  262. console.error('出错')
  263. }
  264. if (++v == 3) {
  265. disableS3();
  266. saveCFG();
  267. showError('【自动 -3 完成,祝你好运】');
  268. setTimeout(() => { window.location.reload(); }, 600);
  269.  
  270. }
  271. },
  272. onerror: (response) => {
  273. showError('【出错了,淦】');
  274. }
  275. });
  276. }
  277. }
  278.  
  279.  
  280. class Request {
  281. constructor(timeout = 3000) {
  282. this.timeout = timeout;
  283. }
  284. get(url, opt = {}) {
  285. return this.baseRequest(url, 'GET', opt, 'json');
  286. }
  287. getHtml(url, opt = {}) {
  288. return this.baseRequest(url, 'GET', opt, '');
  289. }
  290. getText(url, opt = {}) {
  291. return this.baseRequest(url, 'GET', opt, 'text');
  292. }
  293. post(url, data, opt = {}) {
  294. opt.data = JSON.stringify(data);
  295. return this.baseRequest(url, 'POST', opt, 'json');
  296. }
  297. baseRequest(url, method = 'GET', opt = {}, responseType = 'json') {
  298. Object.assign(opt, {
  299. url, method, responseType, timeout: this.timeout
  300. });
  301. return new Promise((resolve, reject) => {
  302. opt.ontimeout = opt.onerror = reject;
  303. opt.onload = ({ readyState, status, response, responseText }) => {
  304. if (readyState === 4 && status === 200) {
  305. if (responseType == 'json') {
  306. resolve(response);
  307. } else if (responseType == 'text') {
  308. resolve(responseText);
  309. }
  310. } else {
  311. console.error('网络错误');
  312. console.log(readyState);
  313. console.log(status);
  314. console.log(response);
  315. reject('解析出错');
  316. }
  317. }
  318. GM_xmlhttpRequest(opt);
  319. });
  320. }
  321. }
  322. const $http = new Request();