Steam: Automatically check Subscriber Agreement checkboxes

Automatically checks Steam Subscriber Agreement checkboxes

当前为 2023-12-07 提交的版本,查看 最新版本

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