Spaces:
Running
Running
File size: 6,219 Bytes
de423ab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | <!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>ICA Code Wizard 🔮</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial;
padding: 24px;
max-width: 640px;
margin: 36px auto;
color: #111;
background: #f7f7f8;
}
.card {
background: #fff;
padding: 18px;
border-radius: 12px;
box-shadow: 0 6px 18px rgba(0,0,0,0.06);
}
label { display:block; margin-bottom:8px; font-weight:600 }
input[type="text"] {
width:100%;
padding:10px 12px;
font-size:16px;
border:1px solid #ddd;
border-radius:8px;
box-sizing:border-box;
}
.row { display:flex; gap:8px; margin-top:12px; }
button {
padding:10px 14px;
font-size:15px;
border-radius:8px;
border: none;
cursor: pointer;
background:#2563eb;
color:white;
}
button.secondary { background:#6b7280; }
pre {
background:#111827;
color:#f9fafb;
padding:12px;
border-radius:8px;
overflow-x:auto;
margin-top:12px;
font-size:16px;
}
.hint { color:#6b7280; margin-top:8px; font-size:13px }
</style>
</head>
<body>
<div class="card">
<h1>ICA Code Wizard 🔮</h1>
<p class="hint">Введи магическую переменную (например <code>0170</code>) и нажми «Сгенерировать».</p>
<label for="inputVar">Магическая переменная 🔢✨</label>
<input id="inputVar" type="text" value="0170" />
<div class="row">
<button id="btnGen">✨ Сгенерировать</button>
<button id="btnCopy" class="secondary" title="Копировать результат">📋 Копировать</button>
<button id="btnAuto" class="secondary" title="Генерировать автоматически при загрузке">⚡ Авто</button>
</div>
<label style="margin-top:14px">Результат</label>
<pre id="result">✨ Жду твою магию...</pre>
<p class="hint">Магический алгоритм: <code>SHA-256("C673_ICA" + ввод + MM + DD)</code>, затем берем подстроку хэша с позиции <code>день+1</code> по <code>день+13</code> ✨</p>
</div>
<script>
async function sha256Hex(message) {
const data = new TextEncoder().encode(message);
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
const bytes = new Uint8Array(hashBuffer);
return Array.from(bytes, b => ("0" + b.toString(16)).slice(-2)).join("");
}
function getMMDD(date = new Date()) {
const mm = String(date.getMonth() + 1).padStart(2, "0");
const dd = String(date.getDate()).padStart(2, "0");
return { mm, dd, date };
}
async function generateCode(inputValue) {
// prepare input
const trimmed = String(inputValue ?? "").trim();
if (trimmed.length === 0) {
throw new Error("Пустая строка. Введите переменную.");
}
const { mm, dd, date } = getMMDD();
const base = "C673_ICA" + trimmed + mm + dd;
const hex = await sha256Hex(base);
// расчет индексов как в оригинале: substring(day+1, day+13)
// substring uses indices where end is exclusive.
const day = date.getDate();
const start = day + 1;
const end = day + 13;
// защитимся от выхода за длину
const safeStart = Math.max(0, Math.min(start, hex.length));
const safeEnd = Math.max(safeStart, Math.min(end, hex.length));
const res = hex.substring(safeStart, safeEnd);
return { base, hex, res, mm, dd, start: safeStart, end: safeEnd };
}
const inputEl = document.getElementById("inputVar");
const resEl = document.getElementById("result");
const btnGen = document.getElementById("btnGen");
const btnCopy = document.getElementById("btnCopy");
const btnAuto = document.getElementById("btnAuto");
let autoOn = false;
async function doGenerate(showErrors = true) {
try {
btnGen.disabled = true;
resEl.textContent = "Генерация…";
const info = await generateCode(inputEl.value);
resEl.textContent = info.res || "Пустой результат (проверь ввод/дату)";
btnGen.disabled = false;
return info;
} catch (e) {
btnGen.disabled = false;
resEl.textContent = "Ошибка: " + (e.message || e);
if (showErrors) console.error(e);
}
}
btnGen.addEventListener("click", () => doGenerate());
btnCopy.addEventListener("click", async () => {
const text = resEl.textContent || "";
if (!text || text.startsWith("Ошибка") || text === "Генерация…") {
return;
}
try {
await navigator.clipboard.writeText(text);
btnCopy.textContent = "Скопировано!";
setTimeout(() => btnCopy.textContent = "Копировать", 1400);
} catch {
btnCopy.textContent = "Не удалось";
setTimeout(() => btnCopy.textContent = "Копировать", 1400);
}
});
btnAuto.addEventListener("click", () => {
autoOn = !autoOn;
btnAuto.textContent = autoOn ? "Авто: вкл" : "Авто";
if (autoOn) doGenerate(false);
});
// allow pressing Enter in input to generate
inputEl.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
e.preventDefault();
doGenerate();
}
});
// generate on load once
window.addEventListener("load", () => {
// короткая задержка для красоты
setTimeout(() => doGenerate(false), 120);
});
</script>
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
</body>
</html>
|