<commit_before>// ==UserScript==
// @name			Show Income On Top
// @description		Shows the actual income also on top of the site.
// @namespace		http://*.ikariam.*/*
// @author			TOBBE
// @version			1.05
//
// @require			http://www.betawarriors.com/bin/gm/57756user.js
//
// @include			http://*.ikariam.*/index.php?view=finances
//
// @exclude			http://board.ikariam.*/*
// @exclude			http://support.ikariam.*/*
// @exclude			http://support.*.ikariam.*/*
// 
// @history			1.05	Added new Script Updater - will be replaced by my own Updater in the next few days.
// @history			1.04	Fixed: Due to the Problem with Greasemonkey-Scripts I remove the Script-Updater. It has been written by the same guy who probably has written the infected Script.
// @history			1.03	Fixed: Bug with , as seperator
// @history			1.03	Added: New style of update-panel
// @history			1.02	Fixed: Cleaned up code
// @history			1.02	Added: Income in 24h
// @history			1.01	Added: Update check
// @history			1.00	Initial release
// ==/UserScript==

// Version and Script-ID
var version = 1.05;
var scriptId = 74221;

// Seperator ist an point or not
var point = true;

// Set the Style
setStyles();

// Check for Updates
ScriptUpdater.check(scriptId, version);

// Start script
main();

// Main-function of the script.
function main() {
	var income = getIncome();
	
	var balance = document.getElementById('balance');
	
	incomeRow = balance.insertRow(1);
	incomeRow24h = balance.insertRow(2);
	
	createTableRow(new Array("+/-", "", "", formatToIkaNumber(income)), new Array("sigma", "value res", "value res", "value res"), incomeRow);
	createTableRow(new Array("+/- in 24h", "", "", formatToIkaNumber(income * 24)), new Array("sigma", "value res", "value res", "value res"), incomeRow24h);
}

// Returns the actual income.
function getIncome() {
	var hidden = document.getElementsByClassName('hidden');
	var txt = hidden[hidden.length - 1].innerHTML;

	if(txt.search(",") != -1) {
		txt = txt.replace(",", "");
		point = false;
	} else {
		txt = txt.replace(".", "");
	}

	return Number(txt);
}

// Formats a number to that format that is used in Ikariam.
function formatToIkaNumber(num) {
	num += "";

	if(point) {
		num = num.replace(/(\d)(?=(\d{3})+\b)/g,"$1.");
	} else {
		num = num.replace(/(\d)(?=(\d{3})+\b)/g,"$1,");
	}

	return num;
}

// Adds cells to an table row.
function createTableRow(cellText, cellClassName, row) {
	for(var i = 0; i < 4; i++) {
		var cell = document.createElement("td");
		var cell_Text = document.createTextNode(cellText[i]);
		
		cell.appendChild(cell_Text);
		cell.className = cellClassName[i];
		row.appendChild(cell);
	}
}

function setStyles() {
	// #ddb577 Dark
	// #fdf7dd Bright
	// #542c0f Font/Border
	
	GM_addStyle(
			"#ScriptUpdater74221Mask { position:fixed !important; } \
			#ScriptUpdater74221Body { position:fixed !important; background-color:#fdf7dd !important; border:#542c0f !important; color:#542c0f !important; } \
			#ScriptUpdater74221Body h1 { background-color:#ddb577 !important; -moz-border-radius:5px !important;}"
	);
}<commit_msg>Version 1.3.2 for history purpose<commit_after>// ==UserScript==
// @name			Show Income On Top
// @description		Shows the actual income also on top of the site.
// @namespace		http://*.ikariam.*/*
// @author			TOBBE
// @version			1.06
//
// @include			http://*.ikariam.*/index.php?view=finances
//
// @exclude			http://board.ikariam.*/*
// @exclude			http://support.ikariam.*/*
// @exclude			http://support.*.ikariam.*/*
// 
// @history			1.06	Added: Own Script-Updater.
// @history			1.06	Fixed: Remove everything what refered to other Scripts.
// @history			1.05	Added: New Script-Updater - will be replaced by my own Updater in the next few days.
// @history			1.04	Fixed: Remove the Script-Updater (Because of the Problem with Greasemonkey-Scripts).
// @history			1.03	Fixed: Bug with , as seperator
// @history			1.03	Added: New style of update-panel
// @history			1.02	Fixed: Cleaned up code
// @history			1.02	Added: Income in 24h
// @history			1.01	Added: Update check
// @history			1.00	Initial release
// ==/UserScript==

// Version and Script-ID
var version = 1.06;
var scriptId = 74221;

// Check for Updates
checkForUpdates();

// Seperator ist an point or not
var point = true;

// Set the Style
setStyles();

// Start script
main();

// Main-function of the script.
function main() {
	var income = getIncome();
	
	var balance = document.getElementById('balance');
	
	incomeRow = balance.insertRow(1);
	incomeRow24h = balance.insertRow(2);
	
	createTableRow(new Array('+/-', '', '', formatToIkaNumber(income)), new Array('sigma', 'value res', 'value res', 'value res'), incomeRow);
	createTableRow(new Array('+/- in 24h', '', '', formatToIkaNumber(income * 24)), new Array('sigma', 'value res', 'value res', 'value res'), incomeRow24h);
}

// Returns the actual income.
function getIncome() {
	var hidden = document.getElementsByClassName('hidden');
	var txt = hidden[hidden.length - 1].innerHTML;

	if(txt.search(',') != -1) {
		txt = txt.replace(',', '');
		point = false;
	} else {
		txt = txt.replace('.', '');
	}

	return Number(txt);
}

// Formats a number to that format that is used in Ikariam.
function formatToIkaNumber(num) {
	num += '';

	if(point) {
		num = num.replace(/(\d)(?=(\d{3})+\b)/g,'$1.');
	} else {
		num = num.replace(/(\d)(?=(\d{3})+\b)/g,'$1,');
	}

	return num;
}

// Adds cells to an table row.
function createTableRow(cellText, cellClassName, row) {
	for(var i = 0; i < cellText.length; i++) {
		var cell = document.createElement('td');
		
		cell.innerHTML = cellText[i];
		cell.className = cellClassName[i];
		row.appendChild(cell);
	}
}

// Checks for Updates of the Script.
function checkForUpdates(){
	GM_xmlhttpRequest ({
		method: 'GET',
		url: 'http://userscripts.org/scripts/source/74221.meta.js',
		headers: {'User-agent': 'Mozilla/5.0', 'Accept': 'text/html'},
		onload: function (response) {
			var metadata = formatMetadata(response.responseText);

			if(version < metadata.version) {
				showUpdateInfo(metadata);
			}
		}
	});
}

// Formats the given Metadata.
function formatMetadata(metadataIn) {
	var metadataOut = new Array();
	var innerMeta = metadataIn.match(/\/\/ ==UserScript==((.|\n|\r)*?)\/\/ ==\/UserScript==/)[0];
	
	if(innerMeta) {
		var tags = innerMeta.match(/\/\/ @(.*?)(\n|\r)/g);
		
		for(var i = 0; i < tags.length; i++) {
			var tmp = tags[i].match(/\/\/ @(.*?)\s+(.*)/);
			
			if(!metadataOut[tmp[1]]) {
				metadataOut[tmp[1]] = new Array (tmp[2]);
				
			} else {
				metadataOut[tmp[1]].push(tmp[2]);
				
			}
		}
	}

	return metadataOut;
}

// Shows the Update information
function showUpdateInfo(metadata) {
	balance = document.getElementById('balance');
	
	updateRow = balance.insertRow(3);
	infoRow = balance.insertRow(4);
	
	var updateInfo = '<br><br>';
	
	for(var i = 0; i < metadata['history'].length; i++) {
		updateInfo += metadata['history'][i] + '<br><br>';
	}
	
	createTableRow(new Array('<u><a href="http://userscripts.org/scripts/show/74221">There is version ' + metadata.version + ' of Show Income On Top available.</a></u> You currently have version ' + version + ' installed.'), new Array('sigma'), updateRow);
	createTableRow(new Array(updateInfo), new Array('sigma'), infoRow);
}

// Sets the Styles that are used.
function setStyles() {
	// #ddb577 Dark
	// #fdf7dd Bright
	// #542c0f Font/Border
}
{'fraction_non_alphanumeric': 0.1803011803011803, 'fraction_numerical': 0.02577669244335911, 'mean_word_length': 3.503359804520464, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6589929', 'n_tokens_mistral': 2804, 'n_tokens_neox': 2545, 'n_words': 676}