JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<a href="https://www.banggood.com/VIOFO-A119-1440P-160-Degree-Wide-Angle-Car-DVR-With-GPS-Black-p-1068196.html" class="btn_offer_block re_track_btn" target="_blank" rel="nofollow">banggood</a>
<br>
<br>
<br>
<a href="http://www.gearbest.com/robot-vacuum/pp_615997.html" class="btn_offer_block re_track_btn" target="_blank" rel="nofollow">gearbest</a>

JavaScript

jQuery('a.btn_offer_block').each(function(i, obj) {
    var url = jQuery(this).attr("href");
    var domain = extractHostname(url);
    var newUrl = checkUrl(url,domain);
    //console.log(newUrl);
    
    jQuery(this).attr("href",newUrl);
    
});



function checkUrl(url,domain) {
	var myRef = url;
  if(url.indexOf(domain) != "-1") {
    myRef += "?p=BQ06121739480201506E";
  } else if(myRef.indexOf("gearbest") != "-1") {
    myRef += "1234";
  }
  
  return myRef;
}



function extractHostname(url) {
    var hostname;
    //find & remove protocol (http, ftp, etc.) and get hostname

    if (url.indexOf("://") > -1) {
        hostname = url.split('/')[2];
    }
    else {
        hostname = url.split('/')[0];
    }

    //find & remove port number
    hostname = hostname.split(':')[0];
    //find & remove "?"
    hostname = hostname.split('?')[0];

    return hostname;
}