GC - Gormball character selector and prize logger

Remembers your last played character and up to 100 prizes

目前為 2022-12-15 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GC - Gormball character selector and prize logger
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Remembers your last played character and up to 100 prizes
// @author       wibreth
// @match        https://www.grundos.cafe/games/gormball/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';
    /* globals $:false */

    GM_addStyle('#prize-list {\
    max-width: 200px;\
    font-size: .8em;\
    max-height: 200px;\
    overflow: auto;\
    border: 1px solid #000;\
    position: absolute;\
    background: #fff;\
    padding: 5px 5px 5px 35px;\
    z-index: 3;\
    right: 0;\
}\
#prize-list-btn, #clear-list-btn {\
    float: right;\
    margin-top: -6px;\
}\
#page_content > p {\
    position: relative;\
}\
img[src$="gorm.gif"] {\
    cursor: pointer;\
}');


    $('document').ready(() => {
        let listLoaded = false;
        let listVisible = false;

        // log prizes
        if ($('strong:contains("Your Prize")').length != 0) { //win page
            let prizeList = GM_getValue("prizeList", []);
            if (prizeList.push($('.mt-1 strong').text()) > 100) // max of 100 items stored
                prizeList.shift();
            GM_setValue("prizeList", prizeList);
        }

        // show prizes
        let showbtn = $('<input type="button" id="prize-list-btn" value="Show Prize Log">');
        showbtn.click(() => {
            if (listVisible) {
                $('#prize-list').hide();
                listVisible = false;
                return;
            }
            if (listLoaded) {
                $('#prize-list').show();
                listVisible = true;
                return;
            }
            let prizeList = GM_getValue("prizeList", []);
            let $prizeList = $('<ol id="prize-list">');
            if (!prizeList.length)
                $prizeList.append('<li>none!</li>');
            for (const prize of prizeList)
                $prizeList.append(`<li>${prize}</li>`);
            $('#page_content > p').append($prizeList);
            listLoaded = true;
            listVisible = true;
        });
        let clearbtn = $('<input type="button" id="clear-list-btn" value="Clear Prize Log">');
        clearbtn.click((e) => {
            if (!confirm("Are you sure you want to clear the prize log?")) {
                e.preventDefault();
                return;
            }
            if (listLoaded)
                $('#prize-list').empty();
            GM_setValue("prizeList", []);
        });
        $('#page_content > p:first-of-type').append(showbtn);
        $('#page_content > p:first-of-type').append(clearbtn);


        if ($('img[src$="gorm.gif"]').length == 0)
            return; //not on the character select page

        let playerDD = GM_getValue("playerDD", 1); //default Thyassa
        $('#playerDD').val(playerDD);

        $('.gormball_player').click(function() {
            playerDD = $(this).data('id');
            GM_setValue("playerDD", playerDD);
        });

        let clicked = false;
        $('img[src$="gorm.gif"]').click(() => {
            if (clicked)
                return;
            clicked = true;
            $('form#play_gormball').submit();
        });


    });
})();