Steam: Bypass age confirmation prompts

Suppresses age confirmations on Steam store pages and community hubs

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

(function () {
	"use strict";

	// Set up 1 year cookies to bypass age verification
	const cookieOptions = "; Secure; Path=/; Max-Age=31536000; SameSite=None";

	// This cookie bypasses the "mature content - view page/cancel" screen.
	// It works on both community and the store.
	document.cookie = "wants_mature_content=1" + cookieOptions;


	if (location.hostname === "store.steampowered.com") {
		// This cookie bypasses the "enter your date of birth" screen.
		const twentyFiveYearsAgo = ((Date.now() - 788_400_000_000) / 1000).toFixed();
		document.cookie = "birthtime=" + twentyFiveYearsAgo + cookieOptions;

		// Reload after making sure we're actually on a page with an age gate
		window.addEventListener("DOMContentLoaded", () => {
			if (document.getElementById("app_agegate")) {
				location.reload();
			}
		});
	} else if (location.hostname === "steamcommunity.com") {
		// Auto reload if we managed to land on an age gate on our very
		// first load. The wants_mature_content cookie should prevent this.
		window.addEventListener("DOMContentLoaded", () => {
			const proceed = function (context = window) {
				if ("AcceptAppHub" in context) {
					context.Proceed?.();
				}
			};

			if ("wrappedJSObject" in window) {
				// Firefox sandbox, bypass and execute directly
				proceed(window.wrappedJSObject);
			} else {
				// Inject as script tag otherwise
				const script = document.createElement("script");
				script.text = `"use strict";(${proceed})();`;
				(document.head ?? document.documentElement).prepend(script);
				script.remove();
			}
		});
	}
})();