Steam: Automatically check Subscriber Agreement checkboxes

Automatically checks Steam Subscriber Agreement checkboxes

  1. // ==UserScript==
  2. // @name Steam: Automatically check Subscriber Agreement checkboxes
  3. // @namespace zo8dd7kkrrnquyxs5yd2
  4. // @match https://store.steampowered.com/account/registerkey
  5. // @match https://store.steampowered.com/account/registerkey?*
  6. // @match https://store.steampowered.com/account/registerkey/
  7. // @match https://store.steampowered.com/account/registerkey/?*
  8. // @match https://checkout.steampowered.com/checkout
  9. // @match https://checkout.steampowered.com/checkout?*
  10. // @match https://checkout.steampowered.com/checkout/
  11. // @match https://checkout.steampowered.com/checkout/?*
  12. // @match https://steamcommunity.com/*
  13. // @grant none
  14. // @version 1.6.1
  15. // @description Automatically checks Steam Subscriber Agreement checkboxes
  16. // @inject-into content
  17. // @run-at document-end
  18. // @sandbox DOM
  19. // @license MIT
  20. // ==/UserScript==
  21.  
  22. (function () {
  23. "use strict";
  24.  
  25. const keepChecked = function (event) {
  26. if (!this.checked) {
  27. event.preventDefault();
  28. }
  29. };
  30.  
  31. const checkIDs = ["accept_ssa", "market_sell_dialog_accept_ssa", "market_buyorder_dialog_accept_ssa", "market_buynow_dialog_accept_ssa", "market_multi_accept_ssa"];
  32. const found = [];
  33.  
  34. for (const id of checkIDs) {
  35. const box = document.getElementById(id);
  36.  
  37. if (box?.type === "checkbox") {
  38. box.checked = true;
  39. box.defaultChecked = true;
  40. box.tabIndex = -1;
  41. box.addEventListener("click", keepChecked);
  42.  
  43. found.push(id);
  44. }
  45. }
  46.  
  47.  
  48. // Additionally prevent checkboxes from being unchecked by JavaScript.
  49. // The "redeem key" page for example does this - you have to manually re-tick the box for each key.
  50. // We do this by adding a special "checked" property to the checkboxes found.
  51. if (found.length) {
  52. const inject = function (checkIDs) {
  53. const checkedDescriptor = {
  54. configurable: true,
  55. enumerable: false,
  56. // no-op to prevent changes
  57. set() {},
  58. // copy over native getter
  59. get: Reflect.getOwnPropertyDescriptor(HTMLInputElement.prototype, "checked").get
  60. };
  61.  
  62. for (const id of checkIDs) {
  63. Reflect.defineProperty(document.getElementById(id), "checked", checkedDescriptor);
  64. }
  65. };
  66.  
  67. const script = document.createElement("script");
  68. script.textContent = `"use strict";(${inject})(${JSON.stringify(found)});`;
  69. (document.head ?? document.documentElement).prepend(script);
  70. script.remove();
  71. }
  72. })();