alike03 / Steam2keyseller

// ==UserScript==
// @name         Steam2keyseller
// @description  A Button in Steam to some keyseller sites
// @author       alike03
// @namespace    http://alike.ml/UserScript.php
// @version      1.5
// @icon         https://store.steampowered.com/favicon.ico
// @updateURL    https://openuserjs.org/meta/alike03/Steam2keyseller.meta.js
// @supportURL   https://openuserjs.org/scripts/alike03/Steam2keyseller/issues
// @downloadURL  https://openuserjs.org/install/alike03/Steam2keyseller.user.js
// @match        http://store.steampowered.com/app/*
// @match        https://store.steampowered.com/app/*
// @copyright    2022, alike03 (https://openuserjs.org/users/alike03)
// @license      MIT
// ==/UserScript==

let gamename = document.getElementsByClassName('apphub_AppName');
gamename = remove_non_ascii(gamename[0].innerText);

let seller = [
  {
    name: 'Allkeyshop',
    url: 'http://www.allkeyshop.com/blog/catalogue/search-',
  },
  {
    name: 'GG.deals',
    url: 'https://gg.deals/games/?title=/',
  },
  {
    name: 'GoCDkeys',
    url: 'https://gocdkeys.com/en/search?product=',
  },
  {
    name: 'Planet Key',
    url: 'https://www.planetkey.de/suche/',
  }
]

for (let i in seller) {
  let but = document.createElement('a');
  but.innerHTML = '<span>' + seller[i].name + '</span>';
  but.href = seller[i].url + gamename;
  but.target = '_blank';
  but.className = 'btnv6_blue_hoverfade btn_medium';
  but.style.cssText = 'margin-right: 5px;';

  document.getElementsByClassName('btnv6_blue_hoverfade btn_medium')[0].parentElement.prepend(but);
}

function remove_non_ascii(str) {
  if ((str === null) || (str === ''))
    return false;
  else
    str = str.toString();
  return str.replace(/[^\x20-\x7E]/g, '');
}