SteamGifts GA input

Adds input on top menu where you can enter 5characters of GA id and it will open the GA page for you.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         SteamGifts GA input
// @description  Adds input on top menu where you can enter 5characters of GA id and it will open the GA page for you.
// @author       Bladito
// @version      1.0.0
// @homepageURL  https://greasyfork.org/en/users/55159-bladito
// @match        https://www.steamgifts.com/*
// @namespace    Bladito/sg-ga-input
// @require      http://code.jquery.com/jquery-latest.js
// @grant        GM_addStyle
// ==/UserScript==

(function($) {
    'use strict';

    var $input = $('<input id="bsg-ga-input">');
    $input.on('input', function(event) {
        var value = event.target.value;
        if (value.length === 5) {
            var url = 'https://www.steamgifts.com/giveaway/' + value + '/';
            $.get(url, function(data) {
                if ($(data).find('.sidebar__navigation__item__name').text().indexOf('Entries') > -1) { // it is a giveaway page
                    window.open(url, '_blank');
                    $('#bsg-ga-input').removeClass('bsg-invalid');
                } else {
                    $('#bsg-ga-input').addClass('bsg-invalid');
                }
            });
        }
    });
    $('.nav__left-container').append($input);

    addStyles();

    //---------------------------------------------------------------------------------

    function addStyles() {
        GM_addStyle('#bsg-ga-input { ' +
                    'width: 100px;' +
                    'color: white;' +
                    'background-color: #3d434f;' +
                    'border: 1px solid #6e7788;' +
                    '}');
        GM_addStyle('#bsg-ga-input:focus { ' +
                    'color: black;' +
                    'background-color: white;' +
                    '}');
        GM_addStyle('#bsg-ga-input.bsg-invalid { ' +
                    'border: 1px solid red;' +
                    '}');
        GM_addStyle('#bsg-ga-input.bsg-invalid:focus { ' +
                    'background-color: #ffd2d2;' +
                    'border: 1px solid red;' +
                    '}');
    }

})(jQuery);