键盘暴打小苹果

使用'D' 'F' 'J' 'K'四个键位暴打小苹果

当前为 2022-01-02 提交的版本,查看 最新版本

  1. /* eslint-disable no-multi-spaces */
  2.  
  3. // ==UserScript==
  4. // @name Keyboard support for http://game.hg0355.com/game/xpg/
  5. // @name:zh-CN 键盘暴打小苹果
  6. // @namespace SP_XPG_WITH_KEYBOARD
  7. // @version 0.1
  8. // @description Use 'D' 'F' 'J' 'K' to beat the apples
  9. // @description:zh-CN 使用'D' 'F' 'J' 'K'四个键位暴打小苹果
  10. // @author PY-DNG
  11. // @license MIT
  12. // @match http*://game.hg0355.com/game/xpg/
  13. // @icon https://api.iowen.cn/favicon/get.php?url=http://game.hg0355.com/game/xpg/
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. (function main() {
  21. if (typeof (GameLayerBG) != 'object') {
  22. setTimeout(main, 100);
  23. return false;
  24. }
  25.  
  26. document.addEventListener('keydown', function(e) {
  27. const key = e.key.toLowerCase();
  28. if (key === 'enter') {closeWelcomeLayer();}
  29. if (!['d', 'f', 'j', 'k'].includes(key)) {return false;}
  30.  
  31. // Get block
  32. let number = 0;
  33. switch(key) {
  34. case 'd':
  35. number = _gameBBListIndex * 4 + 4;
  36. break;
  37. case 'f':
  38. number = _gameBBListIndex * 4 + 5;
  39. break;
  40. case 'j':
  41. number = _gameBBListIndex * 4 + 6;
  42. break;
  43. case 'k':
  44. number = _gameBBListIndex * 4 + 7;
  45. break;
  46. }
  47. const id = '#GameLayer{A}-{B}'.replace('{A}', Math.floor(number / 40) % 2 === 0 ? '1' : '2').replace('{B}', (number % 40).toString());
  48. const tar = document.querySelector(id);
  49. console.log(number, id);
  50.  
  51. // Create event
  52. const evtOptions = {
  53. clientX: Math.round((touchArea[0] + touchArea[1]) / 2),
  54. clientY: Math.round((touchArea[0] + touchArea[1]) / 2),
  55. target: tar
  56. }
  57.  
  58. // Dispatch event
  59. GameLayerBG.onmousedown(evtOptions);
  60. console.log(_gameBBList[_gameBBListIndex]);
  61.  
  62. // Using keyboard, then display keyboard text in final page
  63. window.shareText = _shareText;
  64. });
  65.  
  66. function _shareText(score) {
  67. cookie('score2', score, 100);
  68. if (score <= 49) return '呵呵!我吃掉了' + score + '个小苹果!<br/>亲,还得加油哦!<br/><span style="font-size:0.5em">(电脑端键盘操作)</span>';
  69. if (score <= 99) return '酷!我吃掉了' + score + '个小苹果!<br/>亲,不错哦!<br/><span style="font-size:0.5em">(电脑端键盘操作)</span>';
  70. if (score <= 149) return '帅呆了!我吃掉了' + score + '个小苹果!<br/>亲,爱死你了!<br/><span style="font-size:0.5em">(电脑端键盘操作)</span>';
  71. if (score <= 199) return '太牛了!我吃掉了' + score + '个小苹果!<br/>亲,奥巴马和金正恩都惊呆了!<br/><span style="font-size:0.5em">(电脑端键盘操作)</span>';
  72. if (score >= 200) return '【年度科幻片】您在20秒内恰了' + score + '个小苹果!<br/><span style="font-size:0.2em"><del>您入门了</del></span><br/><span style="font-size:0.5em">(电脑端键盘操作)</span>';
  73. }
  74. }) ();
  75. })();