RYM: Catalog Discography Ratings Shortcut

Quickly see how users rated other releases from the same artist. Adds links for searching users' collections for the current artist at the bottom of the music release page where user ratings are displayed.

  1. // ==UserScript==
  2. // @name RYM: Catalog Discography Ratings Shortcut
  3. // @match https://rateyourmusic.com/release/*
  4. // @version 1.0
  5. // @namespace https://github.com/fauu
  6. // @author fau
  7. // @description Quickly see how users rated other releases from the same artist. Adds links for searching users' collections for the current artist at the bottom of the music release page where user ratings are displayed.
  8. // @license MIT
  9. // @grant GM.addStyle
  10. // @run-at document-end
  11. // ==/UserScript==
  12. "use strict"
  13.  
  14. const cssPrefix = "cdrs";
  15. const linkClass = `${cssPrefix}_link`;
  16.  
  17. // https://rateyourmusic.com/rymzilla/view?id=6255
  18. const workingArtistCodeSearchMinLength = 10; // "[Artist10]".length;
  19.  
  20. const css = `
  21. .${linkClass} {
  22. float: right;
  23. margin-left: 3px;
  24. font-size: .9em;
  25. color: var(--mono-6);
  26. }
  27. `.trim();
  28.  
  29. function makeHref(username, searchTerm) {
  30. return `https://rateyourmusic.com/collection/${username}/strm_a,ss.rd/${encodeURIComponent(searchTerm)}`;
  31. }
  32.  
  33. function makeLinkEl(username, searchTerm) {
  34. const el = document.createElement("a");
  35. el.classList.add(linkClass);
  36. el.href = makeHref(username, searchTerm);
  37. el.textContent = "[A]";
  38. return el;
  39. }
  40.  
  41. function addLinks(catalogEl, searchTerms) {
  42. catalogEl.querySelectorAll(".catalog_header").forEach(el => {
  43. const adjacentEl = el.querySelector(".catalog_ownership").nextSibling;
  44. if (!adjacentEl) return;
  45. const userHref = el.querySelector(".catalog_user > .user").href;
  46. const username = userHref.substring(userHref.lastIndexOf("/") + 2); // Skip "/~" prefix
  47. searchTerms.forEach(term => adjacentEl.after(makeLinkEl(username, term)));
  48. });
  49. }
  50.  
  51. function getSearchTerms() {
  52. return Array.from(document.querySelectorAll(".album_info .artist")).map(el => {
  53. const artistCode = el.title;
  54. if (artistCode.length >= workingArtistCodeSearchMinLength) {
  55. return artistCode;
  56. } else {
  57. const artistName = el.childNodes[0].textContent.trim();
  58. if (!artistName) return;
  59. return `"${artistName}"`;
  60. }
  61. });
  62. }
  63.  
  64. function main() {
  65. const catalogEl = document.getElementById("catalog_list");
  66. if (!catalogEl) return;
  67. const searchTerms = getSearchTerms();
  68. if (searchTerms.length === 0) return;
  69.  
  70. GM.addStyle(css);
  71.  
  72. const process = () => addLinks(catalogEl, searchTerms);
  73. process();
  74. new MutationObserver(process).observe(catalogEl, { childList: true });
  75. }
  76.  
  77. main();