MiM / BLU show Blu-ray.com link

// ==UserScript==
// @name         BLU show Blu-ray.com link
// @description  Add link to Blu-ray.com when possible
// @version      1.0.3
// @author       MiM
// @copyright    2024
// @license      MIT
// @match        https://blutopia.cc/torrents/similar/*
// @match        https://blutopia.cc/torrents/*
// @match        https://blutopia.cc/requests/*
// @grant        GM_xmlhttpRequest
// @icon         https://blutopia.cc/favicon.ico
// @updateURL    https://openuserjs.org/meta/MiM/BLU_show_Blu-ray.com_link.meta.js
// @downloadURL  https://openuserjs.org/src/scripts/MiM/BLU_show_Blu-ray.com_link.user.js
// ==/UserScript==

async function search_bluray_com(url) {
  console.log(url);
  const headers = {
    "Content-Type": "application/html"
  };
  let resolver;
  let rejecter;
  const p = new Promise((resolveFn, rejectFn) => {
    resolver = resolveFn;
    rejecter = rejectFn;
  });
  const final = GM_xmlhttpRequest({
    method: "GET",
    url: url,
    headers: headers,
    onload: (response) => resolver(response),
    onerror: (response) => rejecter(response),
    ontimeout: (response) => rejecter(response)
  });
  return p;
}

(async function () {
  'use strict';
  try {
    let imdb_url = document.getElementsByClassName("meta__imdb")[0].getElementsByTagName("a")[0].href;
    let url_regex = /^(.*)(tt\d+)([^\d]*)$/;
    let imdb_id = imdb_url.match(url_regex)[2];
    let bluray_com_search_url = `https://www.blu-ray.com/search/?quicksearch=1&quicksearch_keyword=${imdb_id}&section=theatrical`;
    let bluray_com_search = await search_bluray_com(bluray_com_search_url);
    let bluray_com_search_html = document.createElement('html');
    bluray_com_search_html.innerHTML = bluray_com_search.response;
    let bluray_com_link = bluray_com_search_html.getElementsByClassName("alphaborder hoverlink")[0].href;

    let bluray_com_html = document.createElement('li');
    bluray_com_html.setAttribute("class", "meta__bluray_com");
    let bluray_com_font_awesome = document.createElement('i');
    bluray_com_font_awesome.setAttribute("class", "fa-duotone fa-square-b");
    bluray_com_font_awesome.setAttribute("style", "--fa-secondary-opacity: 1.0; --fa-primary-color: #FFFFFF; --fa-secondary-color: #4DA2E3; font-size: 23px; bottom: 2px;");
    let bluray_com_anchor_tag = document.createElement('a');
    bluray_com_anchor_tag.setAttribute("class", "meta-id-tag");
    bluray_com_anchor_tag.href = bluray_com_link;
    bluray_com_anchor_tag.target = "_blank";
    bluray_com_anchor_tag.setAttribute("title", `Blu-ray.com: ${imdb_id}`);
    bluray_com_anchor_tag.append(bluray_com_font_awesome);
    bluray_com_html.appendChild(bluray_com_anchor_tag);

    document.getElementsByClassName("meta__ids")[0].appendChild(bluray_com_html);
  }
  catch {
    console.log("Failed to find Blu-ray.com link for this page.")
  }
})();