Redeem Steam Key

Redirect to Steam Register Key page when copying key

  1. // ==UserScript==
  2. // @name Redeem Steam Key
  3. // @namespace https://savagecore.eu
  4. // @version 0.1.0
  5. // @description Redirect to Steam Register Key page when copying key
  6. // @author SavageCore
  7. // @include *
  8. // @grant GM_openInTab
  9. // ==/UserScript==
  10. //
  11. /* global document window GM_openInTab */
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. // Automatically accept Steam Subscriber Agreement
  17. if (window.location.href.match(/^https?:\/\/store.steampowered.com\/account\/registerkey/)) {
  18. const ssaElem = document.getElementById('accept_ssa');
  19. if (ssaElem) {
  20. ssaElem.checked = 'checked';
  21. }
  22. } else {
  23. const activateProduct = function (e) {
  24. const productKey = window.getSelection().toString().trim() || e.target.value;
  25. let m;
  26. if ((m = /^[\d\w]{2,5}(-[\d\w]{4,5}){2,4}$/.exec(productKey)) !== null) {
  27. // GM_openInTab so that the 'popup' is not blocked by browser
  28. GM_openInTab('https://store.steampowered.com/account/registerkey?key=' + m[0]); // eslint-disable-line new-cap
  29. }
  30. };
  31.  
  32. window.addEventListener('copy', activateProduct, false);
  33. }
  34. })();