From 8a05d8534416256fe2413f5f4fd9970ba94b504b Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Wed, 18 Mar 2026 09:43:32 +1100 Subject: [PATCH] fix: news not loading --- src/background/news.ts | 25 +++++++++++++------------ src/manifests/manifest.json | 2 +- src/seqta/utils/SendNewsPage.ts | 33 +++++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/background/news.ts b/src/background/news.ts index 6e01e910..70bcf1b2 100644 --- a/src/background/news.ts +++ b/src/background/news.ts @@ -92,8 +92,12 @@ const rssFeedsByCountry: Record = { * used to send the fetched news data back to the caller. * It's called with an object like `{ news: { articles: [...] } }`. */ -export async function fetchNews(source: string, sendResponse: any) { - if (source === "australia") { +export async function fetchNews(source: string | undefined, sendResponse: any) { + const normalizedSource = typeof source === "string" && source.trim() + ? source.trim() + : "australia"; + + if (normalizedSource === "australia") { const date = new Date(); const from = @@ -111,18 +115,15 @@ export async function fetchNews(source: string, sendResponse: any) { const parser = new Parser(); let feeds: string[]; - console.log("fetchNews", source); + console.log("fetchNews", normalizedSource); - if (rssFeedsByCountry[source.toLowerCase()]) { - // If the source is a country, fetch from predefined feeds - feeds = rssFeedsByCountry[source.toLowerCase()]; - } else if (source.startsWith("http")) { - // If the source is a URL, use it directly - feeds = [source]; + if (rssFeedsByCountry[normalizedSource.toLowerCase()]) { + feeds = rssFeedsByCountry[normalizedSource.toLowerCase()]; + } else if (normalizedSource.startsWith("http")) { + feeds = [normalizedSource]; } else { - throw new Error( - "Invalid source. Provide a country code or a valid RSS feed URL.", - ); + console.warn("[BetterSEQTA+] Invalid news source, falling back to Australia", normalizedSource); + return fetchNews("australia", sendResponse); } const articlesPromises = feeds.map(async (feedUrl) => { diff --git a/src/manifests/manifest.json b/src/manifests/manifest.json index 15565728..de4f9b3a 100644 --- a/src/manifests/manifest.json +++ b/src/manifests/manifest.json @@ -21,7 +21,7 @@ "service_worker": "background.ts" }, "content_security_policy": { - "extension_pages": "script-src 'self'; object-src 'self'; connect-src 'self' https://betterseqta.org https://accounts.betterseqta.org https://raw.githubusercontent.com" + "extension_pages": "script-src 'self'; object-src 'self'; connect-src 'self' http: https: https://betterseqta.org https://accounts.betterseqta.org https://raw.githubusercontent.com https://newsapi.org" }, "content_scripts": [ { diff --git a/src/seqta/utils/SendNewsPage.ts b/src/seqta/utils/SendNewsPage.ts index f21c0bde..3b1e9c66 100644 --- a/src/seqta/utils/SendNewsPage.ts +++ b/src/seqta/utils/SendNewsPage.ts @@ -53,11 +53,22 @@ export async function SendNewsPage() { const newscontainer = document.querySelector("#news-container"); document.getElementById("newsloading")?.remove(); - // Create a document fragment to batch DOM operations + const articles = response?.news?.articles; + if (!Array.isArray(articles) || articles.length === 0) { + const emptyState = document.createElement("div"); + emptyState.classList.add("day-empty"); + const img = document.createElement("img"); + img.src = browser.runtime.getURL(LogoLightOutline); + const text = document.createElement("p"); + text.innerText = "No news articles available right now."; + emptyState.append(img, text); + newscontainer?.append(emptyState); + return; + } + const fragment = document.createDocumentFragment(); - // Map over articles to create elements - response.news.articles.forEach((article: any) => { + articles.forEach((article: any) => { const newsarticle = document.createElement("a"); newsarticle.classList.add("NewsArticle"); newsarticle.href = article.url; @@ -85,12 +96,14 @@ export async function SendNewsPage() { title.target = "_blank"; const description = document.createElement("p"); + const articleDescription = typeof article.description === "string" + ? article.description + : "No description available."; - article.description = - article.description.length > 400 - ? article.description.substring(0, 400) + "..." - : article.description; - description.innerHTML = article.description; + description.innerHTML = + articleDescription.length > 400 + ? articleDescription.substring(0, 400) + "..." + : articleDescription; articletext.append(title, description); newsarticle.append(articleimage, articletext); @@ -102,10 +115,10 @@ export async function SendNewsPage() { if (!settingsState.animations) return; - const articles = Array.from(document.querySelectorAll(".NewsArticle")); + const animatedArticles = Array.from(document.querySelectorAll(".NewsArticle")); animate( - articles.slice(0, 20), + animatedArticles.slice(0, 20), { opacity: [0, 1], y: [10, 0], scale: [0.99, 1] }, { delay: stagger(0.1),