crazoter / SG UI - Activate Key Link

// ==UserScript==
// @name        SG UI - Activate Key Link
// @namespace   steamgifts
// @include     *://www.steamgifts.com/giveaways/won
// @version     1.0.0
// @grant       none
// @run-at      document-end
// @description Add a URL to activate Steam keys
// @author      crazoter
// @updateURL   https://openuserjs.org/meta/crazoter/SG_UI_-_Activate_Key_Link.meta.js
// @downloadURL https://openuserjs.org/src/scripts/crazoter/SG_UI_-_Activate_Key_Link.user.js
// ==/UserScript==

var API_URL = "https://store.steampowered.com/account/registerkey?key=";
var dom_keys = document.getElementsByClassName("table__column--width-medium text-center");
var isKeyRegex = /([A-Za-z0-9]+)(-([A-Za-z0-9]+)){2,}/g;
//
//Setup UI by looping through all visible keys and linking them appropriately
//
function setupUI() {
  for(var i=1;i<dom_keys.length;i++) {//ignore header
    if(dom_keys[i].children.length > 0 && dom_keys[i].children[0].dataset.clipboardText) {
      var s = dom_keys[i].children[0].dataset.clipboardText.trim();
      if(isSteamKey(s)) {
        dom_keys[i].innerHTML = dom_keys[i].children[0].outerHTML+'<a class="table__column__secondary-link" href="'+activateKeyURL(s)+'" rel="nofollow" target="_blank">'+s+"</a>";
      }
    }
  }
}

function delayedSetupUI() {
  window.setTimeout(function(){
    if($(".view_key_btn.is_loading").length > 0) {
      delayedSetupUI();
    } else {
      setupUI();
    }
  },200);
}

function activateKeyURL(key) {
  return API_URL+key;
}

function isSteamKey(s) {
  if(s) {
    return s.match(isKeyRegex) != null;
  } else {
    return false;
  }
}

$("div.view_key_btn").click(function(){
  delayedSetupUI();
});

setupUI();