Skip to content

Instantly share code, notes, and snippets.

@benjuang
Last active June 11, 2020 20:42
Show Gist options
  • Save benjuang/aaeaed1e1b77685b9a7953c1f98778bf to your computer and use it in GitHub Desktop.
Save benjuang/aaeaed1e1b77685b9a7953c1f98778bf to your computer and use it in GitHub Desktop.
Quick hacks to make my Rampart experience better
// ==UserScript==
// @name Warbook
// @namespace http://tampermonkey.net/
// @version 0.2
// @description try to take over the world!
// @author You
// @match https://www.playrampart.com/
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle(`
.card-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
height: auto;
overflow: auto;
max-width: 900px;
margin: auto;
}
.card-list .building-item {
flex: 0;
height: fit-content; /* Not supported on all browsers, but works for Chrome */
float: none; /* No need to float if using flex */
}
.building-item .action-bar {
display: flex;
flex-wrap: wrap;
}
.action-bar button {
margin-bottom: 12px;
}
.stat-list [data-listener=hero_name] {
word-break: break-word;
}
.search-details {
color: white;
background: black;
padding: 3px;
font-size: smaller;
}
`);
const $tickTimer = $(".tick-timer");
const $withMin = $("<span class='with-min'>");
$tickTimer.append($withMin);
// Find our tick starting point
const currentSeconds = parseInt($("[data-listener=next_tick_in]").text(), 10);
const timerSeeker = setInterval(() => {
const newSeconds = parseInt($("[data-listener=next_tick_in]").text(), 10);
if (currentSeconds != newSeconds) {
// a second just elapsed, start our timer parser!
clearInterval(timerSeeker);
registerMinTimer();
}
}, 10);
function registerMinTimer() {
setInterval(() => {
let seconds = parseInt($("[data-listener=next_tick_in]").text(), 10);
const minutes = Math.floor(seconds / 60);
seconds = seconds%60;
if (seconds < 10) {
seconds = "0" + seconds;
}
$withMin.text(`(${minutes}:${seconds})`);
checkForAlliedKingdoms();
}, 1000);
}
// load known alliance kingdoms
let alliedKingdoms = [];
setTimeout(() => {
$(".nav-alliance").click();
alliedKingdoms = $(".alliance-member").map((_, e)=>{return e.innerHTML}).toArray();
setTimeout(() => {
$(".modal-footer [data-dismiss=modal]").click();
}, 1000);
console.log("Allied Kingdoms identified:", alliedKingdoms);
}, 1000);
// load news
let inboundAttacks = {};
// TODO: refresh inboundAttacks when we revisit the news page.
setTimeout(() => {
$(".nav-news").click();
setTimeout(() => {
$(".news-item").each((_, e)=>{
console.log(e.innerText)
const fireball = e.innerText.match(/fireballed by (.*)! /);
if (fireball) {
console.log("matched an fireball");
const kingdom = fireball[1];
if (!inboundAttacks[kingdom]) {
inboundAttacks[kingdom] = {};
}
if (!inboundAttacks[kingdom]['fireball']) {
inboundAttacks[kingdom]['fireball'] = 0;
}
inboundAttacks[kingdom]['fireball']++;
return;
}
const attack = e.innerText.match(/attacked by (.*)! You lost (\d+)/);
if (attack) {
console.log("matched an attack");
const kingdom = attack[1];
const damage = parseInt(attack[2], 10);
if (!inboundAttacks[kingdom]) {
inboundAttacks[kingdom] = {};
}
if (!inboundAttacks[kingdom]['attack']) {
inboundAttacks[kingdom]['attack'] = 0;
}
if (!inboundAttacks[kingdom]['damage']) {
inboundAttacks[kingdom]['damage'] = 0;
}
inboundAttacks[kingdom]['attack']++;
inboundAttacks[kingdom]['damage'] += damage;
}
});
console.log("inboundAttacks parsed", inboundAttacks);
$(".nav-kingdom").click();
}, 1000);
}, 1000);
function checkForAlliedKingdoms() {
// I'm so sorry.
if ($(".search-result").length > 0 && !$(".search-result").data("scanned")) {
$(".search-result").data("scanned", true) ;
$(".search-result").each((_, e) => {
const kingdomName = $(e).children("h3").text();
if (alliedKingdoms.includes(kingdomName)){
console.log("Ally found!");
$(e).css("opacity", 0.5);
}
if (Object.keys(inboundAttacks).includes(kingdomName)){
console.log("Enemy found!");
console.log(inboundAttacks[kingdomName]);
$(e).append(`<div class="search-details">Attacks:${inboundAttacks[kingdomName]['attack']}<br/>Acres stolen:${inboundAttacks[kingdomName]['damage']}<br/>Fireballs:${inboundAttacks[kingdomName]['fireball']}<br/>`);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment