From bb9e60ff8063fb7d1a403d86983c7574753f3bbd Mon Sep 17 00:00:00 2001 From: Annika <56906084+AnnikaCodes@users.noreply.github.com> Date: Sun, 28 Jun 2020 10:48:33 -0700 Subject: [PATCH] Use JSON API for addNews() (#1537) --- js/client-mainmenu.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js index a18570177..47cadf3e0 100644 --- a/js/client-mainmenu.js +++ b/js/client-mainmenu.js @@ -124,14 +124,34 @@ // news addNews: function () { - var newsId = '1990'; - if (newsId === '' + Dex.prefs('readnews')) return; - this.addPseudoPM({ - title: 'Latest News', - html: '', - attributes: 'data-newsid="' + newsId + '"', - cssClass: 'news-embed', - height: 400 + var self = this; + $.ajax({ + url: "https://pokemonshowdown.com/news.json", + dataType: "json", + success: function (data) { + var html = ''; + for (var i in [0, 1]) { + var post = data[i]; + var hasRead = data[i].id && Dex.prefs('readnews') === '' + data[i].id; + + html += '
' + post.summaryHTML + '
'; + html += ''; + if (post.author) html += '—' + post.author + ''; + if (post.date) { + html += ' on ' + new Date(post.date * 1000).toDateString() + ''; + } + html += '