Auto_Sub3

一键快乐-3

当前为 2021-01-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Auto_Sub3
  3. // @namespace https://blog.chrxw.com
  4. // @version 1.9
  5. // @description 一键快乐-3
  6. // @author Chr_
  7. // @include https://keylol.com/*
  8. // @connect steamcommunity.com
  9. // @connect steampowered.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. // 上次-3时间
  18. let VLast = 0;
  19. // 今天还能不能-3
  20. let VCan3 = true;
  21. // 自动展开
  22. let VShow = false;
  23. // 自动-3
  24. let VAuto = false;
  25.  
  26. (function () {
  27. 'use strict';
  28. loadCFG();
  29. addBtns();
  30. if (VShow) {
  31. switchPanel();
  32. }
  33. if (VCan3 && VAuto) {
  34. autoRoll();
  35. }
  36. })();
  37. // 添加GUI
  38. function addBtns() {
  39. function genButton(text, foo, id) {
  40. let b = document.createElement('button');
  41. b.textContent = text;
  42. b.style.cssText = 'margin: 3px 5px;'
  43. b.addEventListener('click', foo);
  44. if (id) { b.id = id; }
  45. return b;
  46. }
  47. function genDiv(cls) {
  48. let d = document.createElement('div');
  49. if (cls) { d.className = cls };
  50. return d;
  51. }
  52. function genPanel(name, visiable) {
  53. let p = genDiv(name);
  54. p.id = name;
  55. p.style.cssText = 'width: 100%;height: 100%;';
  56. if (!visiable) { p.style.display = 'none'; }
  57. return p;
  58. }
  59. let btnSwitch = document.querySelector('.index_left_title>div');
  60.  
  61. if (btnSwitch == null) { return; }
  62.  
  63. btnSwitch.id = 'btnSwitch1';
  64. btnSwitch.title = '点这里开启/隐藏控制面板';
  65. btnSwitch.style.cssText = 'width: auto;padding: 0 5px;cursor: pointer;';
  66. btnSwitch.addEventListener('click', switchPanel);
  67.  
  68. let panelArea = document.querySelector('.index_navi_left');
  69. let panelOri = document.querySelector('.index_left_detail');
  70. panelOri.id = 'panelOri'
  71.  
  72. let panel54 = genPanel('panel54');
  73.  
  74. let aLP = document.createElement('a');
  75. aLP.href = 'https://keylol.com/t571093-1-1';
  76. let img54 = document.createElement('img');
  77. img54.src = 'https://blog.chrxw.com/usr/keylol/index.png';
  78. img54.alt = '总之这里是54的名言';
  79. img54.style.cssText = 'float: right;margin-top: -28px;height: 100%;'
  80. aLP.appendChild(img54);
  81.  
  82. let btnArea = genDiv('btnArea');
  83. btnArea.style.cssText = 'width: 210px;text-align: center;margin-top: -10px;';
  84.  
  85. let btnS3 = genButton('【一键-3】', autoRoll, 'btnS3');
  86.  
  87. if (!VCan3) {
  88. btnS3.style.textDecoration = 'line-through';
  89. btnS3.textContent = '今天已经不能-3了';
  90. }
  91. // let btnFT = genButton('我要水贴', () => { window.location.href = 'https://keylol.com/forum.php?mod=post&action=newthread&fid=148' });
  92.  
  93. let btnShow = genButton(bool2txt(VShow) + '自动打开面板', fBtnShow, 'btnShow');
  94. let btnAuto = genButton(bool2txt(VAuto) + '自动每日-3', fBtnAuto, 'btnAuto');
  95.  
  96. btnArea.appendChild(btnS3);
  97. // btnArea.appendChild(btnFT);
  98. btnArea.appendChild(btnShow);
  99. btnArea.appendChild(btnAuto);
  100.  
  101. panel54.appendChild(aLP);
  102. panel54.appendChild(btnArea);
  103. panelArea.insertBefore(panel54, panelArea.children[1]);
  104. }
  105.  
  106. // 显示小轮盘
  107. function showLiteRoll() {
  108. // TODO 显示轮盘,手动-3
  109. }
  110. // 自动打开面板
  111. function fBtnShow() {
  112. VShow = !VShow;
  113. document.getElementById('btnShow').textContent = bool2txt(VShow) + '自动打开面板';
  114. saveCFG();
  115. }
  116. // 自动-3
  117. function fBtnAuto() {
  118. VAuto = !VAuto;
  119. document.getElementById('btnAuto').textContent = bool2txt(VAuto) + '自动每日-3';
  120. saveCFG();
  121. }
  122. // 显示布尔
  123. function bool2txt(bool) {
  124. return bool ? '【√】' : '【×】';
  125. }
  126. // 隐藏面板
  127. function switchPanel() {
  128. let panel1 = document.getElementById('panel54');
  129. let panel2 = document.getElementById('panelOri');
  130. if (panel1.style.display == 'none') {
  131. btnSwitch1.textContent = '今天你【-3】了吗 - By Chr_';
  132. panel1.style.display = 'block';
  133. panel2.style.display = 'none';
  134. } else {
  135. btnSwitch1.textContent = '关注重点';
  136. panel1.style.display = 'none';
  137. panel2.style.display = 'block';
  138. }
  139. }
  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.  
  149. t = GM_getValue('VCan3');
  150. VCan3 = Boolean(t);
  151. t = GM_getValue('VShow');
  152. VShow = Boolean(t);
  153. t = GM_getValue('VAuto');
  154. VAuto = Boolean(t);
  155. // 日期变更,重置VCan3
  156. let d = new Date();
  157. let day = d.getDate();
  158. let hour = d.getHours();
  159. if (day != VLast && hour >= 8) {
  160. VCan3 = true;
  161. VLast = day;
  162. }
  163. saveCFG();
  164. }
  165. // 保存设置
  166. function saveCFG() {
  167. GM_setValue('VLast', VLast);
  168. GM_setValue('VCan3', VCan3);
  169. GM_setValue('VShow', VShow);
  170. GM_setValue('VAuto', VAuto);
  171. }
  172. // 检查能否-3
  173. function checkZP() {
  174. GM_xmlhttpRequest({
  175. method: "GET",
  176. url: 'https://keylol.com/plugin.php?id=steamcn_lottery:view&lottery_id=43',
  177. onload: function (response) {
  178. if (response.responseText != null) {
  179. let t = response.responseText;
  180. let can = t.search('<button id="roll">抽奖</button>') != -1;
  181. console.log(can);
  182. if (!can) {
  183. disableS3();
  184. }
  185. saveCFG();
  186. }
  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. var sound = new Audio();
  201. sound.src = "https://blog.chrxw.com/usr/keylol/gas.mp3";
  202. sound.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: 'https://keylol.com/plugin.php?id=steamcn_lottery:view&lottery_id=43',
  216. onload: function (response) {
  217. if (response.status == 200) {
  218. let m = response.responseText.match(/plugin\.php\?id=steamcn_lottery:view&lottery_id=43&hash=(.+)&roll/);
  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. }
  229. } else {
  230. console.error('出错');
  231. }
  232. }
  233. });
  234. }
  235.  
  236. function roll(hash) {
  237. GM_xmlhttpRequest({
  238. method: "GET",
  239. url: 'https://keylol.com/plugin.php?id=steamcn_lottery:view&lottery_id=43&hash=' + hash + '&roll',
  240. onload: function (response) {
  241. if (response.status == 200) {
  242. console.log(response.responseText);
  243. } else {
  244. console.error('出错')
  245. }
  246. if (++v == 3) {
  247. disableS3();
  248. saveCFG();
  249. }
  250. }
  251. });
  252. }
  253. }