// ============================================================
// Chatbot data loader — replaces 196 KB of hardcoded arrays
// Host tours.json, toursV2.json, accommodations.json on GitHub
// then update the BASE_URL below to your raw GitHub URL.
// ============================================================
(function () {
// ▼▼▼ CHANGE THIS to your raw GitHub URL (see instructions) ▼▼▼
const BASE_URL = 'https://raw.githubusercontent.com/tosharetoday007/latestfoto-data/main/';
// ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
let toursData = null;
let toursDataV2 = null;
let accommodationsData = null;
// Load all three JSON files in parallel
Promise.all([
fetch(BASE_URL + 'tours.json').then(r => r.json()),
fetch(BASE_URL + 'toursV2.json').then(r => r.json()),
fetch(BASE_URL + 'accommodations.json').then(r => r.json()),
]).then(([t1, t2, acc]) => {
toursData = t1;
toursDataV2 = t2;
accommodationsData = acc;
}).catch(err => {
console.error('Chatbot data failed to load:', err);
});
// Wire up send button after DOM is ready
document.addEventListener('DOMContentLoaded', function () {
const sendBtn = document.getElementById('send-btn');
if (!sendBtn) return;
sendBtn.addEventListener('click', function () {
const userInput = document.getElementById('user-input').value.trim();
if (userInput === '') return;
// Store the query
const storedQueries = JSON.parse(localStorage.getItem('searchQueries')) || [];
storedQueries.push(userInput);
localStorage.setItem('searchQueries', JSON.stringify(storedQueries));
appendMessage('You', userInput);
document.getElementById('user-input').value = '';
const normalizedInput = userInput.toLowerCase();
if (!Array.isArray(toursData) || !Array.isArray(toursDataV2) || !Array.isArray(accommodationsData)) {
appendMessage('Answer', 'Data is still loading, please try again in a moment.');
return;
}
let resultsList = '';
const allTours = [...toursData, ...toursDataV2];
// Find matching tours
const matchingTours = allTours.filter(tour =>
normalizedInput.split(' ').some(word =>
(tour.city && tour.city.toLowerCase().includes(word)) ||
(tour.City && tour.City.toLowerCase().includes(word)) ||
(tour.Country && tour.Country.toLowerCase().includes(word)) ||
(tour['Tour Title'] && tour['Tour Title'].toLowerCase().includes(word)) ||
(tour.tours && tour.tours.some(t =>
t.name.toLowerCase().includes(word) || t.description.toLowerCase().includes(word)
))
)
);
// Find matching accommodations
const matchingAccommodation = accommodationsData.filter(accommodation =>
normalizedInput.split(' ').some(word =>
(accommodation.city && accommodation.city.toLowerCase().includes(word)) ||
(accommodation.Country && accommodation.Country.toLowerCase().includes(word))
)
);
// Process tour results
if (matchingTours.length > 0) {
matchingTours.forEach(tourData => {
if (tourData.tours && tourData.tours.length > 0) {
const toursList = tourData.tours.map(tourItem =>
`${tourItem.name}: ${tourItem.description} - ${tourItem.price} More Info`
).join('
');
resultsList += `Tours available in ${tourData.city}:
${toursList}
`;
} else if (tourData['Tour Title']) {
resultsList += `${tourData['Tour Title']}: ${tourData['AVG Rating']} ⭐ (${tourData['Reviews']} reviews) - ${tourData['Price from']}€ More Info
`;
}
});
}
// Process accommodation results
if (matchingAccommodation.length > 0) {
matchingAccommodation.forEach(accommodation => {
if (Array.isArray(accommodation.Hostel) && accommodation.Hostel.length > 0) {
const accommodationList = accommodation.Hostel.map(hostelItem =>
`${hostelItem.name}: ${hostelItem.description} - ${hostelItem.price} More Info`
).join('
');
resultsList += `Accommodations available in ${accommodation.city}:
${accommodationList}
`;
} else {
resultsList += `${accommodation.Hostel}: ${accommodation.Description} - ${accommodation.Price}€ More Info
`;
}
});
}
// Display response
if (resultsList === '') {
appendMessage('Answer',
'Sorry, No Answer.
' +
'Explore More:
' +
'Miscellaneous Issues
' +
'Explore Current Immigration Opportunities
' +
'Free Travel and Tours
' +
'Check out
' +
'Shop now
' +
'Learn Language (English, Spanish, Hindi, French)
' +
'Follow Us!
' +
'Twitter
' +
'Facebook
' +
'Our YouTube Channels!
' +
'Travel
' +
'Non-Expert Recipes
' +
'Gossip
'
);
} else {
appendMessage('Answer', resultsList);
}
});
});
function appendMessage(sender, message) {
const chatbox = document.getElementById('chatbox');
if (!chatbox) return;
const messageElem = document.createElement('div');
messageElem.innerHTML = `${sender}: ${message}`;
chatbox.appendChild(messageElem);
chatbox.scrollTop = chatbox.scrollHeight;
// AdSense ad after each message
const adContainer = document.createElement('div');
adContainer.innerHTML = `
`;
chatbox.appendChild(adContainer);
(adsbygoogle = window.adsbygoogle || []).push({});
}
})();