Skip to content

Instantly share code, notes, and snippets.

@seanvikoren
Created October 7, 2016 01:41
Show Gist options
  • Save seanvikoren/a406d84c7a1bd5a8cb69f4880f9f7424 to your computer and use it in GitHub Desktop.
Save seanvikoren/a406d84c7a1bd5a8cb69f4880f9f7424 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name OGameInterfaceFix
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Monkey with interface.
// @author You
// @match https://s116-us.ogame.gameforge.com/game/index.php?page=galaxy*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
var recyclerLimit = 10;
document.onkeydown = checkKey;
function cat() { alert('cat'); }
function fish() { alert('fish'); }
function monkey() { alert('monkey'); }
var readyCount = 0;
function controller() {
readyCount += 1;
if (readyCount == 2) {
rebuildGalaxy();
}
}
function rebuildGalaxy() {
var galaxyContent = document.querySelector('#galaxyContent');
var lootFound = false;
var shipsRequired = 0;
if (galaxyContent) {
var galaxyTable = galaxyContent.querySelector('#galaxytable');
if (galaxyTable) {
var rowList = galaxyTable.rows;
for (var i = 2; i < 17; i++) {
var row = rowList[i];
var orderSlot = row.cells[0];
var j = i - 1;
//console.log(' pew...' + j);
var debrisSelector = '#debris' + j + ' > ul.ListLinks > li.debris-recyclers';
var recyclerCountSource = document.querySelector(debrisSelector);
if (recyclerCountSource) {
var recyclerCount = +(recyclerCountSource.innerHTML.split(': ')[1]);
if (recyclerCount >= recyclerLimit) {
orderSlot.innerHTML = '>' + recyclerCount;
lootFound = true;
shipsRequired += recyclerCount;
} else {
orderSlot.innerHTML = '-' + j;
}
} else {
orderSlot.innerHTML = '-' + j;
}
}
if (lootFound) { alert('Send ' + shipsRequired + ' ships!'); }
} else {
console.log(' No GalaxyTable found...');
}
} else {
console.log(' No Galaxy found...');
}
}
console.log('Begin...no privledge');
//$("body").prepend ('<h1>CaT</h1>');
var galaxyButtonNext = document.querySelector('#galaxyHeader > form > span:nth-child(8)');
var galaxyButtonPrevious = document.querySelector('#galaxyHeader > form > span:nth-child(6)');
galaxyButtonNext.addEventListener("click", function(){ readyCount = 0; });
galaxyButtonPrevious.addEventListener("click", function(){ readyCount = 0; });
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '38') { // up arrow
} else if (e.keyCode == '40') { // down arrow
} else if (e.keyCode == '37') { // left arrow
readyCount = 0;
} else if (e.keyCode == '39') { // right arrow
readyCount = 0;
}
}
//ajaxSuccess
//ajaxComplete
$(document).ajaxComplete(controller);
// .ajaxStop
//$('#galaxyLoading').ajaxStop(galaxyCat);
//$('#galaxyContent').ajaxStop(galaxyCat);
console.log('End');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment