33// @namespace http://tampermonkey.net/
44// @updateURL https://gist.githubusercontent.com/feildmaster/d151a1cc3c7055bfd8b3323ae1529046/raw/undercards.meta.js
55// @downloadURL https://gist.githubusercontent.com/feildmaster/d151a1cc3c7055bfd8b3323ae1529046/raw/undercards.js
6- // @version 0.1
7- // @description Minor changes to undercards game
6+ // @require https://gist.githubusercontent.com/feildmaster/d151a1cc3c7055bfd8b3323ae1529046/raw/utilities.js?v=1
7+ // @version 0.2
8+ // @description try to take over the world!
89// @author feildmaster
9- // @match https://undercards.net:8181/Play
10+ // @match https://undercards.net:8181/*
1011// @grant none
12+ // @history 0.2 - Added EndTurn hotkey (space, middle click), focus chat (enter)
1113// @history 0.1 - Made deck selection smart
1214// ==/UserScript==
1315
14- // Play changes
16+ // === Variables start
17+ var hotkeys = [
18+ new Hotkey ( "Focus Chat" ) . bindKey ( 13 ) . run ( function ( e ) { // Join/Show chat and position cursor to input box
19+ if ( hide ) {
20+ // This currently already works
21+ }
22+ $ ( '#message' ) . focus ( ) ; // Always do this
23+ } ) ,
24+ ] ;
25+ // === Variables end
26+
27+ // === Play changes start
1528if ( location . pathname === "/Play" ) {
1629 // Classic class storage
1730 if ( localStorage . lastClassic && $ ( '#rankedDecks option' ) . filter ( ( i , o ) => o . value === localStorage . lastRanked ) . length !== 0 ) {
@@ -28,4 +41,46 @@ if (location.pathname === "/Play") {
2841 $ ( '#rankedDecks' ) . change ( function updateRank ( ) {
2942 localStorage . lastRanked = $ ( '#rankedDecks option:selected' ) . val ( ) ;
3043 } ) ;
44+
45+ // TODO: Better "game found" support
46+ }
47+ // === Play changes end
48+
49+ // === Game changes start
50+ if ( location . pathname === "/Game" ) {
51+ var started = false ;
52+ // TODO: more Hotkeys
53+ hotkeys . push ( new Hotkey ( "End turn" ) . bindKey ( 32 ) . bindClick ( 2 ) . run ( ( e ) => { if ( started && ! $ ( e . target ) . is ( "#endTurnBtn" ) && userTurn && userTurn === userId ) endTurn ( ) ; } ) ) ; // Binds to Space, Middle Click
54+
55+ // TODO: Event log
56+ // TODO: Visual attack targets
57+ var oHandler = socket . onmessage ;
58+ socket . onmessage = function onMessageScript ( event ) {
59+ var data = JSON . parse ( bin2str ( event . data ) ) ;
60+ if ( data . action === "getGameStarted" ) {
61+ // We're running our game.
62+ started = true ;
63+ }
64+ oHandler ( event ) ;
65+ } ;
3166}
67+ // === Game changes end
68+
69+ // === Always do the following
70+ // Bind hotkey listeners
71+ $ ( ".mainContent" ) . on ( "click.script" , function ( event ) {
72+ if ( false ) return ; // TODO: Check for clicking in chat
73+ hotkeys . forEach ( function ( v ) {
74+ if ( v . clickbound ( event . which ) ) {
75+ v . run ( event ) ;
76+ }
77+ } ) ;
78+ } ) ;
79+ $ ( document ) . on ( "keyup.script" , function ( event ) {
80+ if ( $ ( event . target ) . is ( "input" ) ) return ; // We don't want to listen while typing in chat (maybe listen for F-keys?)
81+ hotkeys . forEach ( function ( v ) {
82+ if ( v . keybound ( event . which ) ) {
83+ v . run ( event ) ;
84+ }
85+ } ) ;
86+ } ) ;
0 commit comments