Free javascript Hosting


tvscript.js

Uploaded on May 01 2022 16:48 by admnelubov

const secretWord = "B52";
$('body').append('<div id="B52Area" draggable="true"></div>');
$('#B52Area').html(`
<div>
<button id='B52ClearChart'>Clear chart</button>
</div>
<div>
<button id='B52Start100'>B52</button>
</div>
<div>
<button id='B52StartBinance'>START!</button>
</div>
<div>
Binance connection status: <span id="B52ConnectionStatus"></span>
<button id='B52ConnectBinance'>Connect</button>
</div>
<div>
Results:
<div id='B52Result'></div>
</div>
`);
$('#B52Area').css({
'-webkit-user-drag': 'element',
'resize': 'both',
'position':'absolute',
'right':'57px',
'bottom':'25px',
'border':'1px solid gray',
'height':'350px',
'width':'240px',
'background-color':'black',
'padding':'5px'
});
$('#B52Area').find("div").css({
'padding':'2px'
});
$("#B52Area").find("button").css({
'border':'1px solid gray',
'background-color':'#3f5721'
});
$("#B52ClearChart").click(()=>{
clearB52s();
});
$("#B52Start100").click(()=>{
runFavIndicator($("#B52Start100").text());
});
$("#B52StartBinance").click(()=>{
var theUniqueName = "B52 " + Date.now().toString();
var menu = xpathGetFirstItem("//div[@data-role='button' and @data-name='alerts']");
triggerMouseEvent (menu, "click");
createNewAlert(theUniqueName, ()=>{
grabAlertMessage(theUniqueName,(res)=>{
$("#B52Result").text(res);
setTimeout(function(){
deleteAlert(getCurrentCurrencyPair(),theUniqueName);
},50);
});
});
});
$("#B52ConnectionStatus").css("color","green");

function triggerMouseEvent (node, eventType) {
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent(eventType, true, true);
node.dispatchEvent(clickEvent);
}

function xpathItemCount(xpath)
{
return itemsCount = document.evaluate(xpath , document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength;
}

function xpathGetFirstItem(xpath)
{
var items = document.evaluate(xpath , document, null, XPathResult.ANY_TYPE, null);
return items.iterateNext();
}

function clearB52s()
{
var query = "//div[@data-name='legend-source-item' and .//div[contains(text(),'"+secretWord +"')]]//div[@data-name='legend-delete-action']";
var itemsCount = xpathItemCount(query);
for (i=0;i<itemsCount;i++)
{
item = xpathGetFirstItem(query);
triggerMouseEvent (item, "mousedown");
}
}

function runFavIndicator(name)
{
var arrow = xpathGetFirstItem("(//div[@data-name='show-favorite-indicators'])[1]");
triggerMouseEvent (arrow, "click");
setTimeout(function() {
var fav = xpathGetFirstItem("//div[./div[text()='Favorite Indicators']]/div[.//span[text()='"+name+"']]");
triggerMouseEvent (fav, "click");
}, 200);
}

function runStopAlert(currency,name)
{
var play = xpathGetFirstItem("(//div[starts-with(@class,'body')]//div[./div/span[contains(text(),'"+currency+"')] and ./div[contains(text(),'"+name+"')]]//div[@role='button'])[1]");
triggerMouseEvent (play, "click");
}

function getCurrentCurrencyPair()
{
var sign = xpathGetFirstItem("//div[@id='header-toolbar-symbol-search']/div");
return sign.innerText;
}

function getCurrentStrategyName()
{
var sign = xpathGetFirstItem("//div[@data-name='legend']//div[@data-name='legend-source-title' and contains(text(),'"+secretWord+"')]");
return sign.innerText;
}

function getAlertMessage()
{
var alert = xpathGetFirstItem("//div[@data-qa-dialog-name='alert-fired']//div[contains(@class,'secondaryRow')]");
return alert.innerText;
}

function closeAlert()
{
var close = xpathGetFirstItem("//div[@data-qa-dialog-name='alert-fired']//span[starts-with(@class,'close')]");
triggerMouseEvent (close, "click");
}

function grabAlertMessage(name,thenRun)
{
var existCondition = setInterval(function() {
if ($("div[data-qa-dialog-name='alert-fired']").length) {
clearInterval(existCondition);
//stop it now
runStopAlert(getCurrentCurrencyPair(),name);
var theMessage = getAlertMessage();
closeAlert();
thenRun(theMessage);
}
}, 100);
}

function createNewAlert(alertName, thenRun)
{
var more = "//div[@data-name='legend-source-item' and .//div[contains(text(),'"+secretWord +"')]]//div[@data-name='legend-more-action']";
item = xpathGetFirstItem(more);
triggerMouseEvent(item, "mousedown");
setTimeout(function() {
var newAlert = xpathGetFirstItem("//div[@id='overlap-manager-root']//tr[.//span[starts-with(text(),'Add alert on')]]");
triggerMouseEvent (newAlert, "click");
setTimeout(function(){
$("input[name='alert-name']")[0].value = alertName;
triggerMouseEvent($("input[name='alert-name']")[0],"focus");
triggerMouseEvent($("input[name='alert-name']")[0],"input");
triggerMouseEvent($("input[name='alert-name']")[0],"change");
triggerMouseEvent($("input[name='alert-name']")[0],"blur");
//dispatch enter press
setTimeout(function(){
const ke = new KeyboardEvent('keydown', {
bubbles: true, cancelable: true, keyCode: 13
});
document.body.dispatchEvent(ke);
thenRun();
}, 50);
}, 250);
}, 150);
}

function deleteAlert(currency,name)
{
var del = xpathGetFirstItem("(//div[starts-with(@class,'body')]//div[./div/span[contains(text(),'"+currency+"')] and ./div[contains(text(),'"+name+"')]]//div[@role='button'])[3]");
triggerMouseEvent (del, "click");
setTimeout(function(){
var yesButton = xpathGetFirstItem("//button[starts-with(@class,'actionButton') and @name='yes']");
triggerMouseEvent (yesButton, "click");
}, 150);
}

Back to list