Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Luno Bot
- // @namespace wuiyang
- // @include https://www.luno.com/*
- // @version 1
- // @grant none
- // ==/UserScript==
- var hasSetup = false;
- var lowerLimit = 0;
- var lowerHasNotify = false;
- var lowerNotifyCount = 0;
- var upperLimit = 0;
- var upperHasNotify = false;
- var upperNotifyCount = 0;
- var spreadLimit = 0;
- var spreadHasNotify = false;
- var spreadNotifyCount = 0;
- function beep(frequency, time){
- if(frequency == undefined){
- frequency = 500;
- }
- if(time == undefined){
- time = 200;
- }
- var context = new (window.AudioContext || window.webkitAudioContext)();
- var o = context.createOscillator();
- var gainNode = context.createGain();
- o.connect(gainNode);
- gainNode.connect(context.destination);
- gainNode.gain.value = 0.35;
- o.type = 'sine';
- o.frequency.value = frequency;
- // Star the sound
- o.start(0);
- // Play the sound for a second before stopping it
- setTimeout(function() {
- o.stop(0);
- }, time);
- }
- function beepSeq(freq, count, step, time, wait, i){
- if(i == undefined){ i = 0; }
- if(count == undefined){ count = 1; }
- if(step == undefined){ step = 0; }
- if(time == undefined){ time = 200; }
- if(wait == undefined){ wait = 0; }
- beep(freq+step*i, time);
- i++;
- if(i<count){
- setTimeout(function(){beepSeq(freq, count, step, time, wait, i);}, time+wait);
- }
- }
- function checkSpread(){
- if(spreadLimit == 0){
- return;
- }
- var spread = parseFloat(document.getElementsByClassName("spread-text")[0].innerHTML.split(" ")[0]);
- if(spread >= spreadLimit){
- if(!spreadHasNotify){
- if(document.hasFocus()){
- beepSeq(500, 3, 0, 200, 100);
- spreadHasNotify = true;
- }else{
- if(spreadNotifyCount%8 == 0){
- spreadNotifyCount = 0;
- beepSeq(500, 3, 0, 200, 100);
- }
- spreadNotifyCount++;
- }
- }
- }else{
- speardHasNotify = false;
- }
- }
- function checkLowerPrice(){
- var currentPrice = parseFloat(document.getElementById("mCSB_5_container").children[0].children[0].children[0].innerHTML);
- if(lowerLimit == 0){
- return;
- }
- if(lowerLimit >= currentPrice){
- if(!lowerHasNotify){
- if(document.hasFocus()){
- beepSeq(700, 3, -100, 100);
- lowerHasNotify = true;
- }else{
- if(lowerNotifyCount%8 == 0){
- lowerNotifyCount = 0;
- beepSeq(700, 3, -100, 100);
- }
- lowerNotifyCount++;
- }
- }
- }else{
- lowerHasNotify = false;
- }
- }
- function checkUpperPrice(){
- var temp = document.getElementById("mCSB_4_container").children;
- var currentPrice = parseFloat(temp[temp.length-1].children[0].children[0].innerHTML);
- if(upperLimit == 0){
- return;
- }
- if(upperLimit <= currentPrice){
- if(!upperHasNotify){
- if(document.hasFocus()){
- beepSeq(500, 3, 100, 100);
- upperHasNotify = true;
- }else{
- if(upperNotifyCount%8 == 0){
- upperNotifyCount = 0;
- beepSeq(500, 3, 100, 100);
- }
- upperNotifyCount++;
- }
- }
- }else{
- upperHasNotify = false;
- }
- }
- function updateBot(){
- beep();
- var text;
- text = document.getElementById("botLower").value;
- lowerLimit = text == "" ? 0 : parseFloat(text);
- text = document.getElementById("botUpper").value;
- upperLimit = text == "" ? 0 : parseFloat(text);
- text = document.getElementById("botSpread").value;
- spreadLimit = text == "" ? 0 : parseFloat(text);
- console.log("Updated Bot Info");
- if(!hasSetup){
- hasSetup = true;
- runner();
- console.log("Bot is runnning now");
- }
- }
- function runner(){
- checkSpread();
- checkLowerPrice();
- checkUpperPrice();
- setTimeout(runner, 1200);
- }
- function setupBotUI(){
- var div = document.createElement("div");
- var divl = document.createElement("div");
- var divu = document.createElement("div");
- var divs = document.createElement("div");
- var pl = document.createElement("p");
- var pu = document.createElement("p");
- var ps = document.createElement("p");
- var lower = document.createElement("input");
- var upper = document.createElement("input");
- var spread = document.createElement("input");
- var btn = document.createElement("input");
- //setup input
- lower.id = "botLower";
- lower.style = "border:1px solid #293235;width:100%;height:30px;";
- lower.placeholder = "lower rate";
- lower.type = "number";
- lower.min = 0.0001;
- lower.step = 0.0001;
- upper.id = "botUpper";
- upper.style = "border:1px solid #293235;width:100%;height:30px;";
- upper.placeholder = "higher rate";
- upper.type = "number";
- upper.min = 0.0001;
- upper.step = 0.0001;
- spread.id = "botSpread";
- spread.style = "border:1px solid #293235;width:100%;height:30px;";
- spread.placeholder = "spread amount";
- spread.type = "number";
- spread.min = 0.0001;
- spread.step = 0.0001;
- //setup div container for input show in one line
- pl.innerHTML += "Current buy is lower than:";
- pl.style = "margin:0 0 0 10px;";
- divl.appendChild(pl);
- divl.appendChild(lower);
- pu.innerHTML = "Current sell is higher than:";
- pu.style = "margin:0 0 0 10px;";
- divu.appendChild(pu);
- divu.appendChild(upper);
- ps.innerHTML += "Current spread is higher than:";
- ps.style = "margin:0 0 0 10px;";
- divs.appendChild(ps);
- divs.appendChild(spread);
- //button
- btn.type = "submit";
- btn.value = "Update Luno Notify Bot";
- btn.className = "btn btn-primary";
- if (btn.addEventListener)
- btn.addEventListener("click", updateBot, false);
- else if (btn.attachEvent)
- btn.attachEvent('onclick', updateBot);
- //setup div
- div.innerHTML = "Create beep noise when:";
- div.appendChild(divu);
- div.appendChild(divl);
- div.appendChild(divs);
- div.innerHTML += "<br>";
- div.appendChild(btn);
- document.getElementsByClassName("exchange-trades-panel")[0].innerHTML = '<h2 class="h1" style="font-size:20px;" translate=""><span class="ng-scope">Luno Notify Bot</span></h2>';
- document.getElementsByClassName("exchange-trades-panel")[0].appendChild(div);
- }
- function firstload(){
- if(document.URL.indexOf("https://www.luno.com/trade/ETHXBT") == 0){
- var check = document.getElementsByClassName("spread-text");
- if(check.length == 1){
- console.log("Loaded notify bot");
- setupBotUI();
- }else{
- setTimeout(firstload, 1500);
- }
- }
- }
- firstload();
Advertisement
Add Comment
Please, Sign In to add comment