Skip to content

Instantly share code, notes, and snippets.

@igromanru
Last active August 29, 2015 14:22
Show Gist options
  • Save igromanru/36bf7d38d7d26e140b06 to your computer and use it in GitHub Desktop.
Save igromanru/36bf7d38d7d26e140b06 to your computer and use it in GitHub Desktop.
GalaxyScan
// ==UserScript==
// @name GalaxyScan
// @namespace IgroGalaxyScan
// @author Igromanru
// @include *.ogame.gameforge.com/game/index.php?page=galaxy*
// @description Browsing through the Universe to get the data for GalaxyTool
// @version 0.1
// @grant none
// ==/UserScript==
var scriptFunc = (function() {
$.fn.exists = function () {
return this.length !== 0;
};
}).toString();
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function injectScript (myFunc) {
var script = document.createElement ("script");
script.setAttribute ("type", "application/javascript");
script.textContent = "(" + myFunc + ") ();";
document.body.appendChild (script);
}
function injectHtml() {
var buttonsDiv = getElementByXpath("//tr[@id='galaxyheadbg']/td/div");
var scanDiv = document.createElement('div');
scanDiv.setAttribute('id',"scanGalaxyButton");
scanDiv.innerHTML = '<a id="buttonScanGalaxy" onclick="doScanGalaxy();" href="javascript:void(0);"><span class="bleft"></span><span class="text">Scan Galaxy</span><span class="bright"></span></a>';
buttonsDiv.appendChild(scanDiv);
}
function injectCss() {
var scanButtonCss = '#buttonScanGalaxy { color: #fff; display: block } #buttonScanGalaxy:hover { color: #9c0; }';
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = scanButtonCss;
document.getElementsByTagName("head")[0].appendChild(style);
}
if (document.body) {
//injectScript(scriptFunc);
injectHtml();
injectCss();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment