Steam: Bypass age confirmation prompts

Suppresses age confirmations on Steam store pages and community hubs

目前為 2021-10-31 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Steam: Bypass age confirmation prompts
// @namespace    steam
// @version      1.8
// @description  Suppresses age confirmations on Steam store pages and community hubs
// @license      MIT
// @match        https://steamcommunity.com/*
// @match        https://store.steampowered.com/agecheck/app/*
// @match        https://store.steampowered.com/app/*/agecheck*
// @grant        none
// @run-at       document-start
// @inject-into  content
// ==/UserScript==

(function () {
	"use strict";

	if (location.hostname === "store.steampowered.com") {
		// Set up long-lived cookies (10 years) to bypass age verification
		const cookieOptions = "; Secure; Path=/; Max-Age=315360000; SameSite=None";

		// This bypasses the "mature content - view page/cancel" screen.
		// Overrides the settings you set here: https://store.steampowered.com/account/preferences/
		document.cookie = "wants_mature_content=1" + cookieOptions;

		// This bypasses the "enter your date of birth" screen.
		const fiftyYearsAgo = ((Date.now() - 1576800000000) / 1000).toFixed();
		document.cookie = "birthtime=" + fiftyYearsAgo + cookieOptions;

		// Reload after making sure we're actually on a page with an age gate
		window.addEventListener("DOMContentLoaded", function () {
			if (document.getElementById("app_agegate")) {
				location.reload();
			}
		});
	} else if (location.hostname === "steamcommunity.com") {
		// Patch Storage.getItem to return a fake value for all keys that look like age_gate_123.
		// This bypasses the mature content overlay on community hubs.
		// Be careful to create objects/functions that the page context has permission to access
		// in case we're inside the Firefox sandbox (e.g. window.Object instead of {})
		const patchSessionStorage = function (context = window, exporter = (f) => f) {
			const overrideRegex = /^age_gate_\d+$/;
			
			const proxyHandler = new window.Object();
			proxyHandler.apply = exporter((getItem, that, args) => {
				if (args.length && that === window.sessionStorage && overrideRegex.test(String(args[0]))) {
					return "1";
				}

				return getItem.apply(that, args);
			});

			context.Storage.prototype.getItem = new window.Proxy(context.Storage.prototype.getItem, proxyHandler);
		};


		
		if ("wrappedJSObject" in window) {
			// Firefox sandbox, bypass and execute directly
			const context = window.wrappedJSObject;
			patchSessionStorage(context, (f) => exportFunction(f, window));
		} else {
			// Chrome sandbox or no sandbox, inject as script tag
			const script = document.createElement("script");
			script.text = `"use strict";(${patchSessionStorage})();`;
			(document.head ?? document.documentElement).prepend(script);
			script.remove();
		}
	}
})();