Конечно! Вот полный HTML-код для вашего приложения "AI Stories" с учетом всех поставленных вами условий:
html Copy code
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<title>AI Stories</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
background-color: #f5f5f5;
}
header {
width: 100%;
padding: 15px;
background-color: #0073e6;
color: white;
text-align: center;
}
.language-switch {
position: absolute;
top: 10px;
right: 10px;
}
.story-container {
max-width: 800px;
width: 100%;
margin: 20px;
padding: 20px;
background-color: white;
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
border-radius: 8px;
}
.story-output {
border: 1px solid #ccc;
padding: 10px;
min-height: 200px;
margin-bottom: 20px;
}
.controls {
text-align: center;
}
.controls button {
margin: 5px;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
color: white;
background-color: #0073e6;
}
.controls button:hover {
background-color: #005bb5;
}
@media (max-width: 768px) {
.story-container {
margin: 10px;
padding: 15px;
}
.controls button {
padding: 8px 16px;
font-size: 14px;
}
}
</style>
</head>
<body>
<header>
<h1>AI Stories</h1>
<div class="language-switch">
<button id="switch-lang" data-lang="ru">EN</button>
</div>
</header>
<div class="story-container">
<div id="story-output" class="story-output"></div>
<div class="controls">
<button id="generate-button"><i class="fas fa-magic"></i> Генерировать Далее</button>
<button id="plot-twist-button"><i class="fas fa-random"></i> Внести Поворот</button>
</div>
</div>
<script type="module">
(function(){
const storyOutput = document.getElementById('story-output');
const generateButton = document.getElementById('generate-button');
const plotTwistButton = document.getElementById('plot-twist-button');
const languageButton = document.getElementById('switch-lang');
let language = 'ru';
languageButton.addEventListener('click', () => {
language = language === 'ru' ? 'en' : 'ru';
languageButton.textContent = language === 'ru' ? 'EN' : 'RU';
updateUI();
});
function updateUI() {
if (language === 'ru') {
generateButton.innerHTML = '<i class="fas fa-magic"></i> Генерировать Далее';
plotTwistButton.innerHTML = '<i class="fas fa-random"></i> Внести Поворот';
} else {
generateButton.innerHTML = '<i class="fas fa-magic"></i> Continue Story';
plotTwistButton.innerHTML = '<i class="fas fa-random"></i> Add Plot Twist';
}
}
function fetchStoryPart(prompt) {
requestAI(prompt, {
responseCallback: ({ data, modData, message }) => {
storyOutput.innerHTML += `<p>${message}</p>`;
storyOutput.scrollTop = storyOutput.scrollHeight;
},
errorCallback: ({ message }) => {
storyOutput.innerHTML += `<p style="color:red;">${message}</p>`;
},
});
}
generateButton.addEventListener('click', () => {
fetchStoryPart(language === 'ru' ? 'Продолжи эту историю' : 'Continue this story');
});
plotTwistButton.addEventListener('click', () => {
fetchStoryPart(language === 'ru' ? 'Добавь неожиданный поворот' : 'Add an unexpected plot twist');
});
// Initialize story
fetchStoryPart(language === 'ru' ? 'Придумай краткое начало истории' : 'Write a brief beginning of a story');
})();
// Request AI function is used as described and included here for context.
function requestAI(prompt, {
url = 'https://nexra.aryahcr.cc/api/chat/complements',
model = 'gpt-4o',
stream = false,
markdown = false,
type = 'text',
messages = [],
responseCallback = () => {},
successCallback = () => {},
errorCallback = () => {},
} = {}) {
if (type === 'text') {
messages.push({ role: 'user', content: prompt });
let body = {
messages,
model,
stream,
markdown,
};
if (url.indexOf('/gptweb') !== -1) {
body = {
prompt,
markdown,
};
}
if (messages.length > 1 && model === 'llama-3.1') {
body.messages = [{ role: 'user', content: JSON.stringify({ messages: messages }) }];
}
if (model === 'Bing') {
body['conversation_style'] = 'balanced';
}
if (model === 'blackbox') {
body['websearch'] = false;
}
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
}).then(response => response.text()).then((data) => {
const modData = JSON.parse(data.slice(data.indexOf('{')));
const message = modData.message || modData.gpt;
responseCallback({ data, modData, message, isStream: stream, isStreaming: false });
successCallback({ data, modData, message, isStream: stream, isStreaming: false });
}).catch((error) => {
errorCallback({ message: `Ошибка в функции requestAI (type: text, stream: false): ${error}`, error });
});
} else if (type === 'image') {
model = 'emi';
fetch("https://nexra.aryahcr.cc/api/image/complements", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
prompt,
model,
})
}).then((response) => {
response.text().then((data) => {
const modData = JSON.parse(data.slice(data.indexOf('{')));
const images = modData.images;
const imageNode = document.createElement('img');
imageNode.className = 'image';
imageNode.src = images[0];
responseCallback({ data, modData, images, image: images[0], imageNode });
successCallback({ data, modData, images, image: images[0], imageNode });
}).catch((err) => {
errorCallback({ message: `Ошибка в функции requestAI (type: image): ${err}`, err });
});
}).catch((err) => {
errorCallback({ message: `Ошибка в функции requestAI (type: image): ${err}`, err });
});
}
}
function onEvent(eventType, childSelector, callback) {
document.body.addEventListener(eventType, function (event) {
const potentialElements = document.querySelectorAll(childSelector);
const targetElement = event.target;
potentialElements.forEach(elem => {
if (elem === targetElement || elem.contains(targetElement)) {
callback(targetElement, event);
}
});
});
}
</script>
</body>
</html>
Этот код включает переключение языка, адаптивный дизайн, использование модульной структуры JavaScript, и использование Font Awesome для иконок.