nettoyage du code

This commit is contained in:
luki39 2022-03-01 10:16:09 +01:00
parent 5e4ff9db0f
commit 5c94f4c961

View File

@ -766,91 +766,3 @@ document.addEventListener('keydown', (e) => {
}
}
})
/**
* Display a news article on the UI.
*
* @param {Object} articleObject The article meta object.
* @param {number} index The article index.
*/
function displayArticle(articleObject, index){
newsArticleTitle.innerHTML = articleObject.title
newsArticleTitle.href = articleObject.link
newsArticleAuthor.innerHTML = 'by ' + articleObject.author
newsArticleDate.innerHTML = articleObject.date
newsArticleComments.innerHTML = articleObject.comments
newsArticleComments.href = articleObject.commentsLink
newsArticleContentScrollable.innerHTML = '<div id="newsArticleContentWrapper"><div class="newsArticleSpacerTop"></div>' + articleObject.content + '<div class="newsArticleSpacerBot"></div></div>'
Array.from(newsArticleContentScrollable.getElementsByClassName('bbCodeSpoilerButton')).forEach(v => {
v.onclick = () => {
const text = v.parentElement.getElementsByClassName('bbCodeSpoilerText')[0]
text.style.display = text.style.display === 'block' ? 'none' : 'block'
}
})
newsNavigationStatus.innerHTML = index + ' of ' + newsArr.length
newsContent.setAttribute('article', index-1)
}
/**
* Load news information from the RSS feed specified in the
* distribution index.
*/
function loadNews(){
return new Promise((resolve, reject) => {
const distroData = DistroManager.getDistribution()
const newsFeed = distroData.getRSS()
const newsHost = new URL(newsFeed).origin + '/'
$.ajax({
url: newsFeed,
success: (data) => {
const items = $(data).find('item')
const articles = []
for(let i=0; i<items.length; i++){
// JQuery Element
const el = $(items[i])
// Resolve date.
const date = new Date(el.find('pubDate').text()).toLocaleDateString('en-US', {month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric'})
// Resolve comments.
let comments = el.find('slash\\:comments').text() || '0'
comments = comments + ' Comment' + (comments === '1' ? '' : 's')
// Fix relative links in content.
let content = el.find('content\\:encoded').text()
let regex = /src="(?!http:\/\/|https:\/\/)(.+?)"/g
let matches
while((matches = regex.exec(content))){
content = content.replace(`"${matches[1]}"`, `"${newsHost + matches[1]}"`)
}
let link = el.find('link').text()
let title = el.find('title').text()
let author = el.find('dc\\:creator').text()
// Generate article.
articles.push(
{
link,
title,
date,
author,
content,
comments,
commentsLink: link + '#comments'
}
)
}
resolve({
articles
})
},
timeout: 2500
}).catch(err => {
resolve({
articles: null
})
})
})
}