Auto_Sub3

一键快乐-3

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

  1. // ==UserScript==
  2. // @name Auto_Sub3
  3. // @namespace https://blog.chrxw.com
  4. // @version 1.0
  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.style.cssText = 'width: auto;padding: 0 5px;';
  65. btnSwitch.addEventListener('click', switchPanel);
  66.  
  67. let panelArea = document.querySelector('.index_navi_left');
  68. let panelOri = document.querySelector('.index_left_detail');
  69. panelOri.id = 'panelOri'
  70.  
  71. let panel54 = genPanel('panel54');
  72.  
  73. let aLP = document.createElement('a');
  74. aLP.href = 'https://keylol.com/t571093-1-1';
  75. let img54 = document.createElement('img');
  76. img54.src = 'https://blog.chrxw.com/usr/keylol/index.png';
  77. img54.alt = '总之这里是54的名言';
  78. img54.style.cssText = 'float: right;margin-top: -28px;height: 100%;'
  79. aLP.appendChild(img54);
  80.  
  81. let btnArea = genDiv('btnArea');
  82. btnArea.style.cssText = 'width: 210px;text-align: center;margin-top: -10px;';
  83.  
  84. let btnS3 = genButton('【一键-3】', autoRoll, 'btnS3');
  85.  
  86. if (!VCan3) {
  87. btnS3.style.textDecoration = 'line-through';
  88. btnS3.textContent = '今天已经不能-3了';
  89. }
  90. // let btnFT = genButton('我要水贴', () => { window.location.href = 'https://keylol.com/forum.php?mod=post&action=newthread&fid=148' });
  91.  
  92. let btnShow = genButton(bool2txt(VShow) + '自动打开面板', fBtnShow, 'btnShow');
  93. let btnAuto = genButton(bool2txt(VAuto) + '自动每日-3', fBtnAuto, 'btnAuto');
  94.  
  95. btnArea.appendChild(btnS3);
  96. // btnArea.appendChild(btnFT);
  97. btnArea.appendChild(btnShow);
  98. btnArea.appendChild(btnAuto);
  99.  
  100. panel54.appendChild(aLP);
  101. panel54.appendChild(btnArea);
  102. panelArea.insertBefore(panel54, panelArea.children[1]);
  103. }
  104.  
  105. // 显示小轮盘
  106. function showLiteRoll() {
  107. // TODO 显示轮盘,手动-3
  108. }
  109. // 自动打开面板
  110. function fBtnShow() {
  111. VShow = !VShow;
  112. document.getElementById('btnShow').textContent = bool2txt(VShow) + '自动打开面板';
  113. saveCFG();
  114. }
  115. // 自动-3
  116. function fBtnAuto() {
  117. VAuto = !VAuto;
  118. document.getElementById('btnAuto').textContent = bool2txt(VAuto) + '自动每日-3';
  119. saveCFG();
  120. }
  121. // 显示布尔
  122. function bool2txt(bool) {
  123. return bool ? '【√】' : '【×】';
  124. }
  125. // 隐藏面板
  126. function switchPanel() {
  127. let panel1 = document.getElementById('panel54');
  128. let panel2 = document.getElementById('panelOri');
  129. if (panel1.style.display == 'none') {
  130. btnSwitch1.textContent = '今天你【-3】了吗 - By Chr_';
  131. panel1.style.display = 'block';
  132. panel2.style.display = 'none';
  133. } else {
  134. btnSwitch1.textContent = '关注重点';
  135. panel1.style.display = 'none';
  136. panel2.style.display = 'block';
  137. }
  138. }
  139.  
  140. // 读取设置
  141. function loadCFG() {
  142. let t = null;
  143. t = GM_getValue('VLast');
  144. VLast = t ? t : 0;
  145. t = GM_getValue('VCan3');
  146. VCan3 = Boolean(t);
  147. t = GM_getValue('VShow');
  148. VShow = Boolean(t);
  149. t = GM_getValue('VAuto');
  150. VAuto = Boolean(t);
  151. // 日期变更,重置VCan3
  152. let d = new Date().getDate();
  153. if (d != VLast) {
  154. VCan3 = true;
  155. VLast = d;
  156. }
  157. saveCFG();
  158. }
  159. // 保存设置
  160. function saveCFG() {
  161. GM_setValue('VLast', VLast);
  162. GM_setValue('VCan3', VCan3);
  163. GM_setValue('VShow', VShow);
  164. GM_setValue('VAuto', VAuto);
  165. }
  166. // 检查能否-3
  167. function checkZP() {
  168. GM_xmlhttpRequest({
  169. method: "GET",
  170. url: 'https://keylol.com/plugin.php?id=steamcn_lottery:view&lottery_id=43',
  171. onload: function (response) {
  172. if (response.responseText != null) {
  173. let t = response.responseText;
  174. let can = t.search('<button id="roll">抽奖</button>') != -1;
  175. console.log(can);
  176. VCan3 = 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. }
  191. // 自动-3
  192. function autoRoll() {
  193. try {
  194. var sound = new Audio();
  195. sound.src = "https://blog.chrxw.com/usr/keylol/gas.mp3";
  196. sound.play();
  197. } catch (e) {
  198. console.error(e);
  199. }
  200. if (!VCan3) {
  201. return;
  202. }
  203. let v = 0;
  204. roll();
  205. roll();
  206. roll();
  207. function roll() {
  208. GM_xmlhttpRequest({
  209. method: "GET",
  210. url: 'https://keylol.com/plugin.php?id=steamcn_lottery:view&lottery_id=43&hash=2a7522a6&roll',
  211. onload: function (response) {
  212. if (response.status == 200) {
  213. console.log(response.responseText);
  214. } else {
  215. console.log('出错')
  216. }
  217. if (++v == 3) {
  218. VCan3 = false;
  219. disableS3();
  220. saveCFG();
  221. }
  222. }
  223. });
  224. }
  225. }

QingJ © 2025

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