Auto_Sub3

一键快乐-3

目前为 2021-03-06 提交的版本,查看 最新版本

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