Skip to content

Commit

Permalink
feat: fetch by link
Browse files Browse the repository at this point in the history
  • Loading branch information
JollyJolli authored Oct 16, 2024
1 parent 58a84df commit 4a0e467
Showing 1 changed file with 21 additions and 287 deletions.
308 changes: 21 additions & 287 deletions JS/script.js
Original file line number Diff line number Diff line change
@@ -1,283 +1,19 @@
// Static JSON data
const projectsData ={
"Webs": [
{
"link": "https://sports.formen.cc",
"titulo": {
"es": "Deportes",
"en": "Sports"
},
"descripcion": {
"es": "⚽ ¡Busca información sobre jugadores de varios deportes!",
"en": "⚽ Find information about players from various sports!"
},
"nueva": false,
"icon": "fa-solid fa-football-ball",
"act": false,
"contribuido": false
},
{
"link": "https://cktls.formen.cc",
"titulo": {
"es": "Cocteles",
"en": "Cocktails"
},
"descripcion": {
"es": "🍹 ¡Busca información sobre cocteles!",
"en": "🍹 Find information about cocktails!"
},
"nueva": false,
"icon": "fa-solid fa-glass-martini",
"act": false,
"contribuido": false
},
{
"link": "https://flag-game.formen.cc",
"titulo": {
"es": "¡Adivina la Bandera!",
"en": "Guess the Flag!"
},
"descripcion": {
"es": "🌍 ¡Un juego sencillo de adivinar la bandera!",
"en": "🌍 A simple game to guess the flag!"
},
"nueva": false,
"icon": "fa-solid fa-flag",
"act": false,
"contribuido": false
},
{
"link": "https://rm.formen.cc",
"titulo": {
"es": "Rick and Morty Characters",
"en": "Rick and Morty Characters"
},
"descripcion": {
"es": "🚀 ¡Busca personajes de Rick and Morty!",
"en": "🚀 Find characters from Rick and Morty!"
},
"nueva": false,
"icon": "fa-solid fa-user-astronaut",
"act": false,
"contribuido": false
},
{
"link": "https://food.formen.cc",
"titulo": {
"es": "Comida",
"en": "Food"
},
"descripcion": {
"es": "🍽️ ¡Busca información sobre comida!",
"en": "🍽️ Find information about food!"
},
"nueva": false,
"icon": "fa-solid fa-utensils",
"act": false,
"contribuido": false
},
{
"link": "https://disney.formen.cc",
"titulo": {
"es": "Disney",
"en": "Disney"
},
"descripcion": {
"es": "✨ ¡Busca personajes de Disney!",
"en": "✨ Find Disney characters!"
},
"nueva": false,
"icon": "fa-solid fa-magic",
"act": false,
"contribuido": false
},
{
"link": "https://office.formen.cc",
"titulo": {
"es": "The Office",
"en": "The Office"
},
"descripcion": {
"es": "📋 ¡Busca personajes de The Office!",
"en": "📋 Find characters from The Office!"
},
"nueva": false,
"icon": "fa-solid fa-briefcase",
"act": false,
"contribuido": false
},
{
"link": "https://btc.formen.cc",
"titulo": {
"es": "Bitcoin",
"en": "Bitcoin"
},
"descripcion": {
"es": "💰 ¡Obtén el valor de bitcoin en dólares!",
"en": "💰 Get the value of bitcoin in dollars!"
},
"nueva": false,
"icon": "fa-brands fa-bitcoin",
"act": false,
"contribuido": false
},
{
"link": "https://paises.formen.cc",
"titulo": {
"es": "Buscar Paises",
"en": "Search Countries"
},
"descripcion": {
"es": "🌎 ¡Busca información de distintos países!",
"en": "🌎 Find information about different countries!"
},
"nueva": false,
"icon": "fa-solid fa-globe",
"act": false,
"contribuido": false
},
{
"link": "https://qr.formen.cc",
"titulo": {
"es": "Generador de QRs",
"en": "QR Generator"
},
"descripcion": {
"es": "📱 ¡Crea tu propio QR!",
"en": "📱 Create your own QR!"
},
"nueva": false,
"icon": "fa-solid fa-qrcode",
"act": false,
"contribuido": false
},
{
"link": "https://clima.formen.cc",
"titulo": {
"es": "Clima",
"en": "Weather"
},
"descripcion": {
"es": "☀️ ¡Consulta el clima de tu ciudad de una forma interesante!",
"en": "☀️ Check the weather in your city in an interesting way!"
},
"nueva": false,
"icon": "fa-solid fa-cloud-sun",
"act": false,
"contribuido": false
},
{
"link": "https://tip.formen.cc",
"titulo": {
"es": "Calculador de Propinas",
"en": "Tip Calculator"
},
"descripcion": {
"es": "💵 ¡Calcula fácilmente la propina que debes dejar en tus comidas y servicios!",
"en": "💵 Easily calculate the tip you should leave for your meals and services!"
},
"nueva": false,
"icon": "fa-solid fa-calculator",
"act": false,
"contribuido": false
},
{
"link": "https://spacex.formen.cc",
"titulo": {
"es": "SpaceX",
"en": "SpaceX"
},
"descripcion": {
"es": "🚀 ¡Descubre el último lanzamiento de SpaceX y explora el historial de eventos!",
"en": "🚀 Discover the latest SpaceX launch and explore the event history!"
},
"nueva": false,
"icon": "fa-solid fa-rocket",
"act": false,
"contribuido": false
},
{
"link": "https://usa.formen.cc",
"titulo": {
"es": "Presidentes de EE.UU.",
"en": "U.S. Presidents"
},
"descripcion": {
"es": "🇺🇸 ¡Explora la lista completa de todos los presidentes que ha tenido Estados Unidos!",
"en": "🇺🇸 Explore the complete list of all U.S. presidents!"
},
"nueva": false,
"icon": "fa-solid fa-landmark",
"act": false,
"contribuido": false
},
{
"link": "https://lastfm.formen.cc",
"titulo": {
"es": "Last.fm",
"en": "Last.fm"
},
"descripcion": {
"es": "🎵 Busca la informacion de cualquier usuario de last.fm!",
"en": "🎵 Search for information about any last.fm user!"
},
"nueva": false,
"icon": "fa-solid fa-music",
"act": false,
"contribuido": false
},
{
"link": "https://taximetro.formen.cc",
"titulo": {
"es": "Taxímetro",
"en": "Taxi Meter"
},
"descripcion": {
"es": "🚖 ¡Calcula el valor que obtendrá el taxímetro al final del recorrido!",
"en": "🚖 Calculate the amount the taxi meter will show at the end of the ride!"
},
"nueva": false,
"icon": "fa-solid fa-tachometer-alt",
"act": false,
"contribuido": false
},
{
"link": "https://contribution-cards.netlify.app/",
"titulo": {
"es": "Cartas de Contribución",
"en": "Contribution Cards"
},
"descripcion": {
"es": "🃏 ¡Explora y crea cartas de contribución!",
"en": "🃏 Explore and create contribution cards!"
},
"nueva": false,
"icon": "fa-solid fa-cards",
"act": false,
"contribuido": true
},
{
"link": "https://nmoji.netlify.app/",
"titulo": {
"es": "Buscador de Emojis",
"en": "Emoji Finder"
},
"descripcion": {
"es": "😀 ¡Encuentra emojis de una manera fácil y divertida!",
"en": "😀 Find emojis in an easy and fun way!"
},
"nueva": false,
"icon": "fa-solid fa-smile",
"act": false,
"contribuido": true
}
]
}


// Variable to store the current filter state and language
let currentFilter = 'all';
let currentLanguage = 'es'; // Default language
let projects = []; // Store fetched projects data

// Function to fetch projects data from the external JSON file
async function fetchProjectsData() {
try {
const response = await fetch('https://raw.githubusercontent.com/JollyJolli/json-db/refs/heads/main/data/webs/web-places.json');
const data = await response.json();
projects = data.Webs; // Store the fetched projects data
displayProjects(projects); // Display projects after fetching
} catch (error) {
console.error('Error fetching projects data:', error);
}
}

// Function to display projects
function displayProjects(projects, filter = 'all', language = currentLanguage) {
Expand Down Expand Up @@ -329,7 +65,7 @@ function setupFilterButtons() {
button.classList.add('active');

// Display filtered projects
displayProjects(projectsData.Webs, filter, currentLanguage);
displayProjects(projects, filter, currentLanguage);
});
});
}
Expand All @@ -339,11 +75,10 @@ function handleLanguageSwitch() {
const languageSwitcher = document.getElementById('language-switcher');
languageSwitcher.addEventListener('change', () => {
currentLanguage = languageSwitcher.value; // Update current language
displayProjects(projectsData.Webs, currentFilter, currentLanguage); // Refresh displayed projects
displayProjects(projects, currentFilter, currentLanguage); // Refresh displayed projects
});
}


function changeLanguage(language) {
const title = document.getElementById("landing-title");
const description = document.getElementById("landing-description");
Expand All @@ -354,8 +89,8 @@ function changeLanguage(language) {
// Update text based on selected language
if (language === "en") {
title.textContent = title.dataset.en;
discordBtn.textContent=discordBtn.dataset.en;
landingWall.textContent=landingWall.dataset.en;
discordBtn.textContent = discordBtn.dataset.en;
landingWall.textContent = landingWall.dataset.en;
description.textContent = description.dataset.en;
projectsTitle.textContent = projectsTitle.dataset.en;

Expand All @@ -369,8 +104,8 @@ function changeLanguage(language) {
title.textContent = title.dataset.es;
description.textContent = description.dataset.es;
projectsTitle.textContent = projectsTitle.dataset.es;
discordBtn.textContent=discordBtn.dataset.es;
landingWall.textContent=landingWall.dataset.es;
discordBtn.textContent = discordBtn.dataset.es;
landingWall.textContent = landingWall.dataset.es;

// Update filter button text
document.getElementById("filter-all").textContent = "Todos";
Expand All @@ -387,7 +122,6 @@ document.getElementById("language-switcher").addEventListener("change", function
});

// Initialize the application
const projects = projectsData.Webs;
displayProjects(projects); // Display all projects initially
fetchProjectsData(); // Fetch and display projects initially
setupFilterButtons(); // Setup filter buttons
handleLanguageSwitch(); // Setup language switche
handleLanguageSwitch(); // Setup language switch

0 comments on commit 4a0e467

Please sign in to comment.