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==
|
// ==UserScript==
|
||||||
// @name Hacker News URL Highlighter with Enhanced Panel
|
// @name Hacker News URL Highlighter with Enhanced Panel and Scores
|
||||||
// @namespace https://news.ycombinator.com/
|
// @namespace https://news.ycombinator.com/
|
||||||
// @version 1.4
|
// @version 1.5
|
||||||
// @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.
|
// @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
|
// @author MorganGeek
|
||||||
// @match https://news.ycombinator.com/item?id=*
|
// @match https://news.ycombinator.com/item?id=*
|
||||||
// @grant GM_xmlhttpRequest
|
// @grant GM_xmlhttpRequest
|
||||||
@ -42,7 +42,7 @@
|
|||||||
panel.style.position = 'fixed';
|
panel.style.position = 'fixed';
|
||||||
panel.style.top = '10px';
|
panel.style.top = '10px';
|
||||||
panel.style.right = '10px';
|
panel.style.right = '10px';
|
||||||
panel.style.width = '300px';
|
panel.style.width = '350px';
|
||||||
panel.style.backgroundColor = '#fff';
|
panel.style.backgroundColor = '#fff';
|
||||||
panel.style.border = '1px solid #ccc';
|
panel.style.border = '1px solid #ccc';
|
||||||
panel.style.borderRadius = '5px';
|
panel.style.borderRadius = '5px';
|
||||||
@ -108,7 +108,7 @@
|
|||||||
|
|
||||||
// Ajouter l'URL à la liste dans le panneau
|
// Ajouter l'URL à la liste dans le panneau
|
||||||
const listItem = document.createElement('li');
|
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.marginBottom = '5px';
|
||||||
listItem.style.wordWrap = 'break-word';
|
listItem.style.wordWrap = 'break-word';
|
||||||
listItem.style.cursor = 'pointer';
|
listItem.style.cursor = 'pointer';
|
||||||
@ -116,6 +116,11 @@
|
|||||||
panel.querySelector('#url-list').appendChild(listItem);
|
panel.querySelector('#url-list').appendChild(listItem);
|
||||||
} else {
|
} else {
|
||||||
urlData[url].count += 1;
|
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
|
// Ajouter la fonctionnalité d'aperçu au survol des liens
|
||||||
@ -127,14 +132,14 @@
|
|||||||
tooltip.innerHTML = '';
|
tooltip.innerHTML = '';
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const doc = parser.parseFromString(response.responseText, 'text/html');
|
const doc = parser.parseFromString(response.responseText, 'text/html');
|
||||||
const title = doc.querySelector('title') ? doc.querySelector('title').innerText : 'Pas de titre';
|
const title = doc.querySelector('title') ? doc.querySelector('title').innerText : 'No Title';
|
||||||
const description = doc.querySelector('meta[name="description"]') ? doc.querySelector('meta[name="description"]').content : 'Pas de description';
|
const description = doc.querySelector('meta[name="description"]') ? doc.querySelector('meta[name="description"]').content : 'No Description';
|
||||||
|
|
||||||
tooltip.innerHTML = `<strong>${title}</strong><p>${description}</p>`;
|
tooltip.innerHTML = `<strong>${title}</strong><p>${description}</p>`;
|
||||||
tooltip.style.display = 'block';
|
tooltip.style.display = 'block';
|
||||||
},
|
},
|
||||||
onerror: () => {
|
onerror: () => {
|
||||||
tooltip.innerHTML = '<strong>Aperçu indisponible</strong>';
|
tooltip.innerHTML = '<strong>Preview unavailable</strong>';
|
||||||
tooltip.style.display = 'block';
|
tooltip.style.display = 'block';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -183,7 +188,6 @@
|
|||||||
|
|
||||||
urlsArray.forEach(item => {
|
urlsArray.forEach(item => {
|
||||||
const listItem = document.createElement('li');
|
const listItem = document.createElement('li');
|
||||||
listItem.textContent = item.url;
|
|
||||||
listItem.style.marginBottom = '5px';
|
listItem.style.marginBottom = '5px';
|
||||||
listItem.style.wordWrap = 'break-word';
|
listItem.style.wordWrap = 'break-word';
|
||||||
listItem.style.cursor = 'pointer';
|
listItem.style.cursor = 'pointer';
|
||||||
@ -201,6 +205,12 @@
|
|||||||
}
|
}
|
||||||
listItem.style.backgroundColor = color;
|
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
|
// Ajouter l'événement de clic pour copier l'URL
|
||||||
listItem.addEventListener('click', () => {
|
listItem.addEventListener('click', () => {
|
||||||
GM_setClipboard(item.url, 'text');
|
GM_setClipboard(item.url, 'text');
|
||||||
|
Loading…
Reference in New Issue
Block a user