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()
+12 -13
View File
@@ -116,16 +116,7 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse:
break; break;
case 'sendNews': case 'sendNews':
GetNews(sendResponse); console.log("Sending news")
return true;
default:
console.log('Unknown request type');
}
});
function GetNews(sendResponse: any) {
// Gets the current date
const date = new Date(); const date = new Date();
const from = const from =
@@ -135,14 +126,22 @@ function GetNews(sendResponse: any) {
'-' + '-' +
(date.getDate() - 1); (date.getDate() - 1);
let url = `https://newsapi.org/v2/everything?domains=abc.net.au&from=${from}&apiKey=17c0da766ba347c89d094449504e3080`; const url = `https://newsapi.org/v2/everything?domains=abc.net.au&from=${from}&apiKey=17c0da766ba347c89d094449504e3080`;
GetNews(sendResponse, url);
return true;
default:
console.log('Unknown request type');
}
});
function GetNews(sendResponse: any, url: string) {
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 });
} }