Steam: Bypass age confirmation prompts

Suppresses age confirmations on Steam store pages and community hubs

当前为 2016-06-27 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Steam: Bypass age confirmation prompts
// @namespace    steam
// @version      1.3
// @description  Suppresses age confirmations on Steam store pages and community hubs
// @author       lunboks
// @match        *://steamcommunity.com/app/*
// @match        *://steamcommunity.com/workshop*
// @match        *://steamcommunity.com/sharedfiles/filedetails*
// @match        *://store.steampowered.com/agecheck/app/*
// @match        *://store.steampowered.com/app/*/agecheck*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    "use strict";

    if (location.hostname === "store.steampowered.com") {
        // Set up long-lived cookies to bypass age verification
        var date = new Date();
        date.setUTCFullYear(date.getUTCFullYear() + 1);

        var cookieOptions = "; path=/; max-age=31536000; expires=" + date.toUTCString();

        // this bypasses the "mature content - continue/cancel" screen
        document.cookie = "mature_content=1" + cookieOptions;
        // this bypasses the "enter your date of birth" screen
        document.cookie = "birthtime=0" + cookieOptions; // 1970-01-01

        // Reload after making sure we're actually on a page with an age gate
        window.addEventListener("DOMContentLoaded", function () {
            if (document.getElementById("agegate_box") || document.getElementById("app_agegate")) {
                document.body.hidden = true;
                location.reload();
            }
        }, false);
    } else if (location.hostname === "steamcommunity.com") {
        // This bypasses the mature content overlay on community hubs.
        // Since the overlay is put up during page load, we don't have to reload here.
        var appIDs = [];
        var appIDURL = location.pathname.match(/^\/app\/(\d+)/);
        var query = location.search;
        var queryRegex = /[&?]appid=(\d+)/g;
        var match;

        if (appIDURL !== null) {
            appIDs.push(appIDURL[1]);
        }

        while ((match = queryRegex.exec(query)) !== null) {
            appIDs.push(match[1]);
        }

        try {
            for (var i = 0, l = appIDs.length; i < l; i++) {
                window.sessionStorage.setItem("age_gate_" + appIDs[i], "1");
            }
        } catch (ignore) {}

        // Sometimes, we cannot read the app ID from the URL.
        // Example URL (Rust Workshop): https://steamcommunity.com/sharedfiles/filedetails/?id=618543834
        // In this case, just simulate a button press...
        // If this becomes nontrivial, we could also hit the GetPublishedFileDetails API
        window.addEventListener("DOMContentLoaded", function () {
            var btn;

            if ((btn = document.getElementById("age_gate_btn_continue")) !== null) {
                btn.dispatchEvent(new MouseEvent("click"));
            }
        }, false);
    }
})();