Last active
August 29, 2015 14:22
-
-
Save igromanru/36bf7d38d7d26e140b06 to your computer and use it in GitHub Desktop.
GalaxyScan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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 injectedFunction = (function() { | |
var GalaxyScan = { | |
scanGalaxy: function(galaxyFrom, galaxyTo, sunsysFrom, sunsysTo) { | |
for(i = sunsysFrom; i <= sunsysTo; i++) { | |
(function(i) { | |
setInterval(function(){ | |
if(i <= sunsysTo) { | |
$('#galaxy_input').val(galaxyFrom); | |
$('#system_input').val(i); | |
$('#showbutton').trigger('click'); | |
} | |
}, 500)} | |
)(i); | |
} | |
} | |
}; | |
$.fn.exists = function () { | |
return this.length !== 0; | |
}; | |
$( '#scanOptions' ).dialog({ | |
autoOpen: false, | |
open: function(event, ui) { | |
var galaxyNr = $('#galaxy_input').val(); | |
$('#galaxyFrom').val(galaxyNr); | |
$('#galaxyTo').val(galaxyNr); | |
}, | |
buttons: { | |
Scan : { | |
text: 'Scan', | |
id: 'dialogScanBut', | |
click: function() { | |
var ok = confirm('\Scan can not be stopped!\r\nDo you want to continue?'); | |
if (ok == true) { | |
$( this ).dialog( 'close' ); | |
GalaxyScan.scanGalaxy($('#galaxyFrom').val(),$('#galaxyTo').val(),$('#sunsysFrom').val(),$('#sunsysTo').val()); | |
} | |
} | |
}, | |
Cancel : { | |
text: 'Cancel', | |
id: 'dialogScanCancel', | |
click: function() { | |
$( this ).dialog( 'close' ); | |
} | |
} | |
} | |
}); | |
$('#buttonScanGalaxy' ).click(function() { | |
$( '#scanOptions' ).dialog( 'open' ); | |
}); | |
}).toString(); | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
function injectIncludeScript(scriptUrl) { | |
var script = document.createElement ("script"); | |
script.setAttribute ("src", scriptUrl); | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} | |
function injectScript(functionString) { | |
var script = document.createElement ("script"); | |
script.setAttribute ("type", "application/javascript"); | |
script.textContent = "(" + functionString + ") ();"; | |
document.body.appendChild (script); | |
} | |
function injectHtml() { | |
var butHtml = '<a id="buttonScanGalaxy" href="javascript:void(0);" ><span class="bleft"></span><span class="text">Scan Galaxy</span><span class="bright"></span></a>'; | |
var buttonsDiv = getElementByXpath("//tr[@id='galaxyheadbg']/td/div"); | |
var scanDiv = document.createElement('div'); | |
scanDiv.setAttribute('id',"scanGalaxyButton"); | |
scanDiv.innerHTML = butHtml; | |
buttonsDiv.appendChild(scanDiv); | |
var guiHtml = '<span class="textlabel">Scan galaxy</span> \ | |
<br/> \ | |
<input type="number" size="5" id="galaxyFrom" min="1" max="9" value="1"> \ | |
<span class="textlabel" style="display:none">to</span> \ | |
<input type="number" size="5" id="galaxyTo" min="1" max="9" value="1" style="display:none"> \ | |
<br/><br/> \ | |
<span class="textlabel">Scan sun system</span> \ | |
<br/> \ | |
<input type="number" size="5" id="sunsysFrom" min="1" max="499" value="1"> \ | |
<span class="textlabel">to</span> \ | |
<input type="number" size="5" id="sunsysTo" min="1" max="499" value="499">'; | |
var divGui = document.createElement('div'); | |
divGui.setAttribute('id',"scanOptions"); | |
divGui.setAttribute('title',"GalaxyScan"); | |
divGui.innerHTML = guiHtml; | |
document.getElementsByTagName("body")[0].appendChild(divGui); | |
} | |
function injectCss() { | |
var scanButtonCss = '#buttonScanGalaxy { color: #fff; display: block } #buttonScanGalaxy:hover { color: #9c0; }'; | |
var guiCss = '#galaxyFrom, #galaxyTo, #sunsysFrom, #sunsysTo { width: 50px;}'; | |
var style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = scanButtonCss + guiCss; | |
document.getElementsByTagName("head")[0].appendChild(style); | |
} | |
if (document.body) { | |
injectIncludeScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"); | |
injectHtml(); | |
injectCss(); | |
injectScript(injectedFunction); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment