btown / VGMdb Liner Note Helper

// ==UserScript==
// @name         VGMdb Liner Note Helper
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Within album notes in VGMdb, link to artists, and reference tracks by name
// @author       btown
// @match        https://vgmdb.net/album/*
// @grant        none
// @license      MIT
// @updateURL https://openuserjs.org/meta/btown/VGMdb_Liner_Note_Helper.meta.js
// @downloadURL https://openuserjs.org/install/btown/VGMdb_Liner_Note_Helper.user.js
// @copyright 2021, btown (https://openuserjs.org/users/btown)
// ==/UserScript==

(function () {
  var notes = document.getElementById('notes');
  var html = notes.innerHTML;
  var links = document.querySelectorAll('a[href^="/artist/"]');
  [...links].map((link) => {
    try {
      var linkText = link.querySelector('[lang="en"]') || link;
      var name = linkText.textContent;
      var replacement = `<a href="${link.href}" target="_blank">${name}</a>`;
      console.log(name, replacement);
      if (!html.includes(replacement)) html = html.replace(new RegExp(name, 'g'), replacement);
    }
    catch (err) {}
  });
  var tracks = document.querySelectorAll('.tl tr');
  [...tracks].map((track) => {
    try {
      var cols = track.children;
      var num = cols[0].textContent.trim();
      var title = cols[1].textContent.trim();
      console.log(num, title);
      html = html.replace(new RegExp(`(\\w-)?\\b(${num}|${parseInt(num, 10)})\\b`, 'g'), `$& (${title})`);
    }
    catch (err) {}
  });
  notes.innerHTML = html;
})();