Steam: Bypass age confirmation prompts

Suppresses age confirmations on Steam store pages and community hubs

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();
			}
		});
	}
})();