Skip to content

Commit

Permalink
Merge pull request #34 from nirvanatikku/enhancement/improve_tv_chart…
Browse files Browse the repository at this point in the history
…_init

Enhancement/Improve TV Chart Init
  • Loading branch information
nirvanatikku authored Dec 24, 2017
2 parents 9370acb + 2a9a3c1 commit 9ab628b
Show file tree
Hide file tree
Showing 3 changed files with 1,298 additions and 18 deletions.
20 changes: 4 additions & 16 deletions enhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const CONSTANTS = {
color: '#0072ed',
colMinWidth: '100px',
tvTrexPrefix: 'BITTREX',
tvChartURL: '//s3.tradingview.com/tv.js',
btcEthTrexApiURL: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-ETH',
btcPriceDomExpr: '[data-bind="text:navigation.displayBitcoinUsd"]',
loginNodeExpr: ".fa-sign-in",
Expand Down Expand Up @@ -412,24 +411,14 @@ Enhancer.enhanceMarketHistoryTable = function enhanceMarketHistoryTable(table){
}
}
Enhancer.initTradingViewWidget = function initTradingViewWidget(ticker, tradingViewOpts){
const script = document.createElement('script');
script.src = CONSTANTS.tvChartURL;
script.async = true;
script.addEventListener('load', function(){
let opts = {};
Object.assign(opts,
tradingViewOpts, {
symbol: ticker,
container_id: 'tv-chart-'+Enhancer.getTickerQP()
});
console.log(opts);
let insertTradingViewChartCode = 'new TradingView.widget('+JSON.stringify(opts)+');';
const chartScript = document.createElement('script');
chartScript.type = 'text/javascript';
chartScript.innerText = insertTradingViewChartCode;
document.body.appendChild(chartScript);
});
document.head.appendChild(script);
new TradingView.widget(opts);
}
Enhancer.getTickerQP = function getTickerQP(){
let qps = document.location.search.substring(1);
Expand All @@ -440,9 +429,8 @@ Enhancer.swapCharts = function swapCharts(tradingViewOpts){
if(charts.length === 2){ // timeline, orderbook
// Clean
let node = charts[0];
while (node.firstChild) {
node.removeChild(node.firstChild);
}
let existingChart = node.getElementsByTagName("iframe")[0];
existingChart.remove();
let ticker = Enhancer.getTickerQP();
let t = ticker.split('-');
let tradingViewTicker = CONSTANTS.tvTrexPrefix + ':' + t[1] + t[0]; // e.g. BTC-NEO => BITTREX:NEOBTC
Expand All @@ -461,7 +449,7 @@ Enhancer.getDataProcessors = function getDataProcessors(proc, opts){
if(opts.tvChart){
setTimeout(function(){
Enhancer.swapCharts(opts.tradingViewOpts);
}, 1200);
}, 400);
}
if(opts.usdVal){
const marketQp = Enhancer.getTickerQP();
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"https://*.bittrex.com/Home/Markets*",
"https://*.bittrex.com/"
],
"js": ["enhancer.js"],
"js": ["enhancer.js", "tv.js"],
"css": ["enhanced-styles.css"]
}
],
"content_security_policy": "default-src 'none'; style-src 'self' 'unsafe-inline'; script-src 'self'; connect-src https://s3.tradingview.com;"
"content_security_policy": "default-src 'none'; style-src 'self' 'unsafe-inline'; script-src 'self'; script-src https://*.tradingview.com;"
}
Loading

0 comments on commit 9ab628b

Please sign in to comment.