From 8ae389af7b5590fb32700f44fda6bdc26321e491 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Fri, 9 Feb 2024 16:53:51 +1100 Subject: [PATCH] fix: idk something to do with news ratelimiting :) --- src/SEQTA.ts | 1 + src/background.ts | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/SEQTA.ts b/src/SEQTA.ts index be254543..86c89f36 100644 --- a/src/SEQTA.ts +++ b/src/SEQTA.ts @@ -2726,6 +2726,7 @@ function SendNewsPage() { AppendLoadingSymbol('newsloading', '#news-container') browser.runtime.sendMessage({ type: 'sendNews' }).then(function (response) { + console.log(response) let newsarticles = response.news.articles var newscontainer = document.querySelector('#news-container') document.getElementById('newsloading')!.remove() diff --git a/src/background.ts b/src/background.ts index 8c586e86..5aee0441 100644 --- a/src/background.ts +++ b/src/background.ts @@ -116,7 +116,19 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse: break; case 'sendNews': - GetNews(sendResponse); + console.log("Sending news") + const date = new Date(); + + const from = + date.getFullYear() + + '-' + + (date.getMonth() + 1) + + '-' + + (date.getDate() - 1); + + const url = `https://newsapi.org/v2/everything?domains=abc.net.au&from=${from}&apiKey=17c0da766ba347c89d094449504e3080`; + + GetNews(sendResponse, url); return true; default: @@ -124,25 +136,12 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse: } }); -function GetNews(sendResponse: any) { - // Gets the current date - const date = new Date(); - - const from = - date.getFullYear() + - '-' + - (date.getMonth() + 1) + - '-' + - (date.getDate() - 1); - - let url = `https://newsapi.org/v2/everything?domains=abc.net.au&from=${from}&apiKey=17c0da766ba347c89d094449504e3080`; - +function GetNews(sendResponse: any, url: string) { fetch(url) .then((result) => result.json()) .then((response) => { if (response.code == 'rateLimited') { - url += '%00'; - GetNews({}); + GetNews(sendResponse, url += '%00'); } else { sendResponse({ news: response }); }