Skip to content

Instantly share code, notes, and snippets.

@mihaeu
Last active February 10, 2017 15:59
Show Gist options
  • Save mihaeu/5fc12fdc2c99696fdf9405205643e301 to your computer and use it in GitHub Desktop.
Save mihaeu/5fc12fdc2c99696fdf9405205643e301 to your computer and use it in GitHub Desktop.
Terra Mystica script for Tampermonkey
// ==UserScript==
// @name Terra Mystica Extensions
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adapts visuals for smaller screens and adds shortcuts to Snellmans Terra Mystica Online.
// @author Michael Haeuslmann <haeuslmann@gmail.com>
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser-polyfill.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js
// @match http://terra.snellman.net/*
// ==/UserScript==
/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext: true */
let removeHeader = () => {
document.getElementById('header').style.display = 'none';
};
let moveFactionsToTheRight = () => {
document.querySelectorAll('.faction-board, .pool').forEach((element) => {
element.style.width = '250px';
});
document.getElementById('factions').style = "position:absolute;top:10px;left:1075px;";
};
let removeColorBlindSwitcher = () => {
let mainTable = document.querySelector('#main-data tbody');
mainTable.removeChild(mainTable.childNodes[1]);
};
let refresh = () => {
loadGame(document.location.host, document.location.pathname);
};
let save = () => {
document.getElementById('move_entry_action').click();
};
let undo = () => {
document.getElementById('move_picker_undo').childNodes[0].click();
};
let toggleVisibility = (element) => {
element.style.visibility = element.style.visibility === 'hidden' ? 'visible' : 'hidden';
};
let toggleFactions = () => {
const LEFT_ALIGN_PX = '5px';
const RIGHT_ALIGN_PX = '1075px';
toggleVisibility(document.getElementById('map'));
toggleVisibility(document.getElementById('cults'));
let factions = document.getElementById('factions');
factions.style.left = factions.style.left === RIGHT_ALIGN_PX ? LEFT_ALIGN_PX : RIGHT_ALIGN_PX;
};
let addKeyboardShortcuts = () => {
const KEY_REFRESH = 82;
const KEY_SAVE = 83;
const KEY_UNDO = 85;
const KEY_TOGGLE_FACTIONS = 76;
document.addEventListener('keydown', (event) => {
switch (event.keyCode) {
case KEY_REFRESH:
refresh();
break;
case KEY_SAVE:
save();
break;
case KEY_UNDO:
undo();
break;
case KEY_TOGGLE_FACTIONS:
toggleFactions();
break;
}
});
};
moveFactionsToTheRight();
removeColorBlindSwitcher();
removeHeader();
addKeyboardShortcuts();
/* jshint ignore:start */
]]></>).toString();
var c = babel.transform(inline_src);
eval(c.code);
/* jshint ignore:end */
Copyright 2017 Michael Haeuslmann
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in th
e Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so, subj
ect to the following conditions:
The above copyright notice and this permission notice shall be included in all c
opies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
ED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYR
IGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT
H THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment