SteamGifts Access Keys

Access Key Helpers for SteamGifts

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SteamGifts Access Keys
// @namespace    http://www.linuxmint.ro/
// @version      1.0
// @description  Access Key Helpers for SteamGifts
// @author       Nicolae Crefelean
// @match        https://www.steamgifts.com/giveaway/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // these are the control elements for the "back" and "hide" features
    const head = document.head;
    const hidePopup = document.querySelector(".popup--hide-games");
    const hideButton = document.querySelector(".trigger-popup");
    const hideConfirm = document.querySelector(".js__submit-hide-games");

    // these are the control elements for the giveaway's "enter/remove entry"
    const form = document.querySelector(".sidebar > form");
    const addButton = document.querySelector("div[data-do='entry_insert']");
    const removeButton = document.querySelector("div[data-do='entry_delete']");

    // there is no form to enter/withdraw in/from the giveaway when you lack the points
    // own the game or it's above your level, so make sure there is a form before using it
    if (form !== null) {
        // define the access key and event handler for toggling the entrance/withdrawal in/from a giveaway
        form.setAttribute("accesskey", "a");
        form.addEventListener("click", toggleEntry, true);
    }

    // don't try to add hiding controls for games that are already hidden
    if (hidePopup !== null) {
        // define the access key and event handler for hiding games
        hidePopup.setAttribute("accesskey", "q");
        hidePopup.addEventListener("click", clickHide, true);
    }

    // define the access key and event handler for going back to the previous page
    head.setAttribute("accesskey", "z");
    head.addEventListener("click", goBack, true);

    // event handler for entering/withdrawing in/from a giveaway
    function toggleEntry() {
        addButton.classList.contains("is-hidden") ? removeButton.click() : addButton.click();
    }

    // event handler for hiding games
    function clickHide() {
        switch (hidePopup.style.display) {
            case "none":
            case "":
                if (hideButton !== null) {
                    hideButton.click();
                }
                break;
            case "block":
                hideConfirm.click();
        }
    }

    // event handler for returning to the giveaways page
    function goBack() {
        history.length > 1 ? history.back() : location.href = "/";
    }
})();