feat(hackernews): display citation and upvote counts next to URLs in panel
This commit is contained in:
parent
1525cc4a32
commit
aebbf345d4
@ -1,8 +1,8 @@
|
||||
// ==UserScript==
|
||||
// @name Hacker News URL Highlighter with Enhanced Panel
|
||||
// @name Hacker News URL Highlighter with Enhanced Panel and Scores
|
||||
// @namespace https://news.ycombinator.com/
|
||||
// @version 1.4
|
||||
// @description Highlights URLs in comments on Hacker News, lists them in a toggleable panel with sorting and coloring based on frequency or upvotes, and provides export functionality. Hover previews only in comments.
|
||||
// @version 1.5
|
||||
// @description Highlights URLs in comments on Hacker News, lists them in a toggleable panel with sorting, color coding based on frequency or upvotes, and displays scores next to each URL. Provides export functionality and hover previews only in comments.
|
||||
// @author MorganGeek
|
||||
// @match https://news.ycombinator.com/item?id=*
|
||||
// @grant GM_xmlhttpRequest
|
||||
@ -42,7 +42,7 @@
|
||||
panel.style.position = 'fixed';
|
||||
panel.style.top = '10px';
|
||||
panel.style.right = '10px';
|
||||
panel.style.width = '300px';
|
||||
panel.style.width = '350px';
|
||||
panel.style.backgroundColor = '#fff';
|
||||
panel.style.border = '1px solid #ccc';
|
||||
panel.style.borderRadius = '5px';
|
||||
@ -108,7 +108,7 @@
|
||||
|
||||
// Ajouter l'URL à la liste dans le panneau
|
||||
const listItem = document.createElement('li');
|
||||
listItem.textContent = url;
|
||||
listItem.innerHTML = `<span>${url}</span> <span style="float: right; font-weight: bold;">1</span>`;
|
||||
listItem.style.marginBottom = '5px';
|
||||
listItem.style.wordWrap = 'break-word';
|
||||
listItem.style.cursor = 'pointer';
|
||||
@ -116,6 +116,11 @@
|
||||
panel.querySelector('#url-list').appendChild(listItem);
|
||||
} else {
|
||||
urlData[url].count += 1;
|
||||
// Mettre à jour le compteur dans le panneau
|
||||
const existingItem = panel.querySelector(`li[data-url="${CSS.escape(url)}"] span:last-child`);
|
||||
if (existingItem) {
|
||||
existingItem.textContent = urlData[url].count;
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter la fonctionnalité d'aperçu au survol des liens
|
||||
@ -127,14 +132,14 @@
|
||||
tooltip.innerHTML = '';
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(response.responseText, 'text/html');
|
||||
const title = doc.querySelector('title') ? doc.querySelector('title').innerText : 'Pas de titre';
|
||||
const description = doc.querySelector('meta[name="description"]') ? doc.querySelector('meta[name="description"]').content : 'Pas de description';
|
||||
const title = doc.querySelector('title') ? doc.querySelector('title').innerText : 'No Title';
|
||||
const description = doc.querySelector('meta[name="description"]') ? doc.querySelector('meta[name="description"]').content : 'No Description';
|
||||
|
||||
tooltip.innerHTML = `<strong>${title}</strong><p>${description}</p>`;
|
||||
tooltip.style.display = 'block';
|
||||
},
|
||||
onerror: () => {
|
||||
tooltip.innerHTML = '<strong>Aperçu indisponible</strong>';
|
||||
tooltip.innerHTML = '<strong>Preview unavailable</strong>';
|
||||
tooltip.style.display = 'block';
|
||||
}
|
||||
});
|
||||
@ -183,7 +188,6 @@
|
||||
|
||||
urlsArray.forEach(item => {
|
||||
const listItem = document.createElement('li');
|
||||
listItem.textContent = item.url;
|
||||
listItem.style.marginBottom = '5px';
|
||||
listItem.style.wordWrap = 'break-word';
|
||||
listItem.style.cursor = 'pointer';
|
||||
@ -201,6 +205,12 @@
|
||||
}
|
||||
listItem.style.backgroundColor = color;
|
||||
|
||||
// Créer le contenu avec URL et score
|
||||
listItem.innerHTML = `
|
||||
<span>${item.url}</span>
|
||||
<span style="float: right; font-weight: bold;">${item.count}${item.upvotes > 0 ? ` / ${item.upvotes}` : ''}</span>
|
||||
`;
|
||||
|
||||
// Ajouter l'événement de clic pour copier l'URL
|
||||
listItem.addEventListener('click', () => {
|
||||
GM_setClipboard(item.url, 'text');
|
||||
@ -240,7 +250,7 @@
|
||||
// Note : Hacker News n'expose pas directement les upvotes des commentaires via le DOM.
|
||||
// Si vous avez une méthode pour obtenir les upvotes, vous pouvez l'implémenter ici.
|
||||
// Par exemple, si les points des commentaires sont visibles, vous pouvez les extraire et les attribuer aux URLs.
|
||||
|
||||
|
||||
// Exemple de récupération des points des commentaires (si disponibles)
|
||||
const commentRows = document.querySelectorAll('tr.comtr');
|
||||
commentRows.forEach(row => {
|
||||
|
Loading…
Reference in New Issue
Block a user