Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const safeStoryLink = encodeURI(storyLink);
const results = [];
const rawResults = await fetch(API_URL + safeStoryLink).then(res => res.json()).then(obj => obj.hits);
if (!rawResults) {
return resolve(results);
}
for (const result of rawResults) {
// eslint-disable-next-line eqeqeq
if (result.objectID == metadata.item.id) {
continue;
}
if (!result.url || !compareUrls(result.url.split('://').pop(), storyLink)) {
continue;
}
if (!metadata.options.showDiscussionsWithNoComments && result.num_comments === 0) {
continue;
}
const date = new Date(result.created_at);
const renderedDate = `${monthNames[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
results.push({
link: `https://news.ycombinator.com/item?id=${result.objectID}`,
title: result.title,
date: renderedDate,
comments: result.num_comments,
points: result.points