Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name JobMarketExtension
- // @description Shows salary without income tax
- // @namespace Violentmonkey Scripts
- // @grant none+
- // @include *.e-sim.org/jobMarket.html*
- // ==/UserScript==
- /**
- * Main
- *
- */
- $(document).ready(function() {
- var aObj = getTaxes();
- var aMMObj = getMMcontent();
- var fGoldRatio = getGoldRatio(aMMObj);
- modifyTable(aObj, fGoldRatio);
- });
- /**
- * Get localisation with bonus.
- * @Return {Object} JSON object of localisation with bonus.
- *
- */
- function getTaxes() {
- var nCountryId = parseInt($('#countryId option:selected').val());
- var sHtml;
- var aResult = {};
- var aResourcesNames = ['Iron', 'Grain', 'Oil', 'Stone', 'Wood', 'Diamonds', 'Weapon', 'House', 'Gift', 'Food', 'Ticket', 'Defense System', 'Hospital', 'Estate'];
- $.ajax({
- type: "GET",
- dataType: "html",
- async: false,
- url: "/countryEconomyStatistics.html?countryId=" + nCountryId,
- success: function(html) {
- sHtml = html;
- }
- });
- var aRows = $('[class*="dataTable"][style="margin: auto;width: 600px;"] tr', sHtml);
- aRows = aRows.slice(1, aRows.length)
- for (i = 0; i < aRows.length; i++) {
- var aCell = $("td", aRows[i]);
- var sResource = aCell[0].innerHTML.trim();
- var nVat = parseInt(aCell[1].innerHTML.trim().replace('%', ''));
- var nImportTax = parseInt(aCell[2].innerHTML.replace(/%| /g, '').trim());
- var nIncomeTax = parseInt(aCell[3].innerHTML.trim().replace('%', ''));
- aResult[aResourcesNames[i]] = {};
- aResult[aResourcesNames[i]]['nVat'] = nVat;
- aResult[aResourcesNames[i]]['nImportTax'] = nImportTax;
- aResult[aResourcesNames[i]]['nIncomeTax'] = nIncomeTax;
- aResult[aResourcesNames[i]]['sResource'] = aResourcesNames[i];
- }
- return aResult;
- }
- /**
- * Modify job market table
- * @Param {Object} JSON Object aObj of taxes.
- * @Param
- */
- function modifyTable(aObj, fGoldRatio) {
- var aRows = $('[class="dataTable"] tr');
- aRows = aRows.slice(1, aRows.length)
- for (i = 0; i < aRows.length; i++) {
- var aCell = $("td", aRows[i]);
- var sResource = $('img', aCell[2])[0].src;
- sResource = sResource.substring(sResource.lastIndexOf('/') + 1, sResource.lastIndexOf('.'));
- sResource = sResource.replace('%20', ' ');
- var nSalary = parseFloat($('b', aCell[4]).html());
- var fSalaryWoTax = Math.round((nSalary * (1 - (aObj[sResource].nIncomeTax) / 100)) * 100) / 100;
- var sCountry = $('[class*="flags-small"]', aCell[4])[0].className.split(' ')[1];
- var aCellClone = $(aCell[4]).clone();
- $('div', aCellClone).remove();
- $('b', aCellClone).remove();
- var sCurrency = aCellClone[0].innerHTML.trim();
- var fInGold = Math.round(fGoldRatio * fSalaryWoTax * 100) / 100;
- $(aCell[2]).append('<b>Income tax:</b></br>' + aObj[sResource].nIncomeTax + '%');
- $(aCell[4]).append('<br/><br/><b>After tax:</b></br><div class="flags-small ' + sCountry + '"></div> <b title="' + fSalaryWoTax + '">' + fSalaryWoTax + '</b> ' + sCurrency + '<br/><b>' + fInGold + '</b> <div class="flags-small Gold"></div>');
- }
- }
- /**
- * @Return {Object} JSON Object of monetary market content.
- *
- */
- function getMMcontent() {
- var sHtml;
- var nCountryId = parseInt($('#countryId').find(":selected").attr('value'));
- $.ajax({
- type: "GET",
- dataType: "html",
- async: false,
- url: "/monetaryMarket.html?buyerCurrencyId=" + nCountryId + "&sellerCurrencyId=0",
- success: function(html) {
- sHtml = html;
- }
- });
- var aHtmlDOM = $.parseHTML(sHtml);
- var aMMtab = $("[class='dataTable']", aHtmlDOM)[0];
- var aRows = $("tr", aMMtab);
- aRows = aRows.slice(1, aRows.length);
- var aResult = [];
- for (i = 0; i < aRows.length; i++) {
- aResult[i] = {};
- var aCell = $("td", aRows[i]);
- var aSeller = $("[class='profileLink'], a[href*='stockCompany']", aCell[0]);
- var bIsStock = false;
- if ($("[class='profileLink']", aCell[0]).length) {
- var nSellerId = parseInt(aSeller.attr('href').match(/profile\.html\?id=([0-9]*)/)[1]);
- } else if ($("a[href*='stockCompany']", aCell[0]).length) {
- var bIsStock = true;
- var nSellerId = parseInt(aSeller.attr('href').match(/stockCompany\.html\?id=([0-9]*)/)[1]);
- }
- var fCurrencyAmount = parseFloat($("b", aCell[1]).attr('title'));
- var fCurrencyPrice = parseFloat($("b", aCell[2]).html());
- var nOfferId = parseInt($("[name='id']", aCell[3]).attr('value'));
- aResult[i]['nSellerId'] = nSellerId;
- aResult[i]['fCurrencyAmount'] = fCurrencyAmount;
- aResult[i]['fCurrencyPrice'] = fCurrencyPrice;
- aResult[i]['nOfferId'] = nOfferId;
- aResult[i]['bIsStock'] = bIsStock;
- }
- return aResult;
- }
- /**
- * @Param {Object} aObjMM JSON Object of MM content.
- * @Return {Number} gold ratio.
- *
- */
- function getGoldRatio(aMMObj) {
- if (aMMObj.length) {
- for (i = 0; i < aMMObj.length; i++) {
- if (aMMObj[i].fCurrencyAmount > 100) {
- return aMMObj[i].fCurrencyPrice;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement