Castle Clash Code Selector (Multilingual & Optimized)

Multilingual promo-code selector and language switcher for Castle Clash

  1. // ==UserScript==
  2. // @name Castle Clash Code Selector (Multilingual & Optimized)
  3. // @name:en Castle Clash Code Selector (Multilingual & Optimized)
  4. // @name:ru Выбор промокода Castle Clash (многоязычный и оптимизированный)
  5. // @namespace http://tampermonkey.net/
  6. // @version 1.8.5
  7. // @description Multilingual promo-code selector and language switcher for Castle Clash
  8. // @description:en Multilingual promo-code selector and language switcher for Castle Clash
  9. // @description:ru Многоязычный выбор промокодов и переключатель языка для Castle Clash
  10. // @match https://castleclash.igg.com/event/cdkey*
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. // --- Configuration ---
  20. const CODES = [
  21. { id: '1', code: 'QYFUF6' },
  22. { id: '2', code: 'NYQZKQ' },
  23. { id: '3', code: 'KJYJT3' },
  24. { id: '4', code: 'DN72M7' },
  25. { id: '5', code: 'GDEJ9E' },
  26. { id: '6', code: 'ZRX6NB' } // Новый код
  27.  
  28. ];
  29.  
  30. const TRANSLATIONS = {
  31. en: { title: 'Select a promo code:', btnPrefix: '', switchLabel: 'Language:' },
  32. ru: { title: 'Выберите промокод:', btnPrefix: '', switchLabel: 'Язык:' }
  33. };
  34.  
  35. // --- Helpers ---
  36. const params = new URLSearchParams(location.search);
  37. const currentLang = params.get('lang') in TRANSLATIONS ? params.get('lang') : 'en';
  38. const t = TRANSLATIONS[currentLang];
  39.  
  40. const basePath = location.origin + '/event/cdkey';
  41. function langUrl(lang) {
  42. return `${basePath}?lang=${lang}`;
  43. }
  44.  
  45. // --- Styles ---
  46. const css = `
  47. #cc-selector { position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  48. background: #fff; border: 1px solid #ccc; padding: 15px; z-index:9999;
  49. box-shadow:0 4px 10px rgba(0,0,0,0.2); border-radius:8px; font-family:sans-serif; }
  50. #cc-selector h3 { margin:0 0 10px; font-size:16px; }
  51. .cc-btn { margin:4px; padding:8px 12px; background:#007bff; color:#fff;
  52. border:none; border-radius:4px; cursor:pointer; font-size:14px; }
  53. .cc-btn:hover { background:#0056b3; }
  54. #cc-language { margin-bottom:8px; display:flex; align-items:center; gap:6px; }
  55. #cc-language a { text-decoration:none; font-size:14px; color:#007bff; }
  56. #cc-language a.active { font-weight:bold; cursor:default; }
  57. `;
  58. const styleNode = document.createElement('style');
  59. styleNode.textContent = css;
  60. document.head.append(styleNode);
  61.  
  62. // --- UI Creation ---
  63. function buildUI() {
  64. const container = document.createElement('div');
  65. container.id = 'cc-selector';
  66.  
  67. // Language Switcher
  68. const langDiv = document.createElement('div');
  69. langDiv.id = 'cc-language';
  70. langDiv.innerHTML = `<span>${t.switchLabel}</span>`;
  71. Object.keys(TRANSLATIONS).forEach(lang => {
  72. const a = document.createElement('a');
  73. a.href = langUrl(lang);
  74. a.textContent = lang.toUpperCase();
  75. if (lang === currentLang) a.classList.add('active');
  76. langDiv.append(a);
  77. });
  78. container.append(langDiv);
  79.  
  80. // Title
  81. const titleEl = document.createElement('h3');
  82. titleEl.textContent = t.title;
  83. container.append(titleEl);
  84.  
  85. // Buttons
  86. CODES.forEach(({ id, code }) => {
  87. const btn = document.createElement('button');
  88. btn.className = 'cc-btn';
  89. btn.textContent = `${id}. ${code}`;
  90. btn.addEventListener('click', () => insertCode(code));
  91. container.append(btn);
  92. });
  93.  
  94. document.body.append(container);
  95. }
  96.  
  97. // --- Insert & Trigger ---
  98. function insertCode(code) {
  99. const input = document.querySelector('#cdkey');
  100. if (input) {
  101. input.value = code;
  102. input.dispatchEvent(new Event('input', { bubbles: true }));
  103. }
  104. }
  105.  
  106. // --- Init ---
  107. window.addEventListener('load', buildUI);
  108. })();