NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Sistemkoin++ // @namespace https://openuserjs.org/users/admaxistrator // @version 0.14 // @description Adds USD columns to buy/sell order lists and hides chat widget. // @license MIT // @author Sebastian Ohme // @match https://sistemkoin.com/* // @grant none // @run-at document-end // ==/UserScript== //debugger; var _monkey = {}; _monkey.addGlobalStyle = function(css) { var head, style; head = document.getElementsByTagName('head')[0]; if (!head) { return; } style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = css; head.appendChild(style); }; _monkey.update = function() { _monkey.loadJson('https://sistemkoin.com/api/market/ticker', _monkey.onJson); }; _monkey.removeChatWidget = function() { var chat = document.getElementsByClassName("zopim"); if (chat !== null && chat.length > 0) { for (var i = 0; i < chat.length; i++) { chat[i].parentElement.removeChild(chat[i]); } } } _monkey.onInterval = function() { _monkey.removeChatWidget(); var x = document.querySelector("#main-wrapper > div > div.container-fluid > ng-component > div.row.page-titles > div:nth-child(1) > h4 > b"); var y = document.querySelector("#main-wrapper > div > div.container-fluid > ng-component > div.row.page-titles > div:nth-child(1) > h4 > small"); if (x !== null && y !== null) { var pairSource = x.innerText; var pairTarget = y.innerText.split(' ').last(); if (_monkey.pairSource == pairSource && _monkey.pairTarget == pairTarget) { return; } _monkey.pairSource = pairSource; _monkey.pairTarget = pairTarget; if (_monkey.pairTarget == 'USD') { _monkey.removeAugmentation(); } else { _monkey.update(); } } }; _monkey.loadJson = function(url, callback) { var xobj = new XMLHttpRequest(); xobj.overrideMimeType("application/json"); xobj.open('GET', url, true); xobj.onreadystatechange = function () { if (xobj.readyState == 4 && xobj.status == "200") { // Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode callback(xobj.responseText); } }; xobj.send(null); }; _monkey.onJson = function(responseText) { _monkey.json = JSON.parse(responseText); _monkey.addAugmentation(); }; _monkey.addAugmentation = function() { _monkey.addListAugmentation('table-responsive sell-order-list'); _monkey.addListAugmentation('table-responsive buy-order-list'); }; _monkey.removeAugmentation = function() { _monkey.removeListAugmentation('table-responsive sell-order-list'); _monkey.removeListAugmentation('table-responsive buy-order-list'); }; _monkey.addListAugmentation = function(tableClassName) { var table = document.getElementsByClassName(tableClassName)[0]; var thead = table.getElementsByTagName('thead')[0]; if (thead !== undefined) { var tr = thead.getElementsByTagName('tr')[0]; if (tr.childElementCount == 3) { var thRate = document.createElement('th'); thRate.innerText = 'Rate'; thRate.classList.add('monkey'); tr.insertBefore(thRate, tr.firstElementChild); var thTotal = document.createElement('th'); thTotal.innerText = 'Total'; thTotal.classList.add('monkey'); thTotal.classList.add('text-right'); tr.insertBefore(thTotal, tr.lastElementChild); } } var tbody = table.getElementsByTagName('tbody')[0]; var bodyRows = tbody.getElementsByTagName('tr'); var conversionFactor = _monkey.getConversionFactor(_monkey.pairTarget, 'USD'); for (var j = 0; j < bodyRows.length; j++) { var row = bodyRows[j]; var targetRateCell = row.firstElementChild; var customRateCell = targetRateCell.cloneNode(); customRateCell.innerText = '$' + (conversionFactor * parseFloat(targetRateCell.innerText)).toFixed(4); row.insertBefore(customRateCell, targetRateCell); var targetTotalCell = row.lastElementChild; var customTotalCell = targetTotalCell.cloneNode(); customTotalCell.innerText = '$' + (conversionFactor * parseFloat(targetTotalCell.innerText)).toFixed(2); row.insertBefore(customTotalCell, targetTotalCell); } }; _monkey.removeListAugmentation = function(tableClassName) { var table = document.getElementsByClassName(tableClassName)[0]; var thead = table.getElementsByTagName('thead')[0]; if (thead !== undefined) { var tr = thead.getElementsByTagName('tr')[0]; for (var i = 0; i < tr.childElementCount; i++) { var child = tr.children[i]; if (child.classList !== undefined && child.classList.contains('monkey')) { tr.removeChild(child); i--; } } } }; _monkey.getConversionFactor = function(source, target) { var sourceData = _monkey.json.data[source]; if (sourceData === undefined) { return 1.0; } for (var i = 0; i < sourceData.length; i++) { if (sourceData[i].currency == target) { return sourceData[i].current; } } }; (function() { 'use strict'; if (!Array.prototype.last) { Array.prototype.last = function() { return this[this.length - 1]; }; } _monkey.addGlobalStyle('td { padding: 0 10px 0 0 !important; } .container-fluid { max-width: 1920px !important; }'); _monkey.interval = setInterval(_monkey.onInterval, 500); })();