Steam: Bypass age confirmation prompts

Suppresses age confirmations on Steam store pages and community hubs

当前为 2023-06-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Steam: Bypass age confirmation prompts
  3. // @namespace steam
  4. // @version 2.0
  5. // @description Suppresses age confirmations on Steam store pages and community hubs
  6. // @license MIT
  7. // @match https://steamcommunity.com/*
  8. // @match https://store.steampowered.com/agecheck/app/*
  9. // @match https://store.steampowered.com/app/*/agecheck*
  10. // @grant none
  11. // @run-at document-start
  12. // @inject-into content
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. "use strict";
  17.  
  18. // Set up 1 month cookies to bypass age verification
  19. const cookieOptions = "; Secure; Path=/; Max-Age=2592000; SameSite=None";
  20.  
  21. // This cookie bypasses the "mature content - view page/cancel" screen.
  22. // It works on both community and the store.
  23. document.cookie = "wants_mature_content=1" + cookieOptions;
  24.  
  25.  
  26. if (location.hostname === "store.steampowered.com") {
  27. // This cookie bypasses the "enter your date of birth" screen.
  28. const twentyFiveYearsAgo = ((Date.now() - 788_400_000_000) / 1000).toFixed();
  29. document.cookie = "birthtime=" + twentyFiveYearsAgo + cookieOptions;
  30.  
  31. // Reload after making sure we're actually on a page with an age gate
  32. window.addEventListener("DOMContentLoaded", () => {
  33. if (document.getElementById("app_agegate")) {
  34. location.reload();
  35. }
  36. });
  37. } else if (location.hostname === "steamcommunity.com") {
  38. // Auto reload if we managed to land on an age gate on our very
  39. // first load. The wants_mature_content cookie should prevent this.
  40. window.addEventListener("DOMContentLoaded", () => {
  41. const proceed = function (context = window) {
  42. if ("AcceptAppHub" in context) {
  43. context.Proceed?.();
  44. }
  45. };
  46.  
  47. if ("wrappedJSObject" in window) {
  48. // Firefox sandbox, bypass and execute directly
  49. proceed(window.wrappedJSObject);
  50. } else {
  51. // Inject as script tag otherwise
  52. const script = document.createElement("script");
  53. script.text = `"use strict";(${proceed})();`;
  54. (document.head ?? document.documentElement).prepend(script);
  55. script.remove();
  56. }
  57. });
  58. }
  59. })();