fix: idk something to do with news ratelimiting :)

This commit is contained in:
SethBurkart123
2024-02-09 16:53:51 +11:00
parent 4cd7bd718e
commit 8ae389af7b
2 changed files with 16 additions and 16 deletions
+1
View File
@@ -2726,6 +2726,7 @@ function SendNewsPage() {
AppendLoadingSymbol('newsloading', '#news-container') AppendLoadingSymbol('newsloading', '#news-container')
browser.runtime.sendMessage({ type: 'sendNews' }).then(function (response) { browser.runtime.sendMessage({ type: 'sendNews' }).then(function (response) {
console.log(response)
let newsarticles = response.news.articles let newsarticles = response.news.articles
var newscontainer = document.querySelector('#news-container') var newscontainer = document.querySelector('#news-container')
document.getElementById('newsloading')!.remove() document.getElementById('newsloading')!.remove()
+15 -16
View File
@@ -116,7 +116,19 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse:
break; break;
case 'sendNews': 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; return true;
default: default:
@@ -124,25 +136,12 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse:
} }
}); });
function GetNews(sendResponse: any) { function GetNews(sendResponse: any, url: string) {
// 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`;
fetch(url) fetch(url)
.then((result) => result.json()) .then((result) => result.json())
.then((response) => { .then((response) => {
if (response.code == 'rateLimited') { if (response.code == 'rateLimited') {
url += '%00'; GetNews(sendResponse, url += '%00');
GetNews({});
} else { } else {
sendResponse({ news: response }); sendResponse({ news: response });
} }