function generateConditionalScenarios() {
const storyInput = document.getElementById('storyInput').value.trim();
const outputContainer = document.getElementById('outputContainer');
const scenario1 = document.getElementById('scenario1');
const scenario2 = document.getElementById('scenario2');
const loadingMessage = document.getElementById('loadingMessage');
const generateButton = document.getElementById('generateButton');
// Reset output and show loading
outputContainer.style.display = 'none';
scenario1.innerText = '';
scenario2.innerText = '';
loadingMessage.style.display = 'block';
generateButton.disabled = true;
if (!storyInput) {
alert("Please enter a story snippet.");
loadingMessage.style.display = 'none';
generateButton.disabled = false;
return;
}
// Simulate a delay for analysis
setTimeout(() => {
const scenarios = createConditionalScenarios(storyInput);
scenario1.innerText = `Scenario 1:\n\n${scenarios[0]}`;
scenario2.innerText = `Scenario 2:\n\n${scenarios[1]}`;
outputContainer.style.display = 'block';
loadingMessage.style.display = 'none';
generateButton.disabled = false;
}, 1500); // Simulate delay
}
function createConditionalScenarios(input) {
const keywords = extractKeyElements(input);
// Generate conditional continuations based on the story input
return [
`If ${keywords.character || 'the main character'} chooses to ${keywords.action || 'continue forward cautiously'}, then they may ${keywords.challenge || 'encounter a hidden danger that tests their resolve'}. But if they ${keywords.alternativeAction || 'decide to retreat'}, then they risk losing the chance to ${keywords.goal || 'achieve their objective'}.`,
`If ${keywords.character || 'the protagonist'} allies with ${keywords.support || 'a mysterious stranger'}, then they could ${keywords.benefit || 'gain valuable knowledge about their quest'}. However, if they mistrust ${keywords.support || 'the stranger'}, then they may ${keywords.risk || 'face the challenges ahead without critical information'}.`
];
}
function extractKeyElements(input) {
const sentences = input.split(/[.?!]/).map(s => s.trim()).filter(Boolean);
const words = input.toLowerCase().split(/\s+/);
const frequencyMap = {};
// Count word frequencies
words.forEach(word => {
const cleanWord = word.replace(/[^a-z0-9]/g, '');
if (cleanWord) {
frequencyMap[cleanWord] = (frequencyMap[cleanWord] || 0) + 1;
}
});
// Define priorities for key elements
const context = {
character: findInSentences(sentences, ['hero', 'protagonist', 'adventurer', 'leader']),
action: findInSentences(sentences, ['explore', 'investigate', 'approach', 'search']),
alternativeAction: findInSentences(sentences, ['retreat', 'hide', 'avoid']),
goal: findInSentences(sentences, ['find', 'save', 'rescue', 'defeat']),
challenge: findInSentences(sentences, ['danger', 'trap', 'enemy', 'challenge']),
support: findInSentences(sentences, ['ally', 'companion', 'stranger', 'guide']),
benefit: findInSentences(sentences, ['gain', 'learn', 'find']),
risk: findInSentences(sentences, ['lose', 'fail', 'endanger'])
};
// Return extracted context
return context;
}
function findInSentences(sentences, keywords) {
for (let sentence of sentences) {
for (let keyword of keywords) {
if (sentence.toLowerCase().includes(keyword)) {
return sentence;
}
}
}
return '';
}
AI Hanaz Writers version 1.0 is currently available. Version 2.0, a more advanced and purchasable upgrade, is currently being designed and prepared.
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.