Steam: Bypass age confirmation prompts

Suppresses age confirmations on Steam store pages and community hubs

目前为 2018-03-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Steam: Bypass age confirmation prompts
  3. // @namespace steam
  4. // @version 1.5
  5. // @description Suppresses age confirmations on Steam store pages and community hubs
  6. // @match *://steamcommunity.com/*
  7. // @match *://store.steampowered.com/agecheck/app/*
  8. // @match *://store.steampowered.com/app/*/agecheck*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. if (location.hostname === "store.steampowered.com") {
  17. // Set up long-lived cookies to bypass age verification
  18. var cookieOptions = "; path=/; max-age=315360000";
  19. var fiftyYearsAgo = ((Date.now() - 1576800000000) / 1000).toFixed();
  20.  
  21. // this bypasses the "mature content - continue/cancel" screen
  22. document.cookie = "mature_content=1" + cookieOptions;
  23. // this bypasses the "enter your date of birth" screen
  24. document.cookie = "birthtime=" + fiftyYearsAgo + cookieOptions;
  25.  
  26. // Reload after making sure we're actually on a page with an age gate
  27. window.addEventListener("DOMContentLoaded", function () {
  28. if (document.getElementById("agegate_box") || document.getElementById("app_agegate")) {
  29. document.body.hidden = true;
  30. location.reload();
  31. }
  32. }, { capture: true, passive: true });
  33. } else if (location.hostname === "steamcommunity.com") {
  34. // Patch Storage.getItem to return a fake value for all keys that look like age_gate_123.
  35. // This bypasses the mature content overlay on community hubs.
  36. var patchSessionStorage = function () {
  37. var overrideRegex = /^age_gate_\d+$/;
  38. var overrideValue = "1";
  39.  
  40. var realGetItem = Storage.prototype.getItem;
  41. var realSessionStorage = window.sessionStorage;
  42.  
  43. Storage.prototype.getItem = function getItem(key) {
  44. // If this is a call on sessionStorage and it matches
  45. // the pattern, return a faked result instead
  46. if (this === realSessionStorage && overrideRegex.test(key)) {
  47. return overrideValue;
  48. }
  49.  
  50. return realGetItem.apply(this, arguments);
  51. };
  52. };
  53.  
  54. if (typeof unsafeWindow !== "undefined" && unsafeWindow !== window) {
  55. // We've been sandboxed against our will
  56. // Thanks, Greasemonkey
  57. var target = document.head || document.documentElement;
  58. var script = document.createElement("script");
  59. script.type = "text/javascript";
  60. script.text = "(" + patchSessionStorage.toString() + ")();";
  61. target.appendChild(script);
  62. target.removeChild(script);
  63. } else {
  64. patchSessionStorage();
  65. }
  66. }
  67. })();