question-answer / index.html
MahmoudFahmy's picture
undefined - Initial Deployment
6fa4455 verified
Raw History Blame Contribute Delete
24.3 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Q&A Platform</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.question-card {
transition: all 0.3s ease;
transform-style: preserve-3d;
}
.question-card.flip {
transform: rotateY(180deg);
}
.question-front, .question-back {
backface-visibility: hidden;
position: absolute;
width: 100%;
height: 100%;
}
.question-back {
transform: rotateY(180deg);
}
.vote-btn {
transition: all 0.2s ease;
}
.vote-btn:hover {
transform: translateY(-2px);
}
.progress-bar {
transition: width 0.5s ease;
}
.fade-in {
animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
</style>
</head>
<body class="bg-gray-100 min-h-screen font-sans">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="mb-8 text-center">
<div class="flex justify-between items-center mb-4">
<div class="flex items-center space-x-2">
<span class="text-sm font-medium text-gray-700">English</span>
<label class="relative inline-flex items-center cursor-pointer">
<input id="language-toggle" type="checkbox" class="sr-only peer">
<div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
<span class="text-sm font-medium text-gray-700">العربية</span>
</div>
<div>
<select id="topic-selector" class="bg-gray-50 border border-gray-300 text-gray-700 text-sm rounded-lg focus:ring-indigo-500 focus:border-indigo-500 p-2">
<option value="all">All Topics</option>
<option value="Geography">Geography</option>
<option value="Science">Science</option>
<option value="Art">Art</option>
<option value="Chemistry">Chemistry</option>
<option value="History">History</option>
</select>
</div>
</div>
<h1 class="text-4xl font-bold text-indigo-700 mb-2">Q&A Explorer</h1>
<p class="text-gray-600">Navigate through questions and provide your feedback</p>
</header>
<!-- Progress Bar -->
<div class="mb-6 bg-gray-200 rounded-full h-4">
<div id="progress" class="progress-bar bg-indigo-600 h-4 rounded-full" style="width: 0%"></div>
</div>
<!-- Main Content -->
<div class="max-w-3xl mx-auto">
<!-- Question Card Container -->
<div class="relative h-96 mb-8 perspective-1000">
<div id="question-card" class="question-card relative w-full h-full">
<!-- Front Side (Question) -->
<div class="question-front bg-white rounded-xl shadow-lg p-6 flex flex-col">
<div class="flex justify-between items-center mb-4">
<span id="question-number" class="text-sm font-medium text-indigo-600 bg-indigo-50 px-3 py-1 rounded-full">Question 1 of 5</span>
<span id="category" class="text-sm font-medium text-gray-500 bg-gray-100 px-3 py-1 rounded-full">General</span>
</div>
<div class="flex-grow flex items-center">
<h2 id="question-text" class="text-2xl font-semibold text-gray-800 text-center w-full">Loading question...</h2>
</div>
<div class="mt-auto pt-4 border-t border-gray-100">
<button id="show-answer-btn" class="w-full py-3 bg-indigo-600 text-white rounded-lg font-medium hover:bg-indigo-700 transition">
Show Answer <i class="fas fa-chevron-down ml-2"></i>
</button>
</div>
</div>
<!-- Back Side (Answer) -->
<div class="question-back bg-white rounded-xl shadow-lg p-6 flex flex-col">
<div class="flex justify-between items-center mb-4">
<span id="answer-number" class="text-sm font-medium text-indigo-600 bg-indigo-50 px-3 py-1 rounded-full">Question 1 of 5</span>
<span id="answer-category" class="text-sm font-medium text-gray-500 bg-gray-100 px-3 py-1 rounded-full">General</span>
</div>
<div class="flex-grow flex flex-col justify-center">
<h3 class="text-lg font-medium text-gray-700 mb-2">Answer:</h3>
<p id="answer-text" class="text-gray-800">Loading answer...</p>
</div>
<div class="mt-auto pt-4 border-t border-gray-100">
<!-- Voting Buttons -->
<div class="flex justify-between space-x-4">
<button id="accept-btn" class="vote-btn flex-grow py-3 bg-green-100 text-green-700 rounded-lg font-medium hover:bg-green-200 flex items-center justify-center">
<i class="fas fa-check-circle mr-2"></i> Accept
</button>
<button id="rephrase-btn" class="vote-btn flex-grow py-3 bg-yellow-100 text-yellow-700 rounded-lg font-medium hover:bg-yellow-200 flex items-center justify-center">
<i class="fas fa-edit mr-2"></i> Rephrase
</button>
<button id="refuse-btn" class="vote-btn flex-grow py-3 bg-red-100 text-red-700 rounded-lg font-medium hover:bg-red-200 flex items-center justify-center">
<i class="fas fa-times-circle mr-2"></i> Refuse
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Navigation Buttons -->
<div class="flex justify-between">
<button id="prev-btn" class="px-6 py-3 bg-gray-200 text-gray-700 rounded-lg font-medium hover:bg-gray-300 transition disabled:opacity-50 disabled:cursor-not-allowed" disabled>
<i class="fas fa-arrow-left mr-2"></i> Previous
</button>
<button id="next-btn" class="px-6 py-3 bg-indigo-600 text-white rounded-lg font-medium hover:bg-indigo-700 transition">
Next <i class="fas fa-arrow-right ml-2"></i>
</button>
</div>
<!-- Stats -->
<div class="mt-8 bg-white rounded-xl shadow-lg p-6">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Your Feedback Summary</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="bg-green-50 p-4 rounded-lg">
<div class="flex items-center">
<div class="p-3 rounded-full bg-green-100 text-green-600 mr-4">
<i class="fas fa-check-circle text-xl"></i>
</div>
<div>
<p class="text-sm text-gray-500">Accepted</p>
<p id="accepted-count" class="text-2xl font-bold text-green-600">0</p>
</div>
</div>
</div>
<div class="bg-yellow-50 p-4 rounded-lg">
<div class="flex items-center">
<div class="p-3 rounded-full bg-yellow-100 text-yellow-600 mr-4">
<i class="fas fa-edit text-xl"></i>
</div>
<div>
<p class="text-sm text-gray-500">Rephrased</p>
<p id="rephrased-count" class="text-2xl font-bold text-yellow-600">0</p>
</div>
</div>
</div>
<div class="bg-red-50 p-4 rounded-lg">
<div class="flex items-center">
<div class="p-3 rounded-full bg-red-100 text-red-600 mr-4">
<i class="fas fa-times-circle text-xl"></i>
</div>
<div>
<p class="text-sm text-gray-500">Refused</p>
<p id="refused-count" class="text-2xl font-bold text-red-600">0</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Sample questions data
const questions = [
{
id: 1,
question: "What is the capital of France?",
question_ar: "ما هي عاصمة فرنسا؟",
answer: "The capital of France is Paris.",
answer_ar: "عاصمة فرنسا هي باريس.",
category: "Geography"
},
{
id: 2,
question: "What is the largest planet in our solar system?",
question_ar: "ما هو أكبر كوكب في نظامنا الشمسي؟",
answer: "Jupiter is the largest planet in our solar system.",
answer_ar: "المشتري هو أكبر كوكب في نظامنا الشمسي.",
category: "Science"
},
{
id: 3,
question: "Who painted the Mona Lisa?",
question_ar: "من رسم الموناليزا؟",
answer: "The Mona Lisa was painted by Leonardo da Vinci.",
answer_ar: "الموناليزا رسمها ليوناردو دا فينشي.",
category: "Art"
},
{
id: 4,
question: "What is the chemical symbol for gold?",
question_ar: "ما هو الرمز الكيميائي للذهب؟",
answer: "The chemical symbol for gold is Au.",
answer_ar: "الرمز الكيميائي للذهب هو Au.",
category: "Chemistry"
},
{
id: 5,
question: "In which year did World War II end?",
question_ar: "في أي عام انتهت الحرب العالمية الثانية؟",
answer: "World War II ended in 1945.",
answer_ar: "انتهت الحرب العالمية الثانية عام 1945.",
category: "History"
}
];
// Current question index
let currentQuestionIndex = 0;
let totalQuestions = questions.length;
// User responses
const userResponses = Array(totalQuestions).fill(null);
// DOM elements
const questionCard = document.getElementById('question-card');
const questionText = document.getElementById('question-text');
const answerText = document.getElementById('answer-text');
const questionNumber = document.getElementById('question-number');
const answerNumber = document.getElementById('answer-number');
const category = document.getElementById('category');
const answerCategory = document.getElementById('answer-category');
const showAnswerBtn = document.getElementById('show-answer-btn');
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const acceptBtn = document.getElementById('accept-btn');
const rephraseBtn = document.getElementById('rephrase-btn');
const refuseBtn = document.getElementById('refuse-btn');
const progressBar = document.getElementById('progress');
const acceptedCount = document.getElementById('accepted-count');
const rephrasedCount = document.getElementById('rephrased-count');
const refusedCount = document.getElementById('refused-count');
// Current language (false = English, true = Arabic)
let currentLanguage = false;
let filteredQuestions = [...questions];
// Initialize the app
function init() {
loadQuestion(currentQuestionIndex);
updateProgress();
updateStats();
// Event listeners
showAnswerBtn.addEventListener('click', toggleAnswer);
prevBtn.addEventListener('click', goToPreviousQuestion);
nextBtn.addEventListener('click', goToNextQuestion);
acceptBtn.addEventListener('click', () => vote('accept'));
rephraseBtn.addEventListener('click', () => vote('rephrase'));
refuseBtn.addEventListener('click', () => vote('refuse'));
// Language toggle
document.getElementById('language-toggle').addEventListener('change', toggleLanguage);
// Topic selector
document.getElementById('topic-selector').addEventListener('change', filterByTopic);
}
// Toggle between English and Arabic
function toggleLanguage() {
currentLanguage = !currentLanguage;
loadQuestion(currentQuestionIndex);
// Update UI elements
const title = document.querySelector('header h1');
const subtitle = document.querySelector('header p');
const showBtn = document.getElementById('show-answer-btn');
if (currentLanguage) {
title.textContent = "مستكشف الأسئلة والأجوبة";
subtitle.textContent = "تصفح الأسئلة وقدم ملاحظاتك";
showBtn.innerHTML = questionCard.classList.contains('flip') ?
'عرض السؤال <i class="fas fa-chevron-up ml-2"></i>' :
'عرض الإجابة <i class="fas fa-chevron-down ml-2"></i>';
} else {
title.textContent = "Q&A Explorer";
subtitle.textContent = "Navigate through questions and provide your feedback";
showBtn.innerHTML = questionCard.classList.contains('flip') ?
'Show Question <i class="fas fa-chevron-up ml-2"></i>' :
'Show Answer <i class="fas fa-chevron-down ml-2"></i>';
}
}
// Filter questions by selected topic
function filterByTopic() {
const topic = document.getElementById('topic-selector').value;
if (topic === 'all') {
filteredQuestions = [...questions];
} else {
filteredQuestions = questions.filter(q => q.category === topic);
}
currentQuestionIndex = 0;
totalQuestions = filteredQuestions.length;
userResponses = Array(totalQuestions).fill(null);
loadQuestion(currentQuestionIndex);
updateStats();
}
// Load question data
function loadQuestion(index) {
const question = filteredQuestions[index];
if (currentLanguage) {
questionText.textContent = question.question_ar;
answerText.textContent = question.answer_ar;
questionNumber.textContent = `سؤال ${index + 1} من ${totalQuestions}`;
answerNumber.textContent = `سؤال ${index + 1} من ${totalQuestions}`;
// Update button texts
acceptBtn.innerHTML = '<i class="fas fa-check-circle mr-2"></i> قبول';
rephraseBtn.innerHTML = '<i class="fas fa-edit mr-2"></i> إعادة صياغة';
refuseBtn.innerHTML = '<i class="fas fa-times-circle mr-2"></i> رفض';
prevBtn.innerHTML = '<i class="fas fa-arrow-left mr-2"></i> السابق';
nextBtn.innerHTML = 'التالي <i class="fas fa-arrow-right ml-2"></i>';
} else {
questionText.textContent = question.question;
answerText.textContent = question.answer;
questionNumber.textContent = `Question ${index + 1} of ${totalQuestions}`;
answerNumber.textContent = `Question ${index + 1} of ${totalQuestions}`;
// Update button texts
acceptBtn.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Accept';
rephraseBtn.innerHTML = '<i class="fas fa-edit mr-2"></i> Rephrase';
refuseBtn.innerHTML = '<i class="fas fa-times-circle mr-2"></i> Refuse';
prevBtn.innerHTML = '<i class="fas fa-arrow-left mr-2"></i> Previous';
nextBtn.innerHTML = 'Next <i class="fas fa-arrow-right ml-2"></i>';
}
category.textContent = question.category;
answerCategory.textContent = question.category;
// Reset card to front
if (questionCard.classList.contains('flip')) {
questionCard.classList.remove('flip');
}
// Update navigation buttons
prevBtn.disabled = index === 0;
// Highlight previously selected vote
resetVoteButtons();
if (userResponses[index] !== null) {
highlightSelectedVote(index);
}
// Add fade-in animation
questionCard.classList.add('fade-in');
setTimeout(() => questionCard.classList.remove('fade-in'), 500);
}
// Toggle between question and answer
function toggleAnswer() {
questionCard.classList.toggle('flip');
if (currentLanguage) {
if (questionCard.classList.contains('flip')) {
showAnswerBtn.innerHTML = 'عرض السؤال <i class="fas fa-chevron-up ml-2"></i>';
} else {
showAnswerBtn.innerHTML = 'عرض الإجابة <i class="fas fa-chevron-down ml-2"></i>';
}
} else {
if (questionCard.classList.contains('flip')) {
showAnswerBtn.innerHTML = 'Show Question <i class="fas fa-chevron-up ml-2"></i>';
} else {
showAnswerBtn.innerHTML = 'Show Answer <i class="fas fa-chevron-down ml-2"></i>';
}
}
}
// Navigate to previous question
function goToPreviousQuestion() {
if (currentQuestionIndex > 0) {
currentQuestionIndex--;
loadQuestion(currentQuestionIndex);
}
}
// Navigate to next question
function goToNextQuestion() {
if (currentQuestionIndex < totalQuestions - 1) {
currentQuestionIndex++;
loadQuestion(currentQuestionIndex);
} else {
// End of questions - could show completion message
alert('You have completed all questions!');
}
}
// Handle voting
function vote(type) {
userResponses[currentQuestionIndex] = type;
updateStats();
highlightSelectedVote(currentQuestionIndex);
// Auto-advance to next question after voting
setTimeout(() => {
if (currentQuestionIndex < totalQuestions - 1) {
currentQuestionIndex++;
loadQuestion(currentQuestionIndex);
}
}, 500);
}
// Highlight the selected vote button
function highlightSelectedVote(index) {
resetVoteButtons();
const response = userResponses[index];
if (response === 'accept') {
acceptBtn.classList.remove('bg-green-100', 'text-green-700');
acceptBtn.classList.add('bg-green-500', 'text-white');
} else if (response === 'rephrase') {
rephraseBtn.classList.remove('bg-yellow-100', 'text-yellow-700');
rephraseBtn.classList.add('bg-yellow-500', 'text-white');
} else if (response === 'refuse') {
refuseBtn.classList.remove('bg-red-100', 'text-red-700');
refuseBtn.classList.add('bg-red-500', 'text-white');
}
}
// Reset all vote buttons to default state
function resetVoteButtons() {
acceptBtn.className = 'vote-btn flex-grow py-3 bg-green-100 text-green-700 rounded-lg font-medium hover:bg-green-200 flex items-center justify-center';
rephraseBtn.className = 'vote-btn flex-grow py-3 bg-yellow-100 text-yellow-700 rounded-lg font-medium hover:bg-yellow-200 flex items-center justify-center';
refuseBtn.className = 'vote-btn flex-grow py-3 bg-red-100 text-red-700 rounded-lg font-medium hover:bg-red-200 flex items-center justify-center';
// Re-add icons
acceptBtn.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Accept';
rephraseBtn.innerHTML = '<i class="fas fa-edit mr-2"></i> Rephrase';
refuseBtn.innerHTML = '<i class="fas fa-times-circle mr-2"></i> Refuse';
}
// Update progress bar
function updateProgress() {
const answeredCount = userResponses.filter(r => r !== null).length;
const progressPercentage = (answeredCount / totalQuestions) * 100;
progressBar.style.width = `${progressPercentage}%`;
}
// Update stats counters
function updateStats() {
const accepted = userResponses.filter(r => r === 'accept').length;
const rephrased = userResponses.filter(r => r === 'rephrase').length;
const refused = userResponses.filter(r => r === 'refuse').length;
acceptedCount.textContent = accepted;
rephrasedCount.textContent = rephrased;
refusedCount.textContent = refused;
updateProgress();
}
// Initialize the application
document.addEventListener('DOMContentLoaded', init);
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=MahmoudFahmy/question-answer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>