SteamGifts Access Keys

Access Key Helpers for SteamGifts

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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 = "/";
    }
})();