eduardog3000 / 270towin Color Picker

// ==UserScript==
// @name         270towin Color Picker
// @version      0.3
// @description  Adds ability to use keyboard to pick colors in 270towin Maps.
// @author       eduardog3000
// @match        http*://www.270towin.com/*-election/
// @match        http*://www.270towin.com
// @grant        none
// @license 0BSD
// @updateURL https://openuserjs.org/meta/eduardog3000/270towin_Color_Picker.meta.js
// ==/UserScript==

(function() {
    'use strict';

    for(var i = 0; i <= 6; i++) {
        document.styleSheets[0].insertRule('td[color_value="' + i + '"]::after { content: "' + i + '"; color: #fff; }');
    }

    document.styleSheets[0].insertRule('td[color_value="7"] { font-size: 0; }');
    document.styleSheets[0].insertRule('td[color_value="7"]::before { font-size: 10pt; }');
    document.styleSheets[0].insertRule('td[color_value="7"]::after { content: " 7"; color: #fff; font-size: 10pt; }');

    document.styleSheets[0].insertRule('td[color_value="a"]::after { content: "a"; color: #fff; }');
    document.styleSheets[0].insertRule('td[color_value="b"]::after { content: "b"; color: #fff; }');

    $(window).keypress(function(e) {
        if(['0', '1', '2', '3', '4', '5', '6', '7', 'a', 'b'].includes(e.key)) {
            $('td[color_value=' + e.key + ']').click();
        }
    });
})();