CF Gift Code

Auto enter Crossfire Gift Code.

  1. // ==UserScript==
  2. // @name CF Gift Code
  3. // @name:vi Gift Code CF
  4. // @namespace https://lelinhtinh.github.io
  5. // @description Auto enter Crossfire Gift Code.
  6. // @description:vi Tự động nhập Gift Code Đột Kích.
  7. // @version 1.3.0
  8. // @icon https://raw.githubusercontent.com/lelinhtinh/Userscript/master/cf_giftcode/icon.png
  9. // @author lelinhtinh
  10. // @oujs:author baivong
  11. // @license MIT; https://baivong.mit-license.org/license.txt
  12. // @match https://dotkich.goplay.vn/shop/giftcode
  13. // @noframes
  14. // @supportURL https://github.com/lelinhtinh/Userscript/issues
  15. // @run-at document-idle
  16. // @grant none
  17. // ==/UserScript==
  18.  
  19. function autoGiftcode() {
  20. if (!gcClipboard.length) return;
  21. const gc = gcClipboard.pop();
  22. console.log('Giftcode', gc);
  23.  
  24. $gcInput.val(gc);
  25. $gcInput.trigger('focus');
  26.  
  27. if (/\(.+?\)/.test(gc)) {
  28. const beginRange = gc.search(/\s?\(/);
  29. let endRange = gc.search(/\)\s/);
  30. endRange = endRange === -1 ? gc.search(/\)/) + 1 : endRange + 2;
  31. $gcInput.get(0).setSelectionRange(beginRange, endRange);
  32. return;
  33. }
  34.  
  35. sendGiftcode(gc);
  36. }
  37.  
  38. function sendGiftcode(gc) {
  39. $.ajax({
  40. url: '/api/ajaxapi/GiftCode/CheckCode',
  41. type: 'POST',
  42. dataType: 'json',
  43. contentType: 'application/json; charset=utf-8',
  44. processData: true,
  45. cache: false,
  46. data: JSON.stringify({
  47. GiftCode: gc,
  48. ServiceCode: 'CF',
  49. UserId: userId,
  50. UserName: userName,
  51. }),
  52. })
  53. .done((data) => {
  54. $helpText.append(`${gc}: ${data.message}\n`);
  55. })
  56. .always(autoGiftcode);
  57. }
  58.  
  59. function onSubmit(e) {
  60. e.preventDefault();
  61. e.stopPropagation();
  62. sendGiftcode($gcInput.val());
  63. }
  64.  
  65. function validateClipboard(clipText) {
  66. if (!clipText) return;
  67. const gcPattern = /\bCFS?[A-Z0-9]{2,}(\s?\(.+?\)\s?)?([A-Z0-9]+)?(\b|\B)/;
  68.  
  69. gcClipboard = clipText
  70. .split('\n')
  71. .map((gc) => gc.trim())
  72. .filter((gc) => gc && gcPattern.test(gc))
  73. .map((gc) => {
  74. gc = gc.match(gcPattern)[0];
  75. const mathPattern = /\s?\(([0-9+\-*/x:]{2,}[0-9]+)=\?\)\s?/;
  76. if (mathPattern.test(gc)) {
  77. return gc.replace(mathPattern, (m) => {
  78. let expression = m.match(mathPattern)[1];
  79. expression = expression.replaceAll('x', '*').replaceAll(':', '/');
  80. return eval(expression);
  81. });
  82. }
  83. return gc;
  84. });
  85.  
  86. if (!gcClipboard.length) {
  87. $helpText.removeClass('text-muted').addClass('text-danger').text('Clipboard không có Gift Code');
  88. return;
  89. }
  90.  
  91. autoGiftcode();
  92. }
  93.  
  94. let gcClipboard = [];
  95.  
  96. const $gcAutoBtn = $('<button />', {
  97. type: 'button',
  98. id: 'btn_giftcode_auto',
  99. class: 'btn btn-lg btn-primary btn-block mb-4',
  100. text: 'Tự động nhập từ bộ nhớ đệm',
  101. });
  102.  
  103. const $helpText = $('<pre />', {
  104. id: 'alert_giftcode_auto',
  105. class: 'form-text text-muted small',
  106. });
  107.  
  108. const $gcInput = $('#input_giftcode');
  109. const $gcForm = $gcInput.closest('form');
  110. const $gcSubmit = $gcForm.find('a');
  111.  
  112. const userInfo = $('[class="text-[#47bac1]"]').text().split(/:|-/);
  113. const userName = userInfo[4].trim();
  114. const userId = userInfo[6].trim();
  115. console.log(userName, userId);
  116.  
  117. $gcForm.append($helpText);
  118. $gcAutoBtn.insertBefore($gcInput);
  119.  
  120. $gcAutoBtn.on('click', (e) => {
  121. e.preventDefault();
  122.  
  123. $helpText.removeClass('text-danger').addClass('text-muted').empty();
  124. navigator.clipboard.readText().then((clipText) => validateClipboard(clipText));
  125. });
  126.  
  127. $gcInput.on('keydown', (e) => {
  128. if (e.which !== 13) return;
  129. onSubmit(e);
  130. });
  131. $gcSubmit.on('click', onSubmit);
  132. $gcForm.on('submit', onSubmit);
  133.  
  134. $('head').append(`<style>
  135. #myModal,
  136. #myModal + .modal-backdrop {
  137. display: none !important;
  138. }
  139. </style>`);

QingJ © 2025

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