gg.deals - jdoqocy link rewrite

Simple deals.gg script to bypass jdoqocy links because my adblocker blocks them

// ==UserScript==
// @name         gg.deals - jdoqocy link rewrite
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @license      MIT
// @description  Simple deals.gg script to bypass jdoqocy links because my adblocker blocks them
// @author       avelardi
// @match        https://gg.deals/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
//This was hacked together and probably coded poorly, but it works for me.
//Note you may need to click one fanatical link once first then reload?

function replaceAllHrefs(node, newHref) {
  const elementsWithHref = node.querySelectorAll('[href]');
  elementsWithHref.forEach(element => {
    element.setAttribute('href', newHref);
  });
}


$( document ).ready(function() {
  const shop_links = document.getElementsByClassName("shop-link");
  var fanatical_img_div = undefined;
  for (let i=0;i<shop_links.length;i++){
      if(shop_links.item(i).querySelector('img') !== null){
        if(shop_links.item(i).querySelector('img').hasAttribute('alt')){
          if(shop_links.item(i).querySelector('img').getAttribute('alt') == "Fanatical"){
            fanatical_img_div = shop_links.item(i);
          }
        }
      }
  }
  $.ajax({
    url: fanatical_img_div.href,
    type: 'GET',
      success: function(data){
        const parser = new DOMParser();
        const redirect_html = parser.parseFromString(data, 'text/html');
        //console.log(redirect_html.getElementsByClassName('redirection-actions')[0].querySelector('a').href);
        var actual_url = decodeURIComponent(redirect_html.getElementsByClassName('redirection-actions')[0].querySelector('a').href).split('url=')[1];
        replaceAllHrefs(fanatical_img_div.parentNode.parentNode,actual_url);
      },
      error: function(data) {
          console.log('Error! Something went wrong');
          console.log(data);
          }})
})