SteamGifts Access Keys

Access Key Helpers for SteamGifts

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

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

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

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

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