- Info: This script looks up the server and community in the url and calculates your highscore position in percentage from the api, then displays it in the top bar and on the overview
- Author: Kraken
- Website:n/a
- Support:
- Download: see code below
- Screenshot:
- Browser: tested with Firefox85.0 (64-bit), Violentmonkey v2.12.8
- Compability: tested with AntiGameReborn 7.1.2 and UniverseView Extension 4.1.4
- Languages:n/a
JavaScript
- // ==UserScript==
- // @name OGame show position in percentage
- // @namespace Violentmonkey Scripts
- // @version 1.0
- // @author Kraken
- // @description 02/02/2021, 00:44:09
- //
- //
- // @include *.ogame*gameforge.com/game/index.php?page*
- // @exclude *.ogame*gameforge.com/game/index.php?page=displayMessageNewPage*
- // ==/UserScript==
- //get user's highscore position from API (updates hourly)
- function getOwnPosition() {
- var url=`https://s${getServer()}-${getCommunity()}.ogame.gameforge.com/api/highscore.xml?category=1&type=0`,xmlhttp;
- xmlhttp=new XMLHttpRequest();
- xmlhttp.open("GET",url,false);
- xmlhttp.send();
- xmlDoc=xmlhttp.responseXML;
- tempPosition = xmlDoc.childNodes[0].outerHTML.toString().search(`${playerId}`);
- return parseInt(xmlDoc.childNodes[0].outerHTML.toString().substring(tempPosition-10,tempPosition-6));
- }
- //gets amount of total players by last place from API (updates hourly)
- function getTotalPlayers() {
- var url=`https://s${getServer()}-${getCommunity()}.ogame.gameforge.com/api/highscore.xml?category=1&type=0`,xmlhttp;
- xmlhttp=new XMLHttpRequest();
- xmlhttp.open("GET",url,false);
- xmlhttp.send();
- xmlDoc=xmlhttp.responseXML;
- totalPlayers = xmlDoc.getElementsByTagName("highscore")[0].lastElementChild.outerHTML;
- return parseInt(totalPlayers.substring(totalPlayers.search("position=\"")+10,totalPlayers.search("\" id")));
- }
- //calculates percentage(2 decimals) and displays next to Highscore link in top bar and in overview details
- function showPercentage() {
- percent = getOwnPosition() / getTotalPlayers() * 100;
- percent = percent.toFixed(2);
- console.log(percent);
- document.getElementById("bar").childNodes[1].childNodes[3].innerHTML = document.getElementById("bar").childNodes[1].childNodes[3].innerHTML.replace(")",`\) ${percent}%`)
- //try-catch because scoreContentField only visible on overview
- try {
- document.getElementById("scoreContentField").innerHTML = document.getElementById("scoreContentField").innerHTML.replace(")",`\) ${percent}%`);
- } catch {}
- }
- showPercentage();
- // gets server from URL
- function getServer() {
- return window.location.href.toString().substring(9,10);
- }
- // gets community/language from URL
- function getCommunity() {
- return window.location.href.toString().substring(11,13);
- }
this is my first attempt at doing something like this. i made this generally for myself because i like to see the number getting smaller as i rise up in points
it might look ugly to you, but i am very proud and it works i know a lot is copy and paste and it took a lot of tries to get data from api. i almost quit
if there is anything wrong please reach out to me and help is greatly appreciated. i want to improve