Что делает:
Автоматически создаёт сотни релевантных ключевых фраз по простым шаблонам — например, [купить|заказать] [умный дом|датчик открытия].
Экономит часы ручного подбора запросов, помогает охватить больше целевых фраз и ускоряет запуск рекламных кампаний в нишах вроде «умный дом», IoT и автоматизации.
SEO-специалистов, владельцев технических блогов и маркетологов, которые хотят быстро собрать семантическое ядро без Excel и рутины.
<div id="keyword-generator" style="background:#1e1e1e;padding:25px;border-radius:12px;box-shadow:0 4px 20px rgba(0,0,0,0.4);margin:30px 0;color:#e0e0e0;border:1px solid #333;">
<h2 style="color:#8a9dff;text-align:center;margin-bottom:20px;">🔮 Генератор ключевых слов</h2>
<div id="kg-error" style="display:none;background:#2d1a1a;color:#f8baba;padding:12px;border-radius:8px;margin-bottom:15px;border-left:4px solid #c62828;"></div>
<form id="kg-form">
<div style="margin-bottom:15px;">
<label style="display:block;font-weight:bold;margin-bottom:5px;color:#ccc;">Шаблоны:</label>
<textarea id="kg-templates" style="width:100%;padding:10px;border:1px solid #444;background:#2a2a2a;color:#e0e0e0;border-radius:6px;min-height:100px;font-family:monospace;" placeholder="[купить|заказать] [умный дом|ZigBee датчик]"></textarea>
</div>
<div style="margin-bottom:15px;">
<label style="display:block;font-weight:bold;margin-bottom:5px;color:#ccc;">Модификаторы (опционально):</label>
<textarea id="kg-modifiers" style="width:100%;padding:10px;border:1px solid #444;background:#2a2a2a;color:#e0e0e0;border-radius:6px;min-height:60px;font-family:monospace;" placeholder="дешево недорого"></textarea>
</div>
<button type="submit" style="background:linear-gradient(135deg,#6a5af9 0%,#8a9dff 100%);color:white;padding:10px 20px;border:none;border-radius:6px;cursor:pointer;font-weight:bold;transition:opacity 0.2s;opacity:0.95;">
🚀 Сгенерировать
</button>
<button type="button" onclick="kgLoadExamples()" style="margin-left:10px;background:#3a3a3a;color:#aaa;padding:10px 15px;border:1px solid #555;border-radius:6px;cursor:pointer;font-size:14px;">
📝 Примеры
</button>
</form>
<div id="kg-results" style="display:none;margin-top:20px;padding:15px;background:#252525;border-radius:8px;border:1px solid #444;">
<h3 style="color:#8a9dff;">Результат: <span id="kg-count">0</span> ключевых слов</h3>
<div id="kg-list" style="max-height:300px;overflow-y:auto;margin-top:10px;font-size:14px;line-height:1.7;color:#d0d0d0;"></div>
<button onclick="copyKeywords()" style="margin-top:12px;background:#2e7d32;color:white;border:none;padding:8px 15px;border-radius:4px;cursor:pointer;transition:background 0.2s;">
📋 Копировать всё
</button>
</div>
</div>
<script>
function kgLoadExamples() {
document.getElementById('kg-templates').value = `[купить|заказать|установить] [умный дом|систему умного дома|датчик открытия двери]
[умный дом] [для квартиры|для частного дома|под ключ]
[цена|стоимость|недорого] [на умный дом|на автоматизацию освещения]
[как сделать|как настроить|как подключить] [умный дом|ZigBee датчик]`;
document.getElementById('kg-modifiers').value = `дешево
недорого
со скидкой
в рассрочку
бесплатная доставка
гарантия`;
}
document.getElementById('kg-form').addEventListener('submit', async (e) => {
e.preventDefault();
const templates = document.getElementById('kg-templates')?.value?.trim() || '';
const modifiers = document.getElementById('kg-modifiers')?.value?.trim() || '';
if (!templates) {
showError('Добавьте хотя бы один шаблон!');
return;
}
try {
const response = await fetch('/generate.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ templates, modifiers, cities: '', seasons: '' })
});
const data = await response.json();
if (data.error) {
showError(data.error);
} else if (data.success) {
showResults(data.keywords, data.stats.total);
} else {
showError('Неожиданный ответ от сервера');
}
} catch (err) {
console.error('Ошибка:', err);
showError('Ошибка соединения с сервером');
}
});
function showError(msg) {
const el = document.getElementById('kg-error');
el.textContent = msg;
el.style.display = 'block';
setTimeout(() => el.style.display = 'none', 5000);
}
function showResults(keywords, total) {
const listEl = document.getElementById('kg-list');
listEl.innerHTML = keywords.map((kw, i) => `<div>${i + 1}. ${kw}</div>`).join('');
document.getElementById('kg-count').textContent = total;
document.getElementById('kg-results').style.display = 'block';
}
function copyKeywords() {
const text = Array.from(document.querySelectorAll('#kg-list div'))
.map(el => el.textContent.replace(/^\d+\.\s/, ''))
.join('\n');
if (text) {
navigator.clipboard.writeText(text).then(() => {
alert('✅ Ключевые слова скопированы!');
});
}
}
</script>
<?php
// /var/www/blog/public_html/tools/generate.php
header('Content-Type: application/json; charset=utf-8');
// Вставь сюда ВСЮ логику из keywords_logic.php
function generateKeywords($template) {
$patterns = [];
$result = [];
preg_match_all('/\[([^\]]+)\]/', $template, $matches);
if (empty($matches[1])) return [$template];
foreach ($matches[1] as $match) {
$patterns[] = array_map('trim', explode('|', $match));
}
$combinations = cartesianProduct($patterns);
foreach ($combinations as $combination) {
$keyword = $template;
foreach ($combination as $index => $value) {
$keyword = preg_replace('/\[[^\]]+\]/', $value, $keyword, 1);
}
$result[] = trim($keyword);
}
return $result;
}
function cartesianProduct($arrays) {
$result = [[]];
foreach ($arrays as $array) {
$temp = [];
foreach ($result as $product) {
foreach ($array as $item) {
$temp[] = array_merge($product, [$item]);
}
}
$result = $temp;
}
return $result;
}
function generateFromTemplates($templates) {
$keywords = [];
foreach ($templates as $template) {
$keywords = array_merge($keywords, generateKeywords($template));
}
return array_values(array_unique(array_filter($keywords)));
}
function applyModifiers($keywords, $modifiers) {
$result = $keywords;
foreach ($keywords as $kw) {
foreach ($modifiers as $mod) {
$result[] = $kw . ' ' . $mod;
$result[] = $mod . ' ' . $kw;
}
}
return array_values(array_unique($result));
}
// Получаем данные
$templates = array_filter(array_map('trim', explode("\n", $_POST['templates'] ?? '')));
$modifiers = array_filter(array_map('trim', explode("\n", $_POST['modifiers'] ?? '')));
$cities = array_filter(array_map('trim', explode("\n", $_POST['cities'] ?? '')));
$seasons = array_filter(array_map('trim', explode("\n", $_POST['seasons'] ?? '')));
if (empty($templates)) {
echo json_encode(['error' => 'Добавьте хотя бы один шаблон!']);
exit;
}
try {
$keywords = generateFromTemplates($templates);
if (!empty($modifiers)) $keywords = applyModifiers($keywords, $modifiers);
if (!empty($cities)) $keywords = applyModifiers($keywords, $cities);
if (!empty($seasons)) $keywords = applyModifiers($keywords, $seasons);
sort($keywords);
echo json_encode([
'success' => true,
'keywords' => $keywords,
'stats' => [
'total' => count($keywords),
'templates' => count($templates),
'modifiers' => count($modifiers),
'cities' => count($cities),
'seasons' => count($seasons)
]
]);
} catch (Exception $e) {
echo json_encode(['error' => 'Ошибка генерации: ' . $e->getMessage()]);
}
?>
Комментарии
Пока нет комментариев. Будьте первым!