Skip to content

Instantly share code, notes, and snippets.

@tomtom87
Created March 13, 2017 12:05
Show Gist options
  • Save tomtom87/00a0118b435ebd3135548fdd12fc8b12 to your computer and use it in GitHub Desktop.
Save tomtom87/00a0118b435ebd3135548fdd12fc8b12 to your computer and use it in GitHub Desktop.
User script for tradingeconomics.com/forecast/currency
// ==UserScript==
// @name Q1 and Q2 differences on forcast
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Shows the differences on forcasts for Q1 Q2
// @author Tom Whitbread
// @match http://www.tradingeconomics.com/forecast/currency
// @grant none
// ==/UserScript==
(function() {
'use strict';
var prices = $('.datatable-row td:nth-child(3), .datatable-row-alternating td:nth-child(3)');
var q1 = $('.datatable-row td:nth-child(4), .datatable-row-alternating td:nth-child(4)');
var q2 = $('.datatable-row td:nth-child(5), .datatable-row-alternating td:nth-child(5)');
for(var i =0; i< prices.length; i++){
var diff = parseFloat(Math.abs(parseFloat(q1[i].textContent).toFixed(2)) - parseFloat(prices[i].textContent).toFixed(2)).toFixed(2);
var diffPercent = parseFloat((diff / parseFloat(prices[i].innerHTML)) * 100).toFixed(2);
var diffColor = (diff > 0) ? 'green' : 'red';
var diffPrefix = (diff > 0)? '+' : '';
var diffq2 = parseFloat(Math.abs(parseFloat(q2[i].textContent).toFixed(2)) - parseFloat(prices[i].textContent).toFixed(2)).toFixed(2);
var diffPercentq2 = parseFloat((diffq2 / parseFloat(prices[i].innerHTML)) * 100).toFixed(2);
var diffColorq2 = (diffq2 > 0) ? 'green' : 'red';
var diffPrefixq2 = (diffq2 > 0)? '+' : '';
q1[i].innerHTML = q1[i].innerHTML + ' (<span style="color:' + diffColor +'" title="'+ diffPrefix + diff +'">'+ diffPrefix + diffPercent +'%</span>)';
q2[i].innerHTML = q2[i].innerHTML + ' (<span style="color:' + diffColorq2 +'" title="'+ diffPrefixq2+ diffq2 +'">'+ diffPrefixq2 + diffPercentq2 +'%</span>)';
//console.log(q1[i]);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment