snippets/RYM_userscript.js

99 lines
3.8 KiB
JavaScript
Raw Normal View History

// ==UserScript==
// @name RYM Artist Rating Display with Multiple Classifications
// @namespace http://tampermonkey.net/
// @version 1.3
// @description Affiche plusieurs appréciations de l'artiste sur RateYourMusic en fonction de vos propres notes personnalisées, avec des couleurs et des bordures spécifiques.
// @author SansGuidon
// @match https://rateyourmusic.com/artist/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Fonction pour extraire les notes personnelles
function getUserRatings() {
let ratings = document.querySelectorAll('#discography .disco_cat_inner');
return Array.from(ratings).map(el => {
let match = el.textContent.trim().match(/(\d\.\d)/);
return match ? parseFloat(match[1]) : null;
}).filter(rating => rating !== null);
}
// Fonction pour calculer les appréciations de l'artiste
function calculateArtistRatings() {
let ratingCounts = getUserRatings();
let count4OrMore = ratingCounts.filter(rating => rating >= 4.0).length;
let count5 = ratingCounts.filter(rating => rating >= 5.0).length;
let ratings = [];
// Ajouter les bordures pour les albums pris en compte
document.querySelectorAll('#discography .disco_cat_inner').forEach(el => {
let match = el.textContent.trim().match(/(\d\.\d)/);
let rating = match ? parseFloat(match[1]) : null;
if (rating !== null) {
if (rating >= 4.0) {
el.closest('.disco_release').style.border = '1px solid saddlebrown';
}
if (rating >= 5.0) {
el.closest('.disco_release').style.border = '1px solid deeppink';
}
}
});
if (count4OrMore >= 5 && count5 >= 1) {
ratings.push({
category: 'Extreme pleasure: Bands/artists I\'ve given at least 5 times 4.0 - 5.0 ratings for theirs albums, including at least one album with 5.0 rating',
color: 'deeppink'
});
}
if (count5 >= 1 || count4OrMore >= 3) {
ratings.push({
category: 'Easy pleasure: Bands/artists I\'ve given at least 1 time 5.0 rating for their album(s), and/or at least 3 times 4.0+ ratings for their albums',
color: 'darkgoldenrod'
});
}
if (count4OrMore >= 2) {
ratings.push({
category: 'Excellent: Bands/artists of albums I\'ve given at least 2 times 4.0-5.0 ratings',
color: 'saddlebrown'
});
}
if (ratings.length === 0) {
ratings.push({
category: 'No significant rating: This artist doesn\'t meet the criteria for any specific rating category',
color: '#333'
});
}
return ratings;
}
// Fonction pour insérer les appréciations dans la page
function insertArtistRatings(ratings) {
let artistNameSection = document.querySelector('.section_artist_name');
if (artistNameSection) {
ratings.forEach(rating => {
let ratingElement = document.createElement('div');
ratingElement.innerHTML = `<b>${rating.category}</b>`;
ratingElement.style.fontSize = '16px';
ratingElement.style.color = rating.color;
ratingElement.style.padding = '5px 0';
ratingElement.style.borderTop = '1px solid #ccc';
artistNameSection.appendChild(ratingElement);
});
}
}
// Calculer les appréciations de l'artiste
let artistRatings = calculateArtistRatings();
// Insérer les appréciations dans la page
insertArtistRatings(artistRatings);
})();