Skip to content

Instantly share code, notes, and snippets.

@panych
Last active December 16, 2022 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panych/1d03572aaaeb4da8788e0d4f92aebd70 to your computer and use it in GitHub Desktop.
Save panych/1d03572aaaeb4da8788e0d4f92aebd70 to your computer and use it in GitHub Desktop.
Glastonbury helper for site happymeeple.com
// ==UserScript==
// @name Glastonbury helper
// @namespace http://tampermonkey.net/
// @version 1.1
// @description
// @author a.s.panchenko@gmail.com
// @match https://www.happymeeple.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=happymeeple.com
// @grant none
// ==/UserScript==
/*
How to use:
1. Get the running game app instance.
1.1. Devtools -> Debugger -> File /js/game_specific/GB/min/GB_controller/GB_controller
1.2. Breakpoint in method click_start_position (before running first move) or click_card
1.3. Save `this` to global or immediately provide it to `gbHelper.init`
2. run gbHelper.init(gameAppObject)
To stop: gbHelper.stop().hide()
To continue: gbHelper.run()
*/
(function() {
if (window.gbHelper) { return };
const GBHelper = class {
static version = '1.1';
gameApp = null;
intervalId = null;
scoreEl = null;
constructor() {}
init(gameApp) {
this.gameApp = gameApp;
this.scoreEl = document.createElement('div');
document.getElementById('GB_bonus_2nd_player').appendChild(this.scoreEl);
this.run();
}
run() {
this.intervalId = setInterval(this._update.bind(this), 1000);
return this;
}
stop() {
clearInterval(this.intervalId);
return this;
}
hide() {
this.gameApp.view_show_scoring(false);
return this;
}
_update() {
if (this.gameApp.game.endgame_status !== 1) {
this.stop();
}
if (this.gameApp.game.phase === this.gameApp.game.PHASE_LOOK_AT_CARDS) {
return;
}
this.gameApp.view_show_scoring(true);
this._updateScore();
}
_getScore() {
return [
this.gameApp.game.game_get_game_points(this.gameApp.game, 1, 0),
this.gameApp.game.game_get_game_points(this.gameApp.game, 2, 0)
]
}
_updateScore() {
const s = this._getScore();
this.scoreEl.innerText = `Score: ${s[0]} | ${s[1]}`;
}
}
window.gbHelper = new GBHelper();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment